Decorator that outputs markdown.

Introduced properties

Redefined properties

redef type SELF: MdDecorator

markdown $ MdDecorator :: SELF

Type of this instance, automatically specialized in every class
redef fun add_abbr(v: PROCESSOR, name: Text, comment: Text)

markdown $ MdDecorator :: add_abbr

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

markdown $ MdDecorator :: add_blockquote

Render a blockquote.
redef fun add_code(v: PROCESSOR, block: BlockCode)

markdown $ MdDecorator :: add_code

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

markdown $ MdDecorator :: add_em

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

markdown $ MdDecorator :: add_headline

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

markdown $ MdDecorator :: add_image

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

markdown $ MdDecorator :: add_line_break

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

markdown $ MdDecorator :: add_listitem

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

markdown $ MdDecorator :: add_orderedlist

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

markdown $ MdDecorator :: add_paragraph

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

markdown $ MdDecorator :: add_ruler

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

markdown $ MdDecorator :: add_span_code

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

markdown $ MdDecorator :: add_strike

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

markdown $ MdDecorator :: add_strong

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

markdown $ MdDecorator :: add_unorderedlist

Render an unordered list.
redef fun append_code(v: PROCESSOR, buffer: Text, from: Int, to: Int)

markdown $ MdDecorator :: append_code

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

markdown $ MdDecorator :: append_value

Render a text and escape it.
redef fun escape_char(v: PROCESSOR, c: Char)

markdown $ MdDecorator :: escape_char

Render a character escape.
redef fun headlines: ArrayMap[String, HeadLine]

markdown $ MdDecorator :: headlines

Found headlines during the processing labeled by their ids.
redef fun strip_id(txt: String): String

markdown $ MdDecorator :: strip_id

Generate a new html valid id from a String.

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
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.
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.
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.
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 :: MdDecorator :: 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.
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.
package_diagram markdown::MdDecorator MdDecorator markdown::Decorator Decorator markdown::MdDecorator->markdown::Decorator core::Object Object markdown::Decorator->core::Object ...core::Object ... ...core::Object->core::Object

Ancestors

interface Object

core :: Object

The root of the class hierarchy.

Parents

interface Decorator

markdown :: Decorator

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

Class definitions

markdown $ MdDecorator
# `Decorator` that outputs markdown.
class MdDecorator
	super Decorator

	redef var headlines = new ArrayMap[String, HeadLine]

	redef fun add_ruler(v, block) do v.add "***\n"

	redef fun add_headline(v, block) do
		# save headline
		var txt = block.block.first_line.as(not null).value
		var id = strip_id(txt)
		var lvl = block.depth
		headlines[id] = new HeadLine(id, txt, lvl)
		v.add "{"#" * lvl} "
		v.emit_in block
		v.addn
	end

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

	redef fun add_code(v, block) do
		if block isa BlockFence and block.meta != null then
			v.add "~~~{block.meta.as(not null).to_s}"
		else
			v.add "~~~"
		end
		v.addn
		v.emit_in block
		v.add "~~~"
		v.addn
	end

	redef fun add_blockquote(v, block) do
		v.add "> "
		v.emit_in block
		v.addn
	end

	redef fun add_unorderedlist(v, block) do
		in_unorderedlist = true
		v.emit_in block
		in_unorderedlist = false
	end
	private var in_unorderedlist = false

	redef fun add_orderedlist(v, block) do
		in_orderedlist = true
		current_li = 0
		v.emit_in block
		in_orderedlist = false
	end
	private var in_orderedlist = false
	private var current_li = 0

	redef fun add_listitem(v, block) do
		if in_unorderedlist then
			v.add "* "
		else if in_orderedlist then
			current_li += 1
			v.add "{current_li} "
		end
		v.emit_in block
		v.addn
	end

	redef fun add_em(v, text) do
		v.add "*"
		v.add text
		v.add "*"
	end

	redef fun add_strong(v, text) do
		v.add "**"
		v.add text
		v.add "**"
	end

	redef fun add_strike(v, text) do
		v.add "~~"
		v.add text
		v.add "~~"
	end

	redef fun add_image(v, link, name, comment) do
		v.add "!["
		v.add name
		v.add "]("
		append_value(v, link)
		if comment != null and not comment.is_empty then
			v.add " "
			append_value(v, comment)
		end
		v.add ")"
	end

	redef fun add_link(v, link, name, comment) do
		v.add "["
		v.add name
		v.add "]("
		append_value(v, link)
		if comment != null and not comment.is_empty then
			v.add " "
			append_value(v, comment)
		end
		v.add ")"
	end

	redef fun add_abbr(v, name, comment) do
		v.add "<abbr title=\""
		append_value(v, comment)
		v.add "\">"
		v.emit_text(name)
		v.add "</abbr>"
	end

	redef fun add_span_code(v, text, from, to) do
		v.add "`"
		append_code(v, text, from, to)
		v.add "`"
	end

	redef fun add_line_break(v) do
		v.add "\n"
	end

	redef fun append_value(v, text) do for c in text do escape_char(v, c)

	redef fun escape_char(v, c) do v.addc(c)

	redef fun append_code(v, buffer, from, to) do
		for i in [from..to[ do
			v.addc buffer[i]
		end
	end

	redef fun strip_id(txt) do
		# strip id
		var b = new FlatBuffer
		for c in txt do
			if c == ' ' then
				b.add '_'
			else
				if not c.is_letter and
				   not c.is_digit and
				   not allowed_id_chars.has(c) then continue
				b.add c
			end
		end
		var res = b.to_s
		var key = res
		# check for multiple id definitions
		if headlines.has_key(key) then
			var i = 1
			key = "{res}_{i}"
			while headlines.has_key(key) do
				i += 1
				key = "{res}_{i}"
			end
		end
		return key
	end

	private var allowed_id_chars: Array[Char] = ['-', '_', ':', '.']
end
lib/markdown/decorators.nit:20,1--187,3