Rich text / foldkit-richtext-markdown

Print a document

Each standard node kind and mark maps to a canonical Markdown spelling:

Document constructMarkdown output
Paragraph, HeadingText lines and # through ###### prefixes
Quote> prefix on every line, including blank lines
List, ListItem, TaskItem-, 1., and - [x] markers with nested alignment
CodeBlockBacktick fence longer than inner backticks, with language
ThematicBreak---
Image![alt](src) on its own line
FootnoteRef on a run[^label] in place of the label the run displays
FootnoteDefinition[^label]: with subsequent lines indented four spaces
Table, TableRow, TableCellGFM pipe table using the first row as the header
Bold, Italic, Code, Strikethrough, Link**, *, `, ~~, and [label](href)

Adjacent lists of the same kind alternate markers (- then *, . then )) so they parse back as separate lists.

Text is escaped to prevent unintended markup: backslashes precede inline delimiters, !, |, and paragraph-opening block markers (-, >, 1.). A leading space becomes  . When CommonMark rules block emphasis because punctuation borders a letter (x**(a)**y), the bordering letter is written as a numeric character reference (x**(a)**y), which parses back as the same letter. An empty task item prints as - [ ], and parse restores an item holding only [ ] or [x] as an empty task.