md.q

Read Markdown as q data: .md.parse answers one row per block, .md.html renders XHTML. The dialect is CommonMark with tables, strikethrough and task lists.

Examples

t:.md.parse hsym `$"user-docs/c-extensions.md"
first exec val from t where kind=`table
.md.html "Hello *world*"

Entity Summary

EntitiesShort Description
.md.html[source]Markdown as XHTML
.md.parse[source]Markdown as a block table

Entity Details

.md.html[source]

The document rendered as XHTML: the contents of , following the CommonMark reference rendering.

Return: (string) the XHTML
Parameters:
  • source - (symbol|string|list) `:notes.md, a URL, the Markdown text, or a list of lines joined with newlines
throws: type a source that is none of those

Examples

.md.html "# Title\n\nSome *text*.\n\n---\n"

.md.parse[source]

The document's blocks as a flat table, one row per block in document order, so a document filters, splits by section and yields its code blocks and tables with ordinary q-sql. Inline markup is dropped from text: emphasis, links and code spans keep their text, a soft line break is a space and a hard one "\n".

Columns:
  • head - (long) the row number of the latest heading at or above it (a heading's own row), 0N before the first
  • val - (any) plain text for h and p, the text as written for code and html, "" for doc quote ul ol li hr, and for a table the q table .csv.read builds from its cells (names and types are .csv.read's)
  • parent - (long) the row number of the enclosing block, 0N for the doc row
  • depth - (long) how many blocks enclose it; the doc row is 0
  • level - (long) a heading's level 1 to 6, 0N for every other kind
  • kind - (symbol) the block: `doc `quote `ul `ol `li `hr `h `code `html `p `table
  • info - (string) a code block's info string ("q title=x"), a task-list item's mark ("x", "X" or " "), else ""
Return: (table) one row per block in document order
Parameters:
  • source - (symbol|string|list) `:notes.md, a URL, the Markdown text, or a list of lines joined with newlines
throws: type a source that is none of those

Examples

.md.parse "# Title\n\nSome *text*.\n\n- one\n- two\n"
t:.md.parse "# A\n\nx\n\n# B\n\ny\n"; select kind, val from t where head=3
exec val from .md.parse "```q\n1+1\n```\n\n```sh\nls\n```\n" where kind=`code, info like "q*"
first exec val from .md.parse["|a|b|\n|-|-|\n|1|x|"] where kind=`table