markdown2 :: markdown_rendering $ MdLineBreak
A line break (soft or hard)markdown2 :: markdown_rendering $ MdLineBreak
A line break (soft or hard)core :: union_find
union–find algorithm using an efficient disjoint-set data structuremarkdown2 :: markdown_html_rendering
HTML rendering of Markdown documentsmarkdown2 :: markdown_latex_rendering
LaTeX rendering of Markdown documentsmarkdown2 :: markdown_man_rendering
Manpages rendering of Markdown documentsmarkdown2 :: markdown_md_rendering
Markdown rendering of Markdown documents
# Markdown document rendering
module markdown_rendering
import markdown_ast
# Common interface for all markdown renderer
interface MdRenderer
super MdVisitor
# Render `node`
fun render(node: MdNode): String is abstract
end
# A renderer that output raw text
class RawTextVisitor
super MdRenderer
# Text under construction
private var text: Buffer is noinit
redef fun render(node) do
text = new Buffer
enter_visit(node)
return text.to_s
end
# Append `string` to `text`
fun add(string: String) do text.append(string)
redef fun visit(node) do node.render_raw_text(self)
end
redef class MdNode
# Return `self` as raw text
fun raw_text: String do
var v = new RawTextVisitor
return v.render(self)
end
# Render `self` as raw text
fun render_raw_text(v: RawTextVisitor) do visit_all(v)
end
redef class MdCode
redef fun render_raw_text(v) do v.add literal
end
redef class MdLineBreak
redef fun render_raw_text(v) do v.add "\n"
end
redef class MdText
redef fun render_raw_text(v) do v.add literal
end
lib/markdown2/markdown_rendering.nit:15,1--69,3