Text and Markup
markdown.renderer
import markdown.renderer
Zuri
markdownlifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelledmarkdown.renderer.*needsimport markdown.renderer.
Converts a parsed document to HTML.
HtmlRenderer produces the same markup as the CommonMark reference
implementation, byte for byte, so its output can be compared with that
of any other conforming renderer. Each node type is rendered by its own
method, which in most cases has the same name as the type. A subclass
can change how one kind of node is rendered by overriding just that
method:
import markdown
import markdown.renderer { HtmlRenderer }
class NewTabLinks < HtmlRenderer {
link(node) {
self.write('<a href="${self.escape(self.url(node.destination))}" target="_blank">')
self.render_children(node)
self.write('</a>')
}
}
var md = markdown({ renderer: NewTabLinks })
echo md.render('[Zuri](https://zuri-lang.github.io/zuri/)')
ZuriInside a method, write() adds markup unchanged, text() adds escaped
text, cr() starts a new line unless the output is already at the start
of one, and render_children() renders the node's children.
Classes
HtmlRenderer
class markdown.HtmlRenderer
ZuriRenders a parsed document as HTML.
A renderer renders one document at a time. A Markdown object creates a
new renderer for each document it renders, so a subclass can keep any
state it needs in its own fields.
- printable — has a
@to_string(), soechoandprint()show something useful
Fields
| Field | Type | Description |
|---|---|---|
options |
dict |
The options that the document was parsed with, after markdown() resolved them. |
Constructor
markdown.HtmlRenderer(options: dict)
ZuriParameters
options(dict) — the resolved options of theMarkdownobject that's rendering the document.
HtmlRenderer.render()
markdown.HtmlRenderer.render(node: instance) -> string
ZuriReturns the HTML for node and its descendants. For a document, the footnotes are added at the end.
Parameters
node(Node)
Returns string
HtmlRenderer.write()
markdown.HtmlRenderer.write(markup: string)
ZuriAdds markup to the output unchanged. Inside an image's description, where only text is allowed, it adds nothing.
Parameters
markup(string)
HtmlRenderer.text()
markdown.HtmlRenderer.text(text: string)
ZuriAdds text to the output, escaped for HTML.
Parameters
text(string)
HtmlRenderer.cr()
markdown.HtmlRenderer.cr()
ZuriStarts a new line, unless the output is already at the start of one.
HtmlRenderer.escape()
markdown.HtmlRenderer.escape(text: string) -> string
ZuriReturns text escaped for HTML.
Parameters
text(string)
Returns string
HtmlRenderer.url()
markdown.HtmlRenderer.url(destination: string) -> string
ZuriReturns destination in a form that can go in an href or src
attribute. Returns '' if it uses a scheme that a page shouldn't
follow: javascript:, vbscript:, file:, or a data: URL that isn't
a PNG, GIF, JPEG or WebP image. With the unsafe_links option, every
destination is allowed.
Parameters
destination(string)
Returns string
HtmlRenderer.attributes()
markdown.HtmlRenderer.attributes(node: instance, extra: ?dict) -> string
ZuriReturns the attributes of node, with extra before them, as markup to
follow a tag name, starting with a space. If both have a class, the
classes are merged. When raw HTML is off, an attribute name that could
be used to run a script gets a data- prefix.
Parameters
node(Node)extra(?dict)
Returns string
HtmlRenderer.render_node()
markdown.HtmlRenderer.render_node(node: instance)
ZuriRenders node by calling the method for its type, which usually has the
same name as the type. A type that this class doesn't know is passed to
unknown().
Parameters
node(Node)
HtmlRenderer.render_children()
markdown.HtmlRenderer.render_children(node: instance)
ZuriRenders the children of node, in order.
Parameters
node(Node)
HtmlRenderer.unknown()
markdown.HtmlRenderer.unknown(node: instance)
ZuriRenders a node of a type that has no method, such as one added by a transform. Only its children are rendered.
Parameters
node(Node)
HtmlRenderer.document()
markdown.HtmlRenderer.document(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.paragraph()
markdown.HtmlRenderer.paragraph(node: instance)
ZuriRenders a paragraph. The <p> tags are left out in a tight list or a
tight definition.
Parameters
node(Node)
HtmlRenderer.heading()
markdown.HtmlRenderer.heading(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.thematic_break()
markdown.HtmlRenderer.thematic_break(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.block_quote()
markdown.HtmlRenderer.block_quote(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.alert()
markdown.HtmlRenderer.alert(node: instance)
ZuriRenders a GitHub alert, using the same markup as GitHub.
Parameters
node(Node)
HtmlRenderer.list()
markdown.HtmlRenderer.list(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.item()
markdown.HtmlRenderer.item(node: instance)
ZuriRenders a list item. A task list item starts with a disabled checkbox.
Parameters
node(Node)
HtmlRenderer.code_block()
markdown.HtmlRenderer.code_block(node: instance)
ZuriRenders a code block. The first word of the info string becomes a
language- class on the <code> element. If the highlight option is
set, its function can supply the markup for the code.
Parameters
node(Node)
HtmlRenderer.html_block()
markdown.HtmlRenderer.html_block(node: instance)
ZuriRenders a block of raw HTML. It's written unchanged when the html
option is on, and shown as text otherwise.
Parameters
node(Node)
HtmlRenderer.table()
markdown.HtmlRenderer.table(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.table_section()
markdown.HtmlRenderer.table_section(node: instance)
ZuriRenders a table's <thead> or <tbody>.
Parameters
node(Node)
HtmlRenderer.table_row()
markdown.HtmlRenderer.table_row(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.table_cell()
markdown.HtmlRenderer.table_cell(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.footnote_definition()
markdown.HtmlRenderer.footnote_definition(node: instance)
ZuriRenders nothing. Footnotes are written together at the end of the
document, by footnotes().
Parameters
node(Node)
HtmlRenderer.definition_list()
markdown.HtmlRenderer.definition_list(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.term()
markdown.HtmlRenderer.term(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.definition()
markdown.HtmlRenderer.definition(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.div()
markdown.HtmlRenderer.div(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.line_block()
markdown.HtmlRenderer.line_block(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.line()
markdown.HtmlRenderer.line(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.math_block()
markdown.HtmlRenderer.math_block(node: instance)
ZuriRenders a ```math block, in the markup that MathJax and KaTeX look for.
Parameters
node(Node)
HtmlRenderer.toc()
markdown.HtmlRenderer.toc(node: instance)
ZuriRenders the document's table of contents, where [TOC] was written.
Parameters
node(Node)
HtmlRenderer.text_node()
markdown.HtmlRenderer.text_node(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.softbreak()
markdown.HtmlRenderer.softbreak(node: instance)
ZuriRenders a line ending inside a paragraph, as a newline, or as <br />
when the breaks option is on.
Parameters
node(Node)
HtmlRenderer.linebreak()
markdown.HtmlRenderer.linebreak(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.code()
markdown.HtmlRenderer.code(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.emphasis()
markdown.HtmlRenderer.emphasis(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.strong()
markdown.HtmlRenderer.strong(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.strikethrough()
markdown.HtmlRenderer.strikethrough(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.mark()
markdown.HtmlRenderer.mark(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.superscript()
markdown.HtmlRenderer.superscript(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.subscript()
markdown.HtmlRenderer.subscript(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.link()
markdown.HtmlRenderer.link(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.image()
markdown.HtmlRenderer.image(node: instance)
ZuriRenders an image. Its description becomes the alt text, with all
markup removed.
Parameters
node(Node)
HtmlRenderer.html_inline()
markdown.HtmlRenderer.html_inline(node: instance)
ZuriRenders raw HTML inside a paragraph. It's written unchanged when the
html option is on, and shown as text otherwise.
Parameters
node(Node)
HtmlRenderer.footnote_reference()
markdown.HtmlRenderer.footnote_reference(node: instance)
ZuriRenders a footnote reference as its number, linked to the footnote.
Parameters
node(Node)
HtmlRenderer.span()
markdown.HtmlRenderer.span(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.math()
markdown.HtmlRenderer.math(node: instance)
ZuriRenders math in the markup that MathJax and KaTeX look for: \(...\)
for inline math, and \[...\] for display math.
Parameters
node(Node)
HtmlRenderer.abbreviation()
markdown.HtmlRenderer.abbreviation(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.emoji()
markdown.HtmlRenderer.emoji(node: instance)
ZuriParameters
node(Node)
HtmlRenderer.footnotes()
markdown.HtmlRenderer.footnotes()
ZuriRenders the footnotes that the document refers to, as a list at the end, in the order of their first reference.
2026, Richard Ore and Zuri contributors