Skip to content

syntax/unified/micromark-quirks

Obsidian’s quirks as micromark extensions: where Obsidian reads valid CommonMark differently (see options.ts).

  • setextHeading: 'single-line': micromark’s setext underline construct is disabled and wrapped by one that first checks Obsidian’s rule, so an underline Obsidian does not read stays text, or is a thematic break. - emptyListItem: 'interrupts-paragraph': micromark’s list construct is wrapped by one that lets an empty item open a list where it interrupts a paragraph, unless the line is the paragraph’s setext underline. - softLineBreak: 'hard-break': a line ending inside inline content gets a hardBreakTrailing token before it, so the HTML compiler and mdast-util-from-markdown read it as a hard line break. - looseList: 'blank-line-anywhere': the HTML compiler decides whether a list is loose, from the events. A resolver marks each list the quirk makes loose, and micromarkQuirksHtml reads the mark. parseMdast applies the quirk to the mdast tree itself. - htmlBlock, htmlComment, characterReference, autolink and linkDefinition: constructs in place of micromark’s htmlFlow, htmlText, autolink and definition (and beside its characterReference, in inline content), with micromark’s tokens. A character reference’s and an autolink’s tokens carry what Obsidian reads, which micromarkQuirksHtml and parseMdast render. A probe at setext underlines leaves a one-line definition that one underlines to the paragraph. - gfmTable: micromarkObsidianTable replaces micromark-extension-gfm-table, with its tokens. - listItem: obsidianList (micromark-list.ts) replaces micromark’s list construct, and the other list quirks build on it.

The list handler of micromarkQuirksHtml is adapted from micromark’s HTML compiler, and its table handlers from micromark-extension-gfm-table’s, under their MIT license (see THIRD-PARTY-NOTICES.md).

Variable Description
micromarkObsidianTable The micromark table extension of the gfmTable quirk: tables as Obsidian reads them, with the tokens of micromark-extension-gfm-table, which it replaces, so gfmTableHtml and mdast-util-gfm-table compile them. micromarkQuirksHtml, after gfmTableHtml, keeps the backslash of `\
micromarkQuirksHtml The micromark HTML extension for the quirks: a list the looseList quirk made loose renders loose, a character reference or an autolink a quirk read renders as Obsidian reads it, and a table the gfmTable quirk read keeps the escapes of its code spans and has its header row cut or padded to its columns, so it goes after gfmTableHtml. The compiler decides whether a list is loose, so its list handlers are replaced by ones that also read the quirk’s mark. Without the quirks, it renders as the compiler does.