Markdown document renderer to LaTeX

Introduced properties

fun add_indent

markdown2 :: LatexRenderer :: add_indent

Add an indentation depending on ident level
fun add_line

markdown2 :: LatexRenderer :: add_line

Add a blank line to the output
fun add_raw(string: String)

markdown2 :: LatexRenderer :: add_raw

Add a raw string to the output
fun add_text(text: String)

markdown2 :: LatexRenderer :: add_text

Add text string to the output
init defaultinit(wrap_document: nullable Bool, document_class: nullable String, page_format: nullable String, font_size: nullable String, use_listings: nullable Bool)

markdown2 :: LatexRenderer :: defaultinit

fun document_class: String

markdown2 :: LatexRenderer :: document_class

LaTeX document class
fun document_class=(document_class: nullable String)

markdown2 :: LatexRenderer :: document_class=

LaTeX document class
fun escaped_chars: Array[Char]

markdown2 :: LatexRenderer :: escaped_chars

LaTeX characters to escape
protected fun escaped_chars=(escaped_chars: Array[Char])

markdown2 :: LatexRenderer :: escaped_chars=

LaTeX characters to escape
fun font_size: String

markdown2 :: LatexRenderer :: font_size

LaTeX font size
fun font_size=(font_size: nullable String)

markdown2 :: LatexRenderer :: font_size=

LaTeX font size
fun indent: Int

markdown2 :: LatexRenderer :: indent

Indentation level
protected fun indent=(indent: Int)

markdown2 :: LatexRenderer :: indent=

Indentation level
fun latex_escape(string: String): String

markdown2 :: LatexRenderer :: latex_escape

Escape string to LaTeX
fun page_format: String

markdown2 :: LatexRenderer :: page_format

LaTeX document page format
fun page_format=(page_format: nullable String)

markdown2 :: LatexRenderer :: page_format=

LaTeX document page format
fun use_listings: Bool

markdown2 :: LatexRenderer :: use_listings

Use listings package for code blocks?
fun use_listings=(use_listings: nullable Bool)

markdown2 :: LatexRenderer :: use_listings=

Use listings package for code blocks?
fun wrap_document: Bool

markdown2 :: LatexRenderer :: wrap_document

Generate the LaTeX document wrapper
fun wrap_document=(wrap_document: nullable Bool)

markdown2 :: LatexRenderer :: wrap_document=

Generate the LaTeX document wrapper

Redefined properties

redef type SELF: LatexRenderer

markdown2 $ LatexRenderer :: SELF

Type of this instance, automatically specialized in every class
redef fun render(document: MdNode): String

markdown2 $ LatexRenderer :: render

Render document as LaTeX
redef fun visit(node: MdNode)

markdown2 $ LatexRenderer :: visit

Visit node

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 SELF: Object

core :: Object :: SELF

Type of this instance, automatically specialized in every class
fun add_indent

markdown2 :: LatexRenderer :: add_indent

Add an indentation depending on ident level
fun add_line

markdown2 :: LatexRenderer :: add_line

Add a blank line to the output
fun add_raw(string: String)

markdown2 :: LatexRenderer :: add_raw

Add a raw string to the output
fun add_text(text: String)

markdown2 :: LatexRenderer :: add_text

Add text string to the output
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.
init defaultinit(wrap_document: nullable Bool, document_class: nullable String, page_format: nullable String, font_size: nullable String, use_listings: nullable Bool)

markdown2 :: LatexRenderer :: defaultinit

fun document_class: String

markdown2 :: LatexRenderer :: document_class

LaTeX document class
fun document_class=(document_class: nullable String)

markdown2 :: LatexRenderer :: document_class=

LaTeX document class
fun enter_visit(node: MdNode)

markdown2 :: MdVisitor :: enter_visit

Start visiting node
fun escaped_chars: Array[Char]

markdown2 :: LatexRenderer :: escaped_chars

LaTeX characters to escape
protected fun escaped_chars=(escaped_chars: Array[Char])

markdown2 :: LatexRenderer :: escaped_chars=

LaTeX characters to escape
fun font_size: String

markdown2 :: LatexRenderer :: font_size

LaTeX font size
fun font_size=(font_size: nullable String)

markdown2 :: LatexRenderer :: font_size=

LaTeX font size
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.
fun indent: Int

markdown2 :: LatexRenderer :: indent

Indentation level
protected fun indent=(indent: Int)

markdown2 :: LatexRenderer :: indent=

Indentation level
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.
fun latex_escape(string: String): String

markdown2 :: LatexRenderer :: latex_escape

Escape string to LaTeX
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 page_format: String

markdown2 :: LatexRenderer :: page_format

LaTeX document page format
fun page_format=(page_format: nullable String)

markdown2 :: LatexRenderer :: page_format=

LaTeX document page format
abstract fun render(node: MdNode): String

markdown2 :: MdRenderer :: render

Render node
fun serialization_hash: Int

core :: Object :: serialization_hash

Hash value use for serialization
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.
fun use_listings: Bool

markdown2 :: LatexRenderer :: use_listings

Use listings package for code blocks?
fun use_listings=(use_listings: nullable Bool)

markdown2 :: LatexRenderer :: use_listings=

Use listings package for code blocks?
protected abstract fun visit(node: MdNode)

markdown2 :: MdVisitor :: visit

Visit node
fun wrap_document: Bool

markdown2 :: LatexRenderer :: wrap_document

Generate the LaTeX document wrapper
fun wrap_document=(wrap_document: nullable Bool)

markdown2 :: LatexRenderer :: wrap_document=

Generate the LaTeX document wrapper
package_diagram markdown2::LatexRenderer LatexRenderer markdown2::MdRenderer MdRenderer markdown2::LatexRenderer->markdown2::MdRenderer markdown2::MdVisitor MdVisitor markdown2::MdRenderer->markdown2::MdVisitor ...markdown2::MdVisitor ... ...markdown2::MdVisitor->markdown2::MdVisitor

Ancestors

interface MdVisitor

markdown2 :: MdVisitor

A visitor for Markdown AST
interface Object

core :: Object

The root of the class hierarchy.

Parents

interface MdRenderer

markdown2 :: MdRenderer

Common interface for all markdown renderer

Class definitions

markdown2 $ LatexRenderer
# Markdown document renderer to LaTeX
class LatexRenderer
	super MdRenderer

	# Generate the LaTeX document wrapper
	#
	# The header includes:
	#  * document class
	#  * package importation
	#  * begin and end document directives
	var wrap_document = false is optional, writable

	# LaTeX document class
	#
	# Default is `article`.
	var document_class = "article" is optional, writable

	# LaTeX document page format
	#
	# Default is `letter`.
	var page_format = "letter" is optional, writable

	# LaTeX font size
	#
	# Default is `10pt`.
	var font_size = "10pt" is optional, writable

	# Use `listings` package for code blocks?
	var use_listings = false is optional, writable

	# LaTeX output under construction
	private var latex: Buffer is noinit

	# Render `document` as LaTeX
	redef fun render(document) do
		latex = new Buffer
		enter_visit(document)
		return latex.write_to_string
	end

	redef fun visit(node) do node.render_latex(self)

	# Indentation level
	var indent = 0

	# Add a raw `string` to the output
	#
	# Raw means that the string will not be escaped.
	fun add_raw(string: String) do latex.append string

	# Add `text` string to the output
	#
	# The string will be escaped.
	fun add_text(text: String) do latex.append latex_escape(text)

	# Add a blank line to the output
	fun add_line do
		if not latex.is_empty and latex.last != '\n' then
			latex.add '\n'
		end
	end

	# Add an indentation depending on `ident` level
	fun add_indent do latex.append " " * indent

	# Escape `string` to LaTeX
	fun latex_escape(string: String): String do
		var buffer = new Buffer
		for i in [0 .. string.length[ do
			var c = string.chars[i]
			if c == '>' then
				buffer.append "\\textgreater"
				continue
			else if c == '<' then
				buffer.append "\\textless"
				continue
			else if c == '\\' then
				buffer.append "\\textbackslash"
				continue
			else if escaped_chars.has(c) then
				buffer.add '\\'
			end
			buffer.add c
		end
		return buffer.to_s
	end

	# LaTeX characters to escape
	var escaped_chars = ['%', '$', '{', '}', '_', '#', '&']
end
lib/markdown2/markdown_latex_rendering.nit:22,1--111,3