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.

Introduced properties

private var _catalog: Catalog

nitc :: NitdocDecorator :: _catalog

The registered catalog
private var _current_mdoc: nullable MDoc

nitc :: NitdocDecorator :: _current_mdoc

The currently processed mdoc.
fun catalog: Catalog

nitc :: NitdocDecorator :: catalog

The registered catalog
protected fun catalog=(catalog: Catalog)

nitc :: NitdocDecorator :: catalog=

The registered catalog
private fun code_from_text(buffer: Text, from: Int, to: Int): String

nitc :: NitdocDecorator :: code_from_text

fun current_mdoc: nullable MDoc

nitc :: NitdocDecorator :: current_mdoc

The currently processed mdoc.
protected fun current_mdoc=(current_mdoc: nullable MDoc)

nitc :: NitdocDecorator :: current_mdoc=

The currently processed mdoc.
private fun toolcontext=(toolcontext: ToolContext)

nitc :: NitdocDecorator :: toolcontext=

Redefined properties

redef type SELF: NitdocDecorator

nitc $ NitdocDecorator :: SELF

Type of this instance, automatically specialized in every class
redef fun add_code(v: PROCESSOR, block: BlockCode)

nitc $ NitdocDecorator :: add_code

Render a code or fence block.
redef fun add_image(v: PROCESSOR, link: Text, name: Text, comment: nullable Text)

nitc :: nitcatalog $ NitdocDecorator :: add_image

Render an image.
redef fun add_span_code(v: PROCESSOR, text: Text, from: Int, to: Int)

nitc $ NitdocDecorator :: add_span_code

Render a code span reading from a buffer.

All properties

fun !=(other: nullable Object): Bool

core :: Object :: !=

Have self and other different values?
fun ==(other: nullable Object): Bool

core :: Object :: ==

Have self and other the same value?
type CLASS: Class[SELF]

core :: Object :: CLASS

The type of the class of self.
type PROCESSOR: MarkdownProcessor

markdown :: Decorator :: PROCESSOR

Kind of processor used
type SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
private var _catalog: Catalog

nitc :: NitdocDecorator :: _catalog

The registered catalog
private var _current_mdoc: nullable MDoc

nitc :: NitdocDecorator :: _current_mdoc

The currently processed mdoc.
abstract fun add_abbr(v: PROCESSOR, name: Text, comment: Text)

markdown :: Decorator :: add_abbr

Render an abbreviation.
abstract fun add_blockquote(v: PROCESSOR, block: BlockQuote)

markdown :: Decorator :: add_blockquote

Render a blockquote.
fun add_char(v: PROCESSOR, c: Char)

markdown :: Decorator :: add_char

Render a single plain char.
abstract fun add_code(v: PROCESSOR, block: BlockCode)

markdown :: Decorator :: add_code

Render a code or fence block.
abstract fun add_em(v: PROCESSOR, text: Text)

markdown :: Decorator :: add_em

Render an emphasis text.
abstract fun add_headline(v: PROCESSOR, block: BlockHeadline)

markdown :: Decorator :: add_headline

Render a headline block with corresponding level.
abstract fun add_image(v: PROCESSOR, link: Text, name: Text, comment: nullable Text)

markdown :: Decorator :: add_image

Render an image.
abstract fun add_line_break(v: PROCESSOR)

markdown :: Decorator :: add_line_break

Render a line break
abstract fun add_listitem(v: PROCESSOR, block: BlockListItem)

markdown :: Decorator :: add_listitem

Render a list item.
abstract fun add_orderedlist(v: PROCESSOR, block: BlockOrderedList)

markdown :: Decorator :: add_orderedlist

Render an ordered list.
abstract fun add_paragraph(v: PROCESSOR, block: BlockParagraph)

markdown :: Decorator :: add_paragraph

Render a paragraph block.
abstract fun add_ruler(v: PROCESSOR, block: BlockRuler)

markdown :: Decorator :: add_ruler

Render a ruler block.
abstract fun add_span_code(v: PROCESSOR, buffer: Text, from: Int, to: Int)

markdown :: Decorator :: add_span_code

Render a code span reading from a buffer.
abstract fun add_strike(v: PROCESSOR, text: Text)

markdown :: Decorator :: add_strike

Render a strike text.
abstract fun add_strong(v: PROCESSOR, text: Text)

markdown :: Decorator :: add_strong

Render a strong text.
abstract fun add_unorderedlist(v: PROCESSOR, block: BlockUnorderedList)

markdown :: Decorator :: add_unorderedlist

Render an unordered list.
private fun allowed_id_chars=(allowed_id_chars: Array[Char])

markdown :: HTMLDecorator :: allowed_id_chars=

abstract fun append_code(v: PROCESSOR, buffer: Text, from: Int, to: Int)

markdown :: Decorator :: append_code

Render code text from buffer and escape it.
abstract fun append_value(v: PROCESSOR, value: Text)

markdown :: Decorator :: append_value

Render a text and escape it.
fun catalog: Catalog

nitc :: NitdocDecorator :: catalog

The registered catalog
protected fun catalog=(catalog: Catalog)

nitc :: NitdocDecorator :: catalog=

The registered catalog
protected fun class_factory(name: String): CLASS

core :: Object :: class_factory

Implementation used by get_class to create the specific class.
fun class_name: String

core :: Object :: class_name

The class name of the object.
private fun code_from_text(buffer: Text, from: Int, to: Int): String

nitc :: NitdocDecorator :: code_from_text

fun current_mdoc: nullable MDoc

nitc :: NitdocDecorator :: current_mdoc

The currently processed mdoc.
protected fun current_mdoc=(current_mdoc: nullable MDoc)

nitc :: NitdocDecorator :: current_mdoc=

The currently processed mdoc.
abstract fun escape_char(v: PROCESSOR, char: Char)

markdown :: Decorator :: escape_char

Render a character escape.
fun get_class: CLASS

core :: Object :: get_class

The meta-object representing the dynamic type of self.
fun hash: Int

core :: Object :: hash

The hash code of the object.
abstract fun headlines: ArrayMap[String, HeadLine]

markdown :: Decorator :: headlines

Found headlines during the processing labeled by their ids.
protected fun headlines=(headlines: ArrayMap[String, HeadLine])

markdown :: HTMLDecorator :: headlines=

init init

core :: Object :: init

fun inspect: String

core :: Object :: inspect

Developer readable representation of self.
protected fun inspect_head: String

core :: Object :: inspect_head

Return "CLASSNAME:#OBJECTID".
intern fun is_same_instance(other: nullable Object): Bool

core :: Object :: is_same_instance

Return true if self and other are the same instance (i.e. same identity).
fun is_same_serialized(other: nullable Object): Bool

core :: Object :: is_same_serialized

Is self the same as other in a serialization context?
intern fun is_same_type(other: Object): Bool

core :: Object :: is_same_type

Return true if self and other have the same dynamic type.
private intern fun native_class_name: CString

core :: Object :: native_class_name

The class name of the object in CString format.
intern fun object_id: Int

core :: Object :: object_id

An internal hash code for the object based on its identity.
fun output

core :: Object :: output

Display self on stdout (debug only).
intern fun output_class_name

core :: Object :: output_class_name

Display class name on stdout (debug only).
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
abstract fun strip_id(txt: String): String

markdown :: Decorator :: strip_id

Generate a new html valid id from a String.
intern fun sys: Sys

core :: Object :: sys

Return the global sys object, the only instance of the Sys class.
abstract fun to_jvalue(env: JniEnv): JValue

core :: Object :: to_jvalue

fun to_s: String

core :: Object :: to_s

User readable representation of self.
private fun toolcontext=(toolcontext: ToolContext)

nitc :: NitdocDecorator :: toolcontext=

package_diagram nitc::NitdocDecorator NitdocDecorator markdown::HTMLDecorator HTMLDecorator nitc::NitdocDecorator->markdown::HTMLDecorator markdown::Decorator Decorator markdown::HTMLDecorator->markdown::Decorator ...markdown::Decorator ... ...markdown::Decorator->markdown::Decorator nitc::InlineDecorator InlineDecorator nitc::InlineDecorator->nitc::NitdocDecorator nitc::CmdDecorator CmdDecorator nitc::CmdDecorator->nitc::NitdocDecorator nitc::CmdInlineDecorator CmdInlineDecorator nitc::CmdInlineDecorator->nitc::InlineDecorator nitc::CmdInlineDecorator... ... nitc::CmdInlineDecorator...->nitc::CmdInlineDecorator

Ancestors

interface Decorator

markdown :: Decorator

A Decorator is used to emit mardown into a specific format.
interface Object

core :: Object

The root of the class hierarchy.

Parents

class HTMLDecorator

markdown :: HTMLDecorator

Decorator that outputs HTML.

Children

class CmdDecorator

nitc :: CmdDecorator

Custom Markdown processor able to process doc commands
class InlineDecorator

nitc :: InlineDecorator

Decorator for span elements.

Descendants

class CmdInlineDecorator

nitc :: CmdInlineDecorator

Same as InlineDecorator but with wikilink commands handling

Class definitions

nitc $ NitdocDecorator
# 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

nitc :: nitcatalog $ NitdocDecorator
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