You should use the various methods of MDoc
like MDoc::html_documentation
The class is public so specific behavior can be plugged on it.
nitc :: NitdocDecorator :: _current_mdoc
The currently processed mdoc.nitc :: NitdocDecorator :: _toolcontext
nitc :: NitdocDecorator :: current_mdoc
The currently processed mdoc.nitc :: NitdocDecorator :: current_mdoc=
The currently processed mdoc.nitc :: NitdocDecorator :: defaultinit
nitc :: NitdocDecorator :: toolcontext
nitc :: NitdocDecorator :: toolcontext=
nitc $ NitdocDecorator :: SELF
Type of this instance, automatically specialized in every classnitc :: nitcatalog $ NitdocDecorator :: add_image
Render an image.nitc $ NitdocDecorator :: add_span_code
Render a code span reading from a buffer.nitc :: NitdocDecorator :: _current_mdoc
The currently processed mdoc.markdown :: HTMLDecorator :: _headlines
nitc :: NitdocDecorator :: _toolcontext
markdown :: Decorator :: add_blockquote
Render a blockquote.markdown :: Decorator :: add_headline
Render a headline block with corresponding level.markdown :: Decorator :: add_line_break
Render a line breakmarkdown :: Decorator :: add_listitem
Render a list item.markdown :: Decorator :: add_orderedlist
Render an ordered list.markdown :: Decorator :: add_paragraph
Render a paragraph block.markdown :: Decorator :: add_span_code
Render a code span reading from a buffer.markdown :: Decorator :: add_strike
Render a strike text.markdown :: Decorator :: add_strong
Render a strong text.markdown :: Decorator :: add_unorderedlist
Render an unordered list.markdown :: Decorator :: add_wikilink
Renders a[[wikilink]]
item.
markdown :: Decorator :: append_code
Render code text from buffer and escape it.markdown :: Decorator :: append_value
Render a text and escape it.core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
nitc :: NitdocDecorator :: current_mdoc
The currently processed mdoc.nitc :: NitdocDecorator :: current_mdoc=
The currently processed mdoc.core :: Object :: defaultinit
markdown :: Decorator :: defaultinit
nitc :: NitdocDecorator :: defaultinit
markdown :: HTMLDecorator :: defaultinit
markdown :: Decorator :: escape_char
Render a character escape.markdown :: HTMLDecorator :: headlines=
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: native_class_name
The class name of the object in CString format.core :: Object :: output_class_name
Display class name on stdout (debug only).nitc :: NitdocDecorator :: toolcontext
nitc :: NitdocDecorator :: toolcontext=
InlineDecorator
but with wikilink commands handling
# The specific markdown decorator used internally to process MDoc object.
#
# You should use the various methods of `MDoc` like `MDoc::html_documentation`
#
# The class is public so specific behavior can be plugged on it.
class NitdocDecorator
super HTMLDecorator
private var toolcontext = new ToolContext
# The currently processed mdoc.
#
# Unfortunately, this seems to be the simpler way to get the currently processed `MDoc` object.
var current_mdoc: nullable MDoc = null
redef fun add_code(v, block) do
var meta = block.meta or else "nit"
# Do not try to highlight non-nit code.
if meta != "nit" and meta != "nitish" then
v.add "<pre class=\"{meta}\"><code>"
v.emit_in block
v.add "</code></pre>\n"
return
end
# Try to parse code
var code = block.raw_content
var ast = toolcontext.parse_something(code)
if ast isa AError then
v.add "<pre class=\"{meta}\"><code>"
v.emit_in block
v.add "</code></pre>\n"
return
end
v.add "<pre class=\"nitcode\"><code>"
var hl = new HtmlightVisitor
hl.line_id_prefix = ""
hl.highlight_node(ast)
v.add(hl.html)
v.add "</code></pre>\n"
end
redef fun add_span_code(v, text, from, to) do
# Try to parse it
var code = code_from_text(text, from, to)
var ast = toolcontext.parse_something(code)
if ast isa AError then
v.add "<code class=\"rawcode\">"
append_code(v, text, from, to)
else
v.add "<code class=\"nitcode\">"
var hl = new HtmlightVisitor
hl.line_id_prefix = ""
hl.highlight_node(ast)
v.add(hl.html)
end
v.add "</code>"
end
private fun code_from_text(buffer: Text, from, to: Int): String do
var out = new FlatBuffer
for i in [from..to[ do out.add buffer[i]
return out.write_to_string
end
end
src/doc/templates/html_model.nit:447,1--512,3
redef class NitdocDecorator
redef fun add_image(v, link, name, comment)
do
# Keep absolute links as is
if link.has_prefix("http://") or link.has_prefix("https://") then
super
return
end
do
# Get the directory of the doc object to deal with the relative link
var mdoc = current_mdoc
if mdoc == null then break
var source = mdoc.location.file
if source == null then break
var path = source.filename
var stat = path.file_stat
if stat == null then break
if not stat.is_dir then path = path.dirname
# Get the full path to the local resource
var fulllink = path / link.to_s
stat = fulllink.file_stat
if stat == null then break
# Get a collision-free catalog name for the resource
var hash = fulllink.md5
var ext = fulllink.file_extension
if ext != null then hash = hash + "." + ext
# Copy the local resource in the resource directory of the catalog
var res = catalog.outdir / "res" / hash
fulllink.file_copy_to(res)
# Hijack the link in the html.
link = ".." / "res" / hash
super(v, link, name, comment)
return
end
# Something went bad
catalog.modelbuilder.toolcontext.error(current_mdoc.location, "Error: cannot find local image `{link}`")
super
end
# The registered catalog
#
# It is used to deal with relative links in images.
var catalog: Catalog is noautoinit
end
src/nitcatalog.nit:135,1--184,3