The Zuri Standard Library Zuri

Text and Markup

markdown.renderer

import markdown.renderer
Zuri

markdown lifts part of this module out to its own top level; each name below is shown with the path that reaches it. Anything still spelled markdown.renderer.* needs import 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/)')
Zuri

Inside 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
Zuri

Renders 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(), so echo and print() 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)
Zuri

Parameters

  • options (dict) — the resolved options of the Markdown object that's rendering the document.

HtmlRenderer.render()

markdown.HtmlRenderer.render(node: instance) -> string
Zuri

Returns 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)
Zuri

Adds 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)
Zuri

Adds text to the output, escaped for HTML.

Parameters

  • text (string)

HtmlRenderer.cr()

markdown.HtmlRenderer.cr()
Zuri

Starts a new line, unless the output is already at the start of one.

HtmlRenderer.escape()

markdown.HtmlRenderer.escape(text: string) -> string
Zuri

Returns text escaped for HTML.

Parameters

  • text (string)

Returns string

HtmlRenderer.url()

markdown.HtmlRenderer.url(destination: string) -> string
Zuri

Returns 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
Zuri

Returns 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)
Zuri

Renders 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)
Zuri

Renders the children of node, in order.

Parameters

  • node (Node)

HtmlRenderer.unknown()

markdown.HtmlRenderer.unknown(node: instance)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.paragraph()

markdown.HtmlRenderer.paragraph(node: instance)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.thematic_break()

markdown.HtmlRenderer.thematic_break(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.block_quote()

markdown.HtmlRenderer.block_quote(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.alert()

markdown.HtmlRenderer.alert(node: instance)
Zuri

Renders a GitHub alert, using the same markup as GitHub.

Parameters

  • node (Node)

HtmlRenderer.list()

markdown.HtmlRenderer.list(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.item()

markdown.HtmlRenderer.item(node: instance)
Zuri

Renders a list item. A task list item starts with a disabled checkbox.

Parameters

  • node (Node)

HtmlRenderer.code_block()

markdown.HtmlRenderer.code_block(node: instance)
Zuri

Renders 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)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.table_section()

markdown.HtmlRenderer.table_section(node: instance)
Zuri

Renders a table's <thead> or <tbody>.

Parameters

  • node (Node)

HtmlRenderer.table_row()

markdown.HtmlRenderer.table_row(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.table_cell()

markdown.HtmlRenderer.table_cell(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.footnote_definition()

markdown.HtmlRenderer.footnote_definition(node: instance)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.term()

markdown.HtmlRenderer.term(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.definition()

markdown.HtmlRenderer.definition(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.div()

markdown.HtmlRenderer.div(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.line_block()

markdown.HtmlRenderer.line_block(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.line()

markdown.HtmlRenderer.line(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.math_block()

markdown.HtmlRenderer.math_block(node: instance)
Zuri

Renders a ```math block, in the markup that MathJax and KaTeX look for.

Parameters

  • node (Node)

HtmlRenderer.toc()

markdown.HtmlRenderer.toc(node: instance)
Zuri

Renders the document's table of contents, where [TOC] was written.

Parameters

  • node (Node)

HtmlRenderer.text_node()

markdown.HtmlRenderer.text_node(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.softbreak()

markdown.HtmlRenderer.softbreak(node: instance)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.code()

markdown.HtmlRenderer.code(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.emphasis()

markdown.HtmlRenderer.emphasis(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.strong()

markdown.HtmlRenderer.strong(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.strikethrough()

markdown.HtmlRenderer.strikethrough(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.mark()

markdown.HtmlRenderer.mark(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.superscript()

markdown.HtmlRenderer.superscript(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.subscript()

markdown.HtmlRenderer.subscript(node: instance)
Zuri

Parameters

  • node (Node)
markdown.HtmlRenderer.link(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.image()

markdown.HtmlRenderer.image(node: instance)
Zuri

Renders an image. Its description becomes the alt text, with all markup removed.

Parameters

  • node (Node)

HtmlRenderer.html_inline()

markdown.HtmlRenderer.html_inline(node: instance)
Zuri

Renders 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)
Zuri

Renders a footnote reference as its number, linked to the footnote.

Parameters

  • node (Node)

HtmlRenderer.span()

markdown.HtmlRenderer.span(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.math()

markdown.HtmlRenderer.math(node: instance)
Zuri

Renders 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)
Zuri

Parameters

  • node (Node)

HtmlRenderer.emoji()

markdown.HtmlRenderer.emoji(node: instance)
Zuri

Parameters

  • node (Node)

HtmlRenderer.footnotes()

markdown.HtmlRenderer.footnotes()
Zuri

Renders 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