Translate mentities to html blocks.

Introduced classes

class InlineDecorator

nitc :: InlineDecorator

Decorator for span elements.
class NitdocDecorator

nitc :: NitdocDecorator

The specific markdown decorator used internally to process MDoc object.

Redefined classes

redef class MAttributeDef

nitc :: html_model $ MAttributeDef

A local definition of an attribute
redef class MClass

nitc :: html_model $ MClass

A named class
redef class MClassDef

nitc :: html_model $ MClassDef

A definition (an introduction or a refinement) of a class in a module
redef class MClassType

nitc :: html_model $ MClassType

A type based on a class.
redef class MDoc

nitc :: html_model $ MDoc

Structured documentation of a MEntity object
redef abstract class MEntity

nitc :: html_model $ MEntity

A named and possibly documented entity in the model.
redef class MGenericType

nitc :: html_model $ MGenericType

A type based on a generic class.
redef class MGroup

nitc :: html_model $ MGroup

A group of modules in a package
redef class MMethodDef

nitc :: html_model $ MMethodDef

A local definition of a method
redef class MModule

nitc :: html_model $ MModule

A Nit module is usually associated with a Nit source file.
redef class MNullableType

nitc :: html_model $ MNullableType

A type prefixed with "nullable"
redef class MPackage

nitc :: html_model $ MPackage

A Nit package, that encompass a product
redef class MParameter

nitc :: html_model $ MParameter

A parameter in a signature
redef class MParameterType

nitc :: html_model $ MParameterType

The type associated to a formal parameter generic type of a class
redef abstract class MPropDef

nitc :: html_model $ MPropDef

A definition of a property (local property)
redef abstract class MProperty

nitc :: html_model $ MProperty

A service (global property) that generalize method, attribute, etc.
redef class MSignature

nitc :: html_model $ MSignature

A signature of a method
redef abstract class MType

nitc :: html_model $ MType

A global static type
redef class MVirtualType

nitc :: html_model $ MVirtualType

A virtual formal type.
redef class MVirtualTypeDef

nitc :: html_model $ MVirtualTypeDef

A local definition of a virtual type
redef class MVirtualTypeProp

nitc :: html_model $ MVirtualTypeProp

A global virtual type
redef class Model

nitc :: html_model $ Model

The container class of a Nit object-oriented model.
redef class Person

nitc :: html_model $ Person

A contributor/author/etc.

All class definitions

class InlineDecorator

nitc $ InlineDecorator

Decorator for span elements.
redef class MAttributeDef

nitc :: html_model $ MAttributeDef

A local definition of an attribute
redef class MClass

nitc :: html_model $ MClass

A named class
redef class MClassDef

nitc :: html_model $ MClassDef

A definition (an introduction or a refinement) of a class in a module
redef class MClassType

nitc :: html_model $ MClassType

A type based on a class.
redef class MDoc

nitc :: html_model $ MDoc

Structured documentation of a MEntity object
redef abstract class MEntity

nitc :: html_model $ MEntity

A named and possibly documented entity in the model.
redef class MGenericType

nitc :: html_model $ MGenericType

A type based on a generic class.
redef class MGroup

nitc :: html_model $ MGroup

A group of modules in a package
redef class MMethodDef

nitc :: html_model $ MMethodDef

A local definition of a method
redef class MModule

nitc :: html_model $ MModule

A Nit module is usually associated with a Nit source file.
redef class MNullableType

nitc :: html_model $ MNullableType

A type prefixed with "nullable"
redef class MPackage

nitc :: html_model $ MPackage

A Nit package, that encompass a product
redef class MParameter

nitc :: html_model $ MParameter

A parameter in a signature
redef class MParameterType

nitc :: html_model $ MParameterType

The type associated to a formal parameter generic type of a class
redef abstract class MPropDef

nitc :: html_model $ MPropDef

A definition of a property (local property)
redef abstract class MProperty

nitc :: html_model $ MProperty

A service (global property) that generalize method, attribute, etc.
redef class MSignature

nitc :: html_model $ MSignature

A signature of a method
redef abstract class MType

nitc :: html_model $ MType

A global static type
redef class MVirtualType

nitc :: html_model $ MVirtualType

A virtual formal type.
redef class MVirtualTypeDef

nitc :: html_model $ MVirtualTypeDef

A local definition of a virtual type
redef class MVirtualTypeProp

nitc :: html_model $ MVirtualTypeProp

A global virtual type
redef class Model

nitc :: html_model $ Model

The container class of a Nit object-oriented model.
class NitdocDecorator

nitc $ NitdocDecorator

The specific markdown decorator used internally to process MDoc object.
redef class Person

nitc :: html_model $ Person

A contributor/author/etc.
package_diagram nitc::html_model html_model nitc::model_collect model_collect nitc::html_model->nitc::model_collect nitc\>catalog\> catalog nitc::html_model->nitc\>catalog\> markdown markdown nitc::html_model->markdown nitc::htmlight htmlight nitc::html_model->nitc::htmlight html::bootstrap bootstrap nitc::html_model->html::bootstrap nitc::model_filters model_filters nitc::model_collect->nitc::model_filters md5 md5 nitc\>catalog\>->md5 counter counter nitc\>catalog\>->counter nitc\>modelize\> modelize nitc\>catalog\>->nitc\>modelize\> template template markdown->template config config markdown->config nitc::highlight highlight nitc::htmlight->nitc::highlight pipeline pipeline nitc::htmlight->pipeline html::bootstrap->template ...nitc::model_filters ... ...nitc::model_filters->nitc::model_filters ...md5 ... ...md5->md5 ...counter ... ...counter->counter ...nitc\>modelize\> ... ...nitc\>modelize\>->nitc\>modelize\> ...template ... ...template->template ...config ... ...config->config ...nitc::highlight ... ...nitc::highlight->nitc::highlight ...pipeline ... ...pipeline->pipeline nitc::nitcatalog nitcatalog nitc::nitcatalog->nitc::html_model nitc::html_commands html_commands nitc::html_commands->nitc::html_model nitc::json_model json_model nitc::json_model->nitc::html_model a_star-m a_star-m a_star-m->nitc::nitcatalog a_star-m... ... a_star-m...->a_star-m nitc::static_cards static_cards nitc::static_cards->nitc::html_commands nitc::api_base api_base nitc::api_base->nitc::html_commands nitc::static_cards... ... nitc::static_cards...->nitc::static_cards nitc::api_base... ... nitc::api_base...->nitc::api_base nitc::json_commands json_commands nitc::json_commands->nitc::json_model nitc::json_commands... ... nitc::json_commands...->nitc::json_commands

Ancestors

module abstract_collection

core :: abstract_collection

Abstract collection classes and services.
module abstract_text

core :: abstract_text

Abstract class for manipulation of sequences of characters
module actors_injection_phase

nitc :: actors_injection_phase

Injects model for the classes annotated with "is actor" so
module annotation

nitc :: annotation

Management and utilities on annotations
module array

core :: array

This module introduces the standard array structure.
module astbuilder

nitc :: astbuilder

Instantiation and transformation of semantic nodes in the AST of expressions and statements
module astutil

nitc :: astutil

Additional features on Nit AST
module auto_super_init

nitc :: auto_super_init

Computing of super-constructors that must be implicitly called at the begin of constructors.
module bitset

core :: bitset

Services to handle BitSet
module bytes

core :: bytes

Services for byte streams and arrays
module caching

serialization :: caching

Services for caching serialization engines
module check_annotation

nitc :: check_annotation

Check that annotation present in the AST are either primitive or user-declared
module circular_array

core :: circular_array

Efficient data structure to access both end of the sequence.
module codec_base

core :: codec_base

Base for codecs to use with streams
module codecs

core :: codecs

Group module for all codec-related manipulations
module collection

core :: collection

This module define several collection classes.
module console

console :: console

Defines some ANSI Terminal Control Escape Sequences.
module core

core :: core

Standard classes and methods used by default by Nit programs and libraries.
module counter

counter :: counter

Simple numerical statistical analysis and presentation
module deriving

nitc :: deriving

Injection of automatic method definitions for standard methods, based on the attributes of the classes
module digraph

graph :: digraph

Implementation of directed graphs, also called digraphs.
module div_by_zero

nitc :: div_by_zero

Detection of divisions by zero in obvious cases
module engine_tools

serialization :: engine_tools

Advanced services for serialization engines
module environ

core :: environ

Access to the environment variables of the process
module error

core :: error

Standard error-management infrastructure.
module exec

core :: exec

Invocation and management of operating system sub-processes.
module file

core :: file

File manipulations (create, read, write, etc.)
module fixed_ints

core :: fixed_ints

Basic integers of fixed-precision
module fixed_ints_text

core :: fixed_ints_text

Text services to complement fixed_ints
module flat

core :: flat

All the array-based text representations
module flow

nitc :: flow

Intraprocedural static flow.
module frontend

nitc :: frontend

Collect and orchestration of main frontend phases
module gc

core :: gc

Access to the Nit internal garbage collection mechanism
module glsl_validation

nitc :: glsl_validation

Check shader code within Nit modules using the tool glslangValidator
module hash_collection

core :: hash_collection

Introduce HashMap and HashSet.
module highlight

nitc :: highlight

Highlighting of Nit AST
module html

html :: html

HTML output facilities
module i18n_phase

nitc :: i18n_phase

Basic support of internationalization through the generation of id-to-string tables
module ini

ini :: ini

Read and write INI configuration files
module inspect

serialization :: inspect

Refine Serializable::inspect to show more useful information
module iso8859_1

core :: iso8859_1

Codec for ISO8859-1 I/O
module kernel

core :: kernel

Most basic classes and methods.
module lexer

nitc :: lexer

Lexer and its tokens.
module lexer_work

nitc :: lexer_work

Internal algorithm and data structures for the Nit lexer
module list

core :: list

This module handle double linked lists
module literal

nitc :: literal

Parsing of literal values in the abstract syntax tree.
module loader

nitc :: loader

Loading of Nit source files
module local_var_init

nitc :: local_var_init

Verify that local variables are initialized before their usage
module location

nitc :: location

Nit source-file and locations in source-file
module math

core :: math

Mathematical operations
module md5

md5 :: md5

Native MD5 digest implementation as Text::md5
module mdoc

nitc :: mdoc

Documentation of model entities
module meta

meta :: meta

Simple user-defined meta-level to manipulate types of instances as object.
module mmodule

nitc :: mmodule

modules and module hierarchies in the metamodel
module mmodule_data

nitc :: mmodule_data

Define and retrieve data in modules
module model

nitc :: model

Classes, types and properties
module model_base

nitc :: model_base

The abstract concept of model and related common things
module model_examples

nitc :: model_examples

Examples for Model entities
module modelbuilder_base

nitc :: modelbuilder_base

Load nit source files and build the associated model
module modelize

nitc :: modelize

Create a model from nit source files
module modelize_class

nitc :: modelize_class

Analysis and verification of class definitions to instantiate model element
module modelize_property

nitc :: modelize_property

Analysis and verification of property definitions to instantiate model element
module more_collections

more_collections :: more_collections

Highly specific, but useful, collections-related classes.
module mpackage

nitc :: mpackage

Modelisation of a Nit package
module native

core :: native

Native structures for text and bytes
module nitpm_shared

nitc :: nitpm_shared

Services related to the Nit package manager
module no_warning

nitc :: no_warning

Fill toolcontext information about blacklisting of warnings.
module numeric

core :: numeric

Advanced services for Numeric types
module opts

opts :: opts

Management of options on the command line
module ordered_tree

ordered_tree :: ordered_tree

Manipulation and presentation of ordered trees.
module parallelization_phase

nitc :: parallelization_phase

Phase generating threads for functions annotated with threaded annotation
module parse_annotations

nitc :: parse_annotations

Simple annotation parsing
module parser

nitc :: parser

Parser.
module parser_nodes

nitc :: parser_nodes

AST nodes of the Nit language
module parser_prod

nitc :: parser_prod

Production AST nodes full definition.
module parser_util

nitc :: parser_util

Utils and tools related to parsers and AST
module parser_work

nitc :: parser_work

Internal algorithm and data structures for the Nit parser
module phase

nitc :: phase

Phases of the processing of nit programs
module pipeline

pipeline :: pipeline

Pipelined filters and operations on iterators.
module poset

poset :: poset

Pre order sets and partial order set (ie hierarchies)
module protocol

core :: protocol

module queue

core :: queue

Queuing data structures and wrappers
module range

core :: range

Module for range of discrete objects.
module re

core :: re

Regular expression support for all services based on Pattern
module regex_phase

nitc :: regex_phase

Check for error in regular expressions from string literals
module ropes

core :: ropes

Tree-based representation of a String.
module scope

nitc :: scope

Identification and scoping of local variables and labels.
module semantize

nitc :: semantize

Process bodies of methods in regard with the model.
module serialization

serialization :: serialization

General serialization services
module serialization_core

serialization :: serialization_core

Abstract services to serialize Nit objects to different formats
module serialization_model_phase

nitc :: serialization_model_phase

Phase generating methods (model-only) to serialize Nit objects
module simple_misc_analysis

nitc :: simple_misc_analysis

Simple vavious processing on a AST
module sorter

core :: sorter

This module contains classes used to compare things and sorts arrays.
module stream

core :: stream

Input and output streams of characters
module tables

nitc :: tables

Module that interfaces the parsing tables.
module template

template :: template

Basic template system
module text

core :: text

All the classes and methods related to the manipulation of text entities
module time

core :: time

Management of time and dates
module toolcontext

nitc :: toolcontext

Common command-line tool infrastructure than handle options and error messages
module typing

nitc :: typing

Intraprocedural resolution of static types and OO-services
module union_find

core :: union_find

union–find algorithm using an efficient disjoint-set data structure
module utf8

core :: utf8

Codec for UTF-8 I/O
module version

nitc :: version

This file was generated by git-gen-version.sh

Parents

module bootstrap

html :: bootstrap

HTML templates for Bootstrap components.
module catalog

nitc :: catalog

Basic catalog generator for Nit packages
module htmlight

nitc :: htmlight

Highlighting of Nit AST with HTML
module markdown

markdown :: markdown

Markdown parsing.
module model_collect

nitc :: model_collect

Collect things from the model.

Children

module html_commands

nitc :: html_commands

Render commands results as HTML
module json_model

nitc :: json_model

Make model entities Serializable.
module nitcatalog

nitc :: nitcatalog

Basic catalog generator for Nit packages

Descendants

module a_star-m

a_star-m

module api

nitc :: api

Components required to build a web server about the nit model.
module api_auth

nitc :: api_auth

module api_base

nitc :: api_base

Base classes used by nitweb.
module api_docdown

nitc :: api_docdown

Nitdoc specific Markdown format handling for Nitweb
module api_feedback

nitc :: api_feedback

Feedback related features
module api_light

nitc :: api_light

Highlight and collect messages from a piece of code
module api_model

nitc :: api_model

module json_commands

nitc :: json_commands

Translate command results to json
module nitdoc

nitc :: nitdoc

Generator of static API documentation for the Nit language
module nitweb

nitc :: nitweb

Runs a webserver based on nitcorn that render things from model.
module static

nitc :: static

Nitdoc generation framework
module static_base

nitc :: static_base

Base entities shared by all the nitdoc code
module static_cards

nitc :: static_cards

Cards templates for the static documentation
module static_html

nitc :: static_html

Render documentation pages as HTML
module static_index

nitc :: static_index

Manage indexing of Nit model for Nitdoc QuickSearch.
module static_structure

nitc :: static_structure

Composes the pages of the static documentation
# Translate mentities to html blocks.
module html_model

import model::model_collect
import catalog

import markdown
import htmlight
import html::bootstrap
private import parser_util

redef class MEntity

	# The MEntity unique ID in the HTML output
	var html_id: String is lazy do return full_name.to_cmangle

	# The MEntity URL in the HTML output
	#
	# You MUST redefine this method.
	# Depending on your implementation, this URL can be a page URL or an anchor.
	var html_url: String is lazy do return html_id

	# The MEntity name escaped for HTML
	var html_name: String is lazy do return name.html_escape

	# The MEntity `full_name` escaped for HTML
	var html_full_name: String is lazy do return full_name.html_escape

	# Link to the MEntity in the HTML output
	#
	# You should redefine this method depending on the organization or your
	# output.
	fun html_link(text, title: nullable String): Link do
		if text == null then
			text = html_name
		end
		var mdoc = self.mdoc_or_fallback
		if title == null and mdoc != null then
			title = mdoc.synopsis
		end
		return new Link(html_url, text, title)
	end

	# Returns the complete MEntity declaration decorated with HTML
	#
	# Examples:
	# * MPackage: `package foo`
	# * MGroup: `group foo`
	# * MModule: `module foo`
	# * MClass: `private abstract class Foo[E: Object]`
	# * MClassDef: `redef class Foo[E]`
	# * MProperty: `private fun foo(e: Object): Int`
	# * MPropdef: `redef fun foo(e)`
	fun html_declaration: Template do
		var tpl = new Template
		tpl.add "<span class='signature'>"
		for modifier in collect_modifiers do
			tpl.add "<span class='modifier'>{modifier}</span>&nbsp;"
		end
		tpl.add "<span class='name'>{html_link.write_to_string}</span>"
		tpl.add html_signature(false)
		tpl.add "</span>"
		return tpl
	end

	# Returns the MEntity signature decorated with HTML
	#
	# This function only returns the parenthesis and return types.
	# See `html_declaration` for the full declaration including modifiers and name.
	fun html_signature(short: nullable Bool): Template do return new Template

	# Returns `full_name` decorated with HTML links
	fun html_namespace: Template is abstract

	# An icon representative of the mentity
	fun html_icon: BSIcon do return new BSIcon("tag", ["text-muted"])

	# CSS classes used to decorate `self`
	#
	# Mainly used for icons.
	var css_classes: Array[String] = collect_modifiers is lazy
end

redef class MPackage
	redef fun html_namespace do return html_link
	redef fun html_icon do return new BSIcon("book", ["text-muted"])
	redef var css_classes = ["public"]
end

redef class MGroup
	redef fun html_icon do return new BSIcon("folder-close", ["text-muted"])

	redef fun html_namespace do
		var tpl = new Template
		var parent = self.parent
		if parent != null then
			tpl.add parent.html_namespace
			tpl.add " > "
		end
		tpl.add html_link
		return tpl
	end
end

redef class MModule
	redef fun html_icon do return new BSIcon("file", ["text-muted"])

	redef fun html_namespace do
		var mpackage = self.mpackage
		var tpl = new Template
		if mpackage != null then
			tpl.add mpackage.html_namespace
			tpl.add " :: "
		end
		tpl.add html_link
		return tpl
	end
end

redef class MClass
	redef fun html_icon do return new BSIcon("stop", css_classes)
	redef fun html_signature(short) do return intro.html_signature(short)
	redef fun css_classes do return super + [visibility.to_s]

	redef fun html_namespace do
		var mgroup = intro_mmodule.mgroup
		var tpl = new Template
		if mgroup != null then
			tpl.add mgroup.mpackage.html_namespace
			tpl.add " :: "
		end
		tpl.add "<span>"
		tpl.add html_link
		tpl.add "</span>"
		return tpl
	end
end

redef class MClassDef
	redef fun css_classes do return super + mclass.css_classes

	redef fun html_namespace do
		var tpl = new Template
		var mpackage = mmodule.mpackage
		if mpackage != null and is_intro then
			if is_intro then
				tpl.add mpackage.html_namespace
				tpl.add " $ "
			else
				tpl.add mmodule.html_namespace
				tpl.add " $ "
				var intro_mpackage = mclass.intro.mmodule.mpackage
				if intro_mpackage != null and mpackage != intro_mpackage then
					tpl.add intro_mpackage.html_namespace
					tpl.add " :: "
				end
			end
		else
			tpl.add mmodule.html_namespace
			tpl.add " $ "
		end
		tpl.add html_link
		return tpl
	end

	redef fun html_icon do
		if is_intro then
			return new BSIcon("plus", css_classes)
		end
		return new BSIcon("asterisk", css_classes)
	end

	redef fun html_signature(short) do
		var tpl = new Template
		var mparameters = mclass.mparameters
		if not mparameters.is_empty then
			tpl.add "["
			for i in [0..mparameters.length[ do
				tpl.add mparameters[i].html_name
				if short == null or not short then
					tpl.add ": "
					tpl.add bound_mtype.arguments[i].html_signature(short)
				end
				if i < mparameters.length - 1 then tpl.add ", "
			end
			tpl.add "]"
		end
		return tpl
	end
end

redef class MProperty
	redef fun html_declaration do return intro.html_declaration
	redef fun html_signature(short) do return intro.html_signature(short)
	redef fun html_icon do return new BSIcon("tag", css_classes)
	redef fun css_classes do return super + [visibility.to_s]

	redef fun html_namespace do
		var tpl = new Template
		tpl.add intro_mclassdef.mclass.html_namespace
		tpl.add " :: "
		tpl.add intro.html_link
		return tpl
	end
end

redef class MPropDef
	redef fun css_classes do return super + mproperty.css_classes

	redef fun html_namespace do
		var tpl = new Template
		tpl.add mclassdef.html_namespace
		tpl.add " :: "
		tpl.add html_link
		return tpl
	end

	redef fun html_icon do
		if is_intro then
			return new BSIcon("plus", css_classes)
		end
		return new BSIcon("asterisk", css_classes)
	end
end

redef class MAttributeDef
	redef fun html_signature(short) do
		var static_mtype = self.static_mtype
		var tpl = new Template
		if static_mtype != null then
			tpl.add ": "
			tpl.add static_mtype.html_signature(short)
		end
		return tpl
	end
end

redef class MMethodDef
	redef fun html_signature(short) do
		var msignature = self.msignature
		if msignature == null then return new Template
		return msignature.html_signature(short)
	end
end

redef class MVirtualTypeProp
	redef fun html_link(text, title) do return mvirtualtype.html_link(text, title)
end

redef class MVirtualTypeDef
	redef fun html_signature(short) do
		var bound = self.bound
		var tpl = new Template
		if bound == null then return tpl
		tpl.add ": "
		tpl.add bound.html_signature(short)
		return tpl
	end
end

redef class MType
	redef fun html_signature(short) do return html_link
end

redef class MClassType
	redef fun html_link(text, title) do return mclass.html_link(text, title)
end

redef class MNullableType
	redef fun html_signature(short) do
		var tpl = new Template
		tpl.add "nullable "
		tpl.add mtype.html_signature(short)
		return tpl
	end
end

redef class MGenericType
	redef fun html_signature(short) do
		var lnk = html_link
		var tpl = new Template
		tpl.add new Link(lnk.href, mclass.name.html_escape, lnk.title)
		tpl.add "["
		for i in [0..arguments.length[ do
			tpl.add arguments[i].html_signature(short)
			if i < arguments.length - 1 then tpl.add ", "
		end
		tpl.add "]"
		return tpl
	end
end

redef class MParameterType
	redef fun html_link(text, title) do
		if text == null then text = name
		if title == null then title = "formal type"
		return new Link("{mclass.html_url}#FT_{name.to_cmangle}", text, title)
	end
end

redef class MVirtualType
	redef fun html_link(text, title) do return mproperty.intro.html_link(text, title)
end

redef class MSignature
	redef fun html_signature(short) do
		var tpl = new Template
		if not mparameters.is_empty then
			tpl.add "("
			for i in [0..mparameters.length[ do
				tpl.add mparameters[i].html_signature(short)
				if i < mparameters.length - 1 then tpl.add ", "
			end
			tpl.add ")"
		end
		if short == null or not short then
			var return_mtype = self.return_mtype
			if return_mtype != null then
				tpl.add ": "
				tpl.add return_mtype.html_signature(short)
			end
		end
		return tpl
	end
end

redef class MParameter
	redef fun html_signature(short) do
		var tpl = new Template
		tpl.add name
		if short == null or not short then
			tpl.add ": "
			tpl.add mtype.html_signature(short)
		end
		if is_vararg then tpl.add "..."
		return tpl
	end
end

# Catalog

redef class Person

	# HTML uniq id
	fun html_id: String do return name.to_cmangle

	# HTML default URL
	#
	# Should be redefined in clients.
	fun html_url: String do return "person_{html_id}.html"

	# Link to this person `html_url`
	fun html_link: Link do return new Link(html_url, name)

	# Render `self` as HTML
	fun to_html: String do
		var tpl = new Template
		tpl.addn "<span>"
		var gravatar = self.gravatar
		if gravatar != null then
			tpl.addn "<img class='avatar' src='https://secure.gravatar.com/avatar/{gravatar}?size=14&amp;default=retro' />"
		end
		tpl.addn html_link
		tpl.addn "</span>"
		return tpl.write_to_string
	end
end

# MDoc

redef class MDoc

	private var markdown_proc: MarkdownProcessor is lazy, writable do
		return original_mentity.as(not null).model.nitdoc_md_processor
	end

	private var inline_proc: MarkdownProcessor is lazy, writable do
		return original_mentity.as(not null).model.nitdoc_inline_processor
	end

	# 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=\"synopsis nitdoc\">{syn}</span>"
		return res
	end

	# 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
		var decorator = markdown_proc.decorator.as(NitdocDecorator)
		decorator.current_mdoc = self
		res.add "<div class=\"nitdoc\">"
		# do not use DocUnit as synopsis
		if not lines.is_empty then
			if not lines.first.has_prefix("    ") and
			   not lines.first.has_prefix("\t") then
				# parse synopsis
				var syn = inline_proc.process(lines.shift)
				res.add "<h1 class=\"synopsis\">{syn}</h1>"
			end
		end
		# check for annotations
		for i in [0 .. lines.length[ do
			var line = lines[i]
			if line.to_upper.has_prefix("ENSURE") or line.to_upper.has_prefix("REQUIRE") then
				var html = inline_proc.process(line)
				lines[i] = "<p class=\"contract\">{html}</p>"
			else if line.to_upper.has_prefix("TODO") or line.to_upper.has_prefix("FIXME") then
				var html = inline_proc.process(line)
				lines[i] = "<p class=\"todo\">{html}</p>"
			end
		end
		# add other lines
		res.add markdown_proc.process(lines.join("\n"))
		res.add "</div>"
		decorator.current_mdoc = null
		return res
	end
end

# 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

# Decorator for span elements.
#
# Because inline comments can appear as span elements,
# InlineDecorator do not decorate things like paragraphs or headers.
class InlineDecorator
	super NitdocDecorator

	redef fun add_paragraph(v, block) do
		v.emit_in block
	end

	redef fun add_headline(v, block) do
		# save headline
		var line = block.block.first_line
		if line == null then return
		var txt = line.value
		var id = strip_id(txt)
		var lvl = block.depth
		headlines[id] = new HeadLine(id, txt, lvl)

		v.emit_in block
	end

	redef fun add_code(v, block) do
		# Try to parse code
		var ast = toolcontext.parse_something(block.block.text.to_s)
		if ast isa AError then
			v.add "<code>"
			v.emit_in block
			v.add "</code>"
			return
		end
		v.add "<code class=\"nitcode\">"
		var hl = new HtmlightVisitor
		hl.highlight_node(ast)
		v.add(hl.html)
		v.add "</code>"
	end
end

redef class Model
	# Get a markdown processor for Nitdoc comments.
	var nitdoc_md_processor: MarkdownProcessor is lazy, writable do
		var proc = new MarkdownProcessor
		proc.decorator = new NitdocDecorator
		return proc
	end

	# Get a markdown inline processor for Nitdoc comments.
	#
	# This processor is specificaly designed to inlinable doc elements like synopsis.
	var nitdoc_inline_processor: MarkdownProcessor is lazy, writable do
		var proc = new MarkdownProcessor
		proc.decorator = new InlineDecorator
		return proc
	end
end
src/doc/templates/html_model.nit:15,1--570,3