nitc :: CmdDecorator :: defaultinit
# Custom Markdown processor able to process doc commands
class CmdDecorator
super NitdocDecorator
redef type PROCESSOR: CmdMarkdownProcessor
# Model used by wikilink commands to find entities
var model: Model
# Filter to apply if any
var filter: nullable ModelFilter
redef fun add_span_code(v, buffer, from, to) do
var text = new FlatBuffer
buffer.read(text, from, to)
var name = text.write_to_string
name = name.replace("nullable ", "")
var mentity = try_find_mentity(name)
if mentity == null then
super
else
v.add "<code>"
v.emit_text mentity.html_link.write_to_string
v.add "</code>"
end
end
private fun try_find_mentity(text: String): nullable MEntity do
var mentity = model.mentity_by_full_name(text, filter)
if mentity != null then return mentity
var mentities = model.mentities_by_name(text, filter)
if mentities.is_empty then
return null
else if mentities.length > 1 then
# TODO smart resolve conflicts
end
return mentities.first
end
redef fun add_wikilink(v, token) do
v.render_wikilink(token, model)
end
end
src/doc/templates/html_commands.nit:361,1--404,3