Parse, expand and render Markdown.

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.link(target, alias?)

Markdown for a wiki link: to a page, to an object by its ref, or to a page or ref given as a string. Nothing when there's nothing to link to, so a missing attribute leaves an empty table cell.

Parameters:

  • target (any) — A page object (linked by its name), any other object (linked by its ref), or a page name or ref.
  • alias? (string) — Text to show instead of the target.

Returns:

  • string — The link, or nil.

Example:

markdown.link(p)
markdown.link("Books/Dune", "Dune")

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.
Loading SilverBullet…