moonmd markdown

a markdown reader

Markdown, read into a tree.

CommonMark 0.31.2 and GitHub Flavored Markdown for MoonBit. A document becomes blocks and inlines you can walk, renders as HTML or as Markdown again, and can be read a chunk at a time while it is still being written.

moon add moonbitstack/moonmd read the guide

commonmark 0.31.2 tables, strikethrough, autolinks, task lists, footnotes, tag filter native, js, wasm, wasm-gc

the workbench

Set a page.

Everything below is this library compiled to JavaScript: the same parser, the same renderer, no second implementation. Type in the left column; the right one follows.

sourceeditable
outputsettling
loading the engine

what it does

Four calls, one tree.

01 · read

Blocks first, then inlines

A line opens a container or closes one; what is left over is read for emphasis, links, code spans and entities. The pairing rules are the ones in the specification, not an approximation of them.

02 · write

HTML, safe by default

Raw HTML is escaped and a destination that would run script keeps its text and loses its link. Pass safe=false to reproduce the specification's output byte for byte.

03 · return

Back out as Markdown

The same tree writes itself out as Markdown that reads back to the same HTML: fences grow to clear their contents, text that would start a block is escaped.

04 · stream

Read while it is written

feed returns the blocks no later text can change, finish the rest. A chunk may end anywhere, including in the middle of a line.

the figures

652specification examples
29extension examples
0.31.2commonmark version
6extensions in gfm

counted from the example sets the package carries, not typed by hand.

read on

Two pages, the whole library.