CommonMark without any of the extensions.
the reference
Every public name.
Generated from the package interface and the comments in the sources, so the page cannot drift from the library: the docs workflow regenerates it and fails when the result differs from what is committed.
3 values · 2 functions · 9 methods · 19 types · one package, and the examples are not part of it.
§01
values
The preset parse uses when the caller does not pass one: gfm.
CommonMark as GitHub reads it: tables, strikethrough, bare links, task list items, the tag filter and footnotes. This is the default.
§02
functions
Parse a Markdown document.
test {
let document = @moonmd.parse("# Title")
assert_eq(document.html(safe=false), "<h1>Title</h1>\n")
}
Visit every node of the document, each container before its children and siblings in order.
§03
types
How a table column lines up its cells, taken from the delimiter row.
No colons in the delimiter row: the column follows the page.
A colon on the left only.
A colon on both ends.
A colon on the right only.
A block level node.
A heading of level 1 to 6.
A paragraph, holding its inlines.
A code block.
A block quote, holding the blocks inside it.
A bullet or ordered list.
A table.
A block of raw HTML, which the renderer escapes unless asked not to.
A thematic break, the line of three or more -, * or _.
The body of a footnote definition.
A line break inside a paragraph.
A newline in the source, which HTML renders as a space or a newline.
Two trailing spaces or a trailing backslash, which HTML renders as <br />.
A code block, fenced or indented. info is the word after the opening fence, empty for indented code.
A parsed document: the blocks in order, and the flavor it was read with, which the HTML renderer needs for the tag filter.
The top level blocks of the document, in order.
The flavor this document was parsed with.
Render the document as HTML. With safe set, which is the default, raw HTML is escaped and links to dangerous destinations lose their anchor; pass safe=false to write a document that may embed HTML of its own.
xhtml closes the elements that carry nothing (<br />, <hr />, <img />) the way the reference implementation does; pass xhtml=false for the form a document written to HTML5 uses.
The lines of the source each top level block was read from, counted from one, one entry per block of blocks() and in the same order. Blank lines between blocks belong to neither. A document assembled with of_blocks was not read from text, so its list is empty.
test {
let document = @moonmd.parse("# One\n\ntwo\n")
let spans = document.lines()
assert_eq((spans[0].first, spans[0].last), (1, 1))
assert_eq((spans[1].first, spans[1].last), (3, 3))
}
Render the document as Markdown.
Assemble a document out of blocks, which is what a caller collecting the output of a Stream needs in order to render it. Footnote references are resolved against the definitions in the blocks, so a definition read after the reference that uses it still applies.
What a parser accepts beyond the CommonMark core. The presets commonmark and gfm cover the two dialects this library is asked for; the fields are public so a caller can take one and drop what it does not want.
Pipe tables.
~one~ and ~~two~~ strikethrough.
Links written bare, without angle brackets or a destination.
- [ ] and - [x] list items.
Escape the raw HTML tags that would change the meaning of the page.
[^label] references with their [^label]: definitions.
Typographic punctuation: "x" and 'x' curl towards the text they wrap, --- and -- become an em and an en dash, and ... becomes an ellipsis. Code spans, raw HTML and destinations are left as written.
A line ending inside a paragraph is a hard break, the way a message box reads it, rather than the soft break the specification gives it.
A footnote, the body of one [^label]: definition. label is the label as it was written. number is the order the footnote is shown with, assigned in the order its first reference appears in the text; backrefs is how many references point at it.
The number the footnote is shown with, or 0 until the document is read.
The references that point at the footnote, in the order they appear.
A footnote reference, [^label], and where it lands: the definition's label, the number that definition is shown with, and ref_ix, the order of this reference among the ones that point at the definition.
The label of the definition the reference points at, as written.
The number the definition is shown with.
The order of this reference among the ones pointing at the definition.
A heading, level counting the ATX # marks or the setext underline.
An inline level node.
Literal text.
A code span, already with its newlines turned into spaces.
Emphasis with a single * or _.
Strong emphasis with a double * or _.
A link.
An image.
Raw inline HTML.
Struck out text between tildes.
A soft or hard line break.
A footnote reference, [^label], with the number of the definition it points at and its order among the references to that definition.
One item of a list, with the task marker that introduced it if any.
A run of source lines, counted from one, that a block was read from.
The first line of the run.
The last line of the run.
The destination, title and content of a link or image. For an image the content is the alternative text.
A list, with its items and whether it is tight (no blank lines between items, so their paragraphs are rendered without <p>).
What kind of list a ListBlock is, together with the marks needed to write it back unchanged.
-, + or *.
The first number, then . or ).
A node as walk hands it to its visitor: either a block or an inline.
A block level node, with everything inside it.
An inline level node, with everything inside it.
A parser that reads a document in pieces. Text that has arrived is parsed again on every call, but only the part that has not been handed out yet, so the work per chunk is proportional to the unfinished tail rather than to the whole document.
Take the next piece of the document and return the blocks it completed.
Close the stream and return whatever was still open.
Start a stream.
defer_links keeps a block that mentions [ back until the whole document has arrived, because a link reference definition written later still applies to it. With it off such a block is handed out as soon as it closes, at the cost of a forward reference not resolving; the blocks are then the same as a whole parse for any document that defines its labels before using them.
A table: the alignment of each column, the header row, then the body rows. A row holds one cell per column, and a cell holds the inlines inside it.
Whether a list item is a task list item, and if so whether it is done.
An ordinary list item.
[ ].
[x] or [X].
§04