The Markdown API provides functions for parsing and rendering Markdown content.

markdown.bakeSections

markdown.bakeSections(text, pageName?)

Re-evaluates all baked Lua sections in Markdown text; sections that error or only render as HTML are left unchanged.

Parameters:

  • text (string) — Markdown containing baked sections.
  • pageName? (string) — Page used as currentPage during evaluation.

Returns:

  • string — Markdown with updated baked section bodies.

Example:

local text = "Total: <!--#lua 1 + 2 -->\nold\n<!-- /lua -->"
print(markdown.bakeSections(text))

markdown.expandMarkdown

markdown.expandMarkdown(text, options?) markdown.expandMarkdown(tree, options?)

Expands Markdown transclusions, Lua directives, and task references. Directive results are written as Markdown, or as HTML for widgets without Markdown (event handlers are dropped).

Parameters:

  • textOrTree — Markdown text or parsed tree.
  • options? (table) — Expansion switches: expandTransclusions, expandLuaDirectives, and rewriteTasks; all default to true. pageName: the page the text comes from, which directives run as (default: the open page).

Returns:

  • Value — Expanded text or tree, matching the input form.

Example:

local expanded = markdown.expandMarkdown("This is some Lua: ${1 + 2}")

markdown.markdownToHtml

markdown.markdownToHtml(text, options?)

Renders Markdown text to HTML.

Parameters:

  • text (string) — Markdown source.
  • options? (table) — HTML rendering options; expand = true first expands transclusions and Lua directives, as markdown.expandMarkdown does.

Returns:

  • string — Rendered HTML.

Example:

local html = markdown.markdownToHtml("# Title")

markdown.objectsToTable

markdown.objectsToTable(data, options?)

Formats a list of objects as a Markdown table.

Parameters:

  • data (table) — Rows to render.
  • options? (table) — Optional renderCell callback.

Returns:

  • string — Markdown table.

Example:

local tableText = markdown.objectsToTable({{name = "Pete", age = 20}})

markdown.parseMarkdown

markdown.parseMarkdown(text)

Parses Markdown text into a syntax tree.

Parameters:

  • text (string) — Markdown source.

Returns:

  • table — Parsed Markdown tree.

Example:

local tree = markdown.parseMarkdown("# Title")

markdown.renderParseTree

markdown.renderParseTree(tree)

Renders a Markdown syntax tree back to source text.

Parameters:

  • tree (table) — Markdown syntax tree.

Returns:

  • string — Rendered Markdown.

Example:

local tree = markdown.parseMarkdown("# Title")
print(markdown.renderParseTree(tree))

markdown.renderToDom

markdown.renderToDom(value)

Renders a Markdown string or a widget to a live DOM node (Space Lua only).

Parameters:

  • value (any) — Markdown string or widget.

Returns:

  • any — DOM node.