private import parser_util
redef class MDoc
- # Comment synopsys HTML escaped
- var short_comment: String is lazy do return content.first.html_escape
- # Full comment HTML escaped
- var full_comment: String is lazy do return content.join("\n").html_escape
+ # Synopsis HTML escaped.
+ var synopsis: String is lazy do return content.first.html_escape
+
+ # Comment without synopsis HTML escaped
+ var comment: String is lazy do
+ var lines = content.to_a
+ if not lines.is_empty then lines.shift
+ return content.join("\n").html_escape
+ end
+
+ # Full comment HTML escaped.
+ var documentation: String is lazy do return content.join("\n").html_escape
private var markdown_proc: MarkdownProcessor is lazy do
return original_mentity.model.nitdoc_md_processor
return original_mentity.model.nitdoc_inline_processor
end
- # Synopsys in a template
- var tpl_short_comment: Writable is lazy do
+ # Renders the synopsis as a HTML comment block.
+ var html_synopsis: Writable is lazy do
var res = new Template
var syn = inline_proc.process(content.first)
res.add "<span class=\"synopsys nitdoc\">{syn}</span>"
end
- # Full comment in a template
- var tpl_comment: Writable is lazy do
- var res = new Template
+ # Renders the comment without the synopsis as a HTML comment block.
+ var html_comment: Writable is lazy do
var lines = content.to_a
+ if not lines.is_empty then lines.shift
+ return lines_to_html(lines)
+ end
+
+ # Renders the synopsis and the comment as a HTML comment block.
+ var html_documentation: Writable is lazy do return lines_to_html(content.to_a)
+
+ # Renders markdown line as a HTML comment block.
+ private fun lines_to_html(lines: Array[String]): Writable do
+ var res = new Template
res.add "<div class=\"nitdoc\">"
# do not use DocUnit as synopsys
- if not content.first.has_prefix(" ") and
- not content.first.has_prefix("\t") then
- # parse synopsys
- var syn = inline_proc.process(lines.shift)
- res.add "<p class=\"synopsys\">{syn}</p>"
+ if not lines.is_empty then
+ if not lines.first.has_prefix(" ") and
+ not lines.first.has_prefix("\t") then
+ # parse synopsys
+ var syn = inline_proc.process(lines.shift)
+ res.add "<p class=\"synopsys\">{syn}</p>"
+ end
end
# check for annotations
for i in [0 .. lines.length[ do
res.add markdown_proc.process(lines.join("\n"))
res.add "</div>"
return res
+
end
end
var def_url = "{cls_url}#{mprop.nitdoc_id}.definition"
var lnk = new Link(def_url, mprop.html_name)
var mdoc = mprop.intro.mdoc_or_fallback
- if mdoc != null then lnk.title = mdoc.short_comment
+ if mdoc != null then lnk.title = mdoc.synopsis
var item = new Template
item.add new DocHTMLLabel.with_classes(classes)
item.add lnk
var tpl = new Link(nitdoc_url, html_name)
var mdoc = mdoc_or_fallback
if mdoc != null then
- tpl.title = mdoc.short_comment
+ tpl.title = mdoc.synopsis
end
return tpl
end
var tpl = new Link("#{nitdoc_id}", html_name)
var mdoc = mdoc_or_fallback
if mdoc != null then
- tpl.title = mdoc.short_comment
+ tpl.title = mdoc.synopsis
end
return tpl
end
# * MPropdef: `mclassdef:mpropdef`
fun html_namespace: Template is abstract
- # Returns the comment of this MEntity formatted as HTML.
- var html_comment: nullable Writable is lazy do
+ # Returns the synopsis and the comment of this MEntity formatted as HTML.
+ var html_documentation: nullable Writable is lazy do
+ var mdoc = mdoc_or_fallback
+ if mdoc == null then return null
+ return mdoc.html_documentation
+ end
+
+ # Returns the synopsis of this MEntity formatted as HTML.
+ var html_synopsis: nullable Writable is lazy do
var mdoc = mdoc_or_fallback
if mdoc == null then return null
- return mdoc.tpl_comment
+ return mdoc.html_synopsis
end
- # Returns the comment of this MEntity formatted as HTML.
- var html_short_comment: nullable Writable is lazy do
+ # Returns the the comment without the synopsis formatted as HTML.
+ var html_comment: nullable Writable is lazy do
var mdoc = mdoc_or_fallback
if mdoc == null then return null
- return mdoc.tpl_short_comment
+ return mdoc.html_comment
end
# Icon that will be displayed before the title
var tpl = new Template
tpl.add new DocHTMLLabel.with_classes(css_classes)
tpl.add html_link
- var comment = html_short_comment
+ var comment = html_synopsis
if comment != null then
tpl.add ": "
tpl.add comment
var lnk = html_link
var tpl = new Template
tpl.add new Link.with_title("#{nitdoc_id}.concern", lnk.text, lnk.title)
- var comment = html_short_comment
+ var comment = html_synopsis
if comment != null then
tpl.add ": "
tpl.add comment
redef fun render_body do
var tabs = new DocTabs("{html_id}.tabs", "")
- var comment = mentity.html_comment
+ var comment = mentity.html_documentation
if comment != null then
tabs.add_panel new DocTabPanel("{html_tab_id}-comment", "Comment", comment)
end
if not is_no_body then
var comment
if is_short_comment then
- comment = mentity.html_short_comment
+ comment = mentity.html_synopsis
else
- comment = mentity.html_comment
+ comment = mentity.html_documentation
end
if comment != null then
tabs.add_panel new DocTabPanel("{html_tab_id}-comment", "Comment", comment)
if not mentity isa MPropDef then continue # TODO handle all mentities
var tpl = new Template
tpl.add mentity.mclassdef.html_namespace
- var comment = mentity.mclassdef.html_short_comment
+ var comment = mentity.mclassdef.html_synopsis
if comment != null then
tpl.add ": "
tpl.add comment