Decorator that outputs HTML.

Introduced properties

Redefined properties

redef type SELF: HTMLDecorator

markdown $ HTMLDecorator :: SELF

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

markdown $ HTMLDecorator :: add_abbr

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

markdown $ HTMLDecorator :: add_blockquote

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

markdown $ HTMLDecorator :: add_code

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

markdown $ HTMLDecorator :: add_em

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

markdown $ HTMLDecorator :: add_headline

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

markdown $ HTMLDecorator :: add_image

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

markdown $ HTMLDecorator :: add_line_break

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

markdown $ HTMLDecorator :: add_listitem

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

markdown $ HTMLDecorator :: add_orderedlist

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

markdown $ HTMLDecorator :: add_paragraph

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

markdown $ HTMLDecorator :: add_ruler

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

markdown $ HTMLDecorator :: add_span_code

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

markdown $ HTMLDecorator :: add_strike

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

markdown $ HTMLDecorator :: add_strong

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

markdown $ HTMLDecorator :: add_unorderedlist

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

markdown $ HTMLDecorator :: append_code

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

markdown $ HTMLDecorator :: append_value

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

markdown $ HTMLDecorator :: escape_char

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

markdown $ HTMLDecorator :: headlines

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

markdown $ HTMLDecorator :: 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 :: 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.
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::HTMLDecorator HTMLDecorator markdown::Decorator Decorator markdown::HTMLDecorator->markdown::Decorator core::Object Object markdown::Decorator->core::Object ...core::Object ... ...core::Object->core::Object markdown::InlineDecorator InlineDecorator markdown::InlineDecorator->markdown::HTMLDecorator markdown::TestBlockDecorator TestBlockDecorator markdown::TestBlockDecorator->markdown::HTMLDecorator

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.

Children

class InlineDecorator

markdown :: InlineDecorator

Decorator for span elements.

Class definitions

markdown $ HTMLDecorator
# `Decorator` that outputs HTML.
class HTMLDecorator
	super Decorator

	redef var headlines = new ArrayMap[String, HeadLine]

	redef fun add_ruler(v, block) do v.add "<hr/>\n"

	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)
		# output it
		v.add "<h{lvl} id=\"{id}\">"
		v.emit_in block
		v.add "</h{lvl}>\n"
	end

	redef fun add_paragraph(v, block) do
		v.add "<p>"
		v.emit_in block
		v.add "</p>\n"
	end

	redef fun add_code(v, block) do
		var meta = block.meta
		if meta != null then
			v.add "<pre class=\""
			append_value(v, meta)
			v.add "\"><code>"
		else
			v.add "<pre><code>"
		end
		v.emit_in block
		v.add "</code></pre>\n"
	end

	redef fun add_blockquote(v, block) do
		v.add "<blockquote>\n"
		v.emit_in block
		v.add "</blockquote>\n"
	end

	redef fun add_unorderedlist(v, block) do
		v.add "<ul>\n"
		v.emit_in block
		v.add "</ul>\n"
	end

	redef fun add_orderedlist(v, block) do
		v.add "<ol>\n"
		v.emit_in block
		v.add "</ol>\n"
	end

	redef fun add_listitem(v, block) do
		v.add "<li>"
		v.emit_in block
		v.add "</li>\n"
	end

	redef fun add_em(v, text) do
		v.add "<em>"
		v.add text
		v.add "</em>"
	end

	redef fun add_strong(v, text) do
		v.add "<strong>"
		v.add text
		v.add "</strong>"
	end

	redef fun add_strike(v, text) do
		v.add "<del>"
		v.add text
		v.add "</del>"
	end

	redef fun add_image(v, link, name, comment) do
		v.add "<img src=\""
		append_value(v, link)
		v.add "\" alt=\""
		append_value(v, name)
		v.add "\""
		if comment != null and not comment.is_empty then
			v.add " title=\""
			append_value(v, comment)
			v.add "\""
		end
		v.add "/>"
	end

	redef fun add_link(v, link, name, comment) do
		v.add "<a href=\""
		append_value(v, link)
		v.add "\""
		if comment != null and not comment.is_empty then
			v.add " title=\""
			append_value(v, comment)
			v.add "\""
		end
		v.add ">"
		v.emit_text(name)
		v.add "</a>"
	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 "<code>"
		append_code(v, text, from, to)
		v.add "</code>"
	end

	redef fun add_line_break(v) do
		v.add "<br/>"
	end

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

	redef fun escape_char(v, c) do
		if c == '&' then
			v.add "&amp;"
		else if c == '<' then
			v.add "&lt;"
		else if c == '>' then
			v.add "&gt;"
		else if c == '"' then
			v.add "&quot;"
		else if c == '\'' then
			v.add "&apos;"
		else
			v.addc c
		end
	end

	redef fun append_code(v, buffer, from, to) do
		for i in [from..to[ do
			var c = buffer[i]
			if c == '&' then
				v.add "&amp;"
			else if c == '<' then
				v.add "&lt;"
			else if c == '>' then
				v.add "&gt;"
			else
				v.addc c
			end
		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/markdown.nit:729,1--919,3