notebook/cmark
the notebook's Markdown API, over the stdlib's tur/markdown.
Since: NB0
md-tag-document
(md-tag-document :)
md-tag-heading
(md-tag-heading :)
md-tag-paragraph
(md-tag-paragraph :)
md-tag-blockquote
(md-tag-blockquote :)
md-tag-list
(md-tag-list :)
md-tag-list-item
(md-tag-list-item :)
md-tag-code-block
(md-tag-code-block :)
md-tag-thematic-break
(md-tag-thematic-break :)
md-tag-table
(md-tag-table :)
md-tag-table-row
(md-tag-table-row :)
md-tag-table-cell
(md-tag-table-cell :)
md-tag-text
(md-tag-text :)
md-tag-emph
(md-tag-emph :)
md-tag-strong
(md-tag-strong :)
md-tag-code-span
(md-tag-code-span :)
md-tag-link
(md-tag-link :)
md-tag-image
(md-tag-image :)
md-tag-strikethrough
(md-tag-strikethrough :)
md-tag-autolink
(md-tag-autolink :)
md-tag-hard-break
(md-tag-hard-break :)
md-tag-soft-break
(md-tag-soft-break :)
md-tag-math-block
(md-tag-math-block :)
md-tag-math-inline
(md-tag-math-inline :)
md-tag-html-block
(md-tag-html-block :)
md-tag-html-inline
(md-tag-html-inline :)
md-node-free
(md-node-free [n : int])
free a node and its entire subtree. Safe on 0.
md-node-free-shell
(md-node-free-shell [n : int])
free a node's own storage but NOT its children.
md-children-free
(md-children-free [lst : int])
free a cons spine, leaving the nodes it names alone.
md-span-free
(md-span-free [span : int])
free the two-cell list md-source-span returned.
md-node-tag
(md-node-tag [n : int])
the tag of a parsed markdown node.
| n | node handle returned by md-parse or md-node-children |
One of the md-tag-* constants, or -1 for 0.
(md-node-tag (md-parse "# Hi")) ; => (md-tag-document)
Since: NB0
md-node-children
(md-node-children [n : int])
the children of a node as a cons list.
| n | node handle |
A cons list of child node handles in document order.
(md-node-children doc)
Since: NB0
md-node-text
(md-node-text [n : int])
a node's text.
| n | node handle |
A paragraph's, heading's or table cell's source text (inline syntax kept), a code block's or formula's body without its final line feed, an HTML block's or inline's HTML, a text or code span's text, or a link's or image's title; "" otherwise. Borrowed from the node.
(md-node-text heading) ; => "Hello" for "# Hello"
Since: NB0
md-node-info
(md-node-info [n : int])
a node's info.
| n | node handle |
A fenced code block's info string, a list's marker ("-", "+", "*", "." or ")"), or a link's or image's destination; "" otherwise. Borrowed.
(md-node-info code-block) ; => "turmeric {id=demo}"
Since: NB0
md-node-meta
(md-node-meta [n : int])
a node's integer fact.
| n | node handle |
A heading's level; an ordered list's start (0 for a bullet list); a list item's task box (0 none, 1 [ ], 2 [x]); 1 on a table's header row; a table cell's alignment (0 none, 1 left, 2 center, 3 right); else 0.
(md-node-meta heading) ; => 2 for "## Two"
Since: NB0
md-source-span
(md-source-span [n : int])
the start/end line pair for a node.
| n | node handle |
A fresh cons pair (start-line . end-line), both 1-based and inclusive; free it with md-span-free. An inline node has its block's lines.
(md-source-span node)
Since: NB0
md-emit
(md-emit [n : int])
a node's Markdown source.
| n | node handle |
A fresh string, owned by the caller.
(md-emit (md-parse "# Title")) ; => "# Title"
Since: NB0
md-emit-html
(md-emit-html [n : int])
a node's HTML, as tur/markdown renders it.
| n | node handle |
A fresh string, owned by the caller.
(md-emit-html (md-parse "# Title")) ; => "<h1>Title</h1>"
Since: NB0
md-parse
(md-parse [source : cstr])
parse a notebook's Markdown into a node tree.
| source | the Markdown text (borrowed) |
A document node owning its whole subtree; free it with md-node-free.
(md-parse "# Title\n\nParagraph.")
Since: NB0
Internal definitions
__md-node-new-- a fresh node record holding copies of text and info.__md-add-child!-- append child to parent's children.__md-set-md!-- give node a copy of s as its Markdown source.__md-set-html!-- give node a copy of s as its HTML.__md-drop-kids-cache-- release a node's cached children spine, if any.__md-opts-- what a notebook's Markdown is: CommonMark, the GFM extensions and math.__md-html-opts-- how it renders: raw HTML through GitHub's tag filter, headings without ids.__md-text-of-- the String in o, or a fresh empty one for (none).__md-chomp-- s without one final line feed, as a fresh String; s is released.__md-lines-text-- lines first..last (1-based, inclusive) of lines, joined by line feeds.__md-new-- a node record for kind with String text and info, both released.__md-set-md-string!-- set node's Markdown source from s, releasing s.__md-set-html-string!-- set node's HTML from s without its final line feed, releasing s.__md-inline-tag-- the md-tag-* of inline kind k.__md-inline-node-- a node for inline id of d, and its children, on lines start..end.__md-align-meta-- a table cell's alignment as md-node-meta has it.__md-task-meta-- a list item's task box as md-node-meta has it.__md-block-tag-- the md-tag-* of block kind b.__md-block-meta-- block kind b's md-node-meta.__md-block-text-- block id's md-node-text: a code block's or formula's body loses its final line feed.__md-block-info-- block id's md-node-info: a code block's info string or a list's marker.__md-block-node-- a node for block id of d and everything in it, with its Markdown source from lines.__md-blank-lines?-- are lines first..last (1-based, inclusive) all blank?__md-trim-blank-- first..last narrowed past the blank lines at either end, as (pair first last); first > last when all are blank.__md-gap-node!-- when lines first..last hold more than blank lines (link reference definitions), add a paragraph node holding them, with no HTML, to doc; first..last as given.__md-head-- the head of a cons cell.__md-tail-- the tail of a cons cell.__md-free-cstr-- free a malloc'd string.__md-doc-md-- the document's Markdown: its top-level nodes' sources, a blank line between each two.