Rich text / foldkit-richtext-markdown

Input rules

markdownInputRules reshapes a block when a marker is completed at its start: # through ###### retype it as a heading (RetypeBlock), and > , - /* /+ , and an ordered marker such as 1. or 3) wrap it in a quote or a list (WrapBlock), an ordered list numbered from the number typed, and a marker typed right after a list of the same kind adds an item to it; and a fence with an optional language, such as ```ts then a space, converts it to a CodeBlock (ConvertBlock). [ ] or [x] at the start of a list item, which - has made by then, makes the item a task where it stands, unticked or ticked (RetypeContainer), in a bulleted or an ordered list, with any list nested in it. Typed in a later paragraph of the item, the marker stays text, as Markdown reads it.

The inline markers close as they are typed (markdownInlineRules, which markdownInputRules ends with): **bold**, *italic* and _italic_, `code`, and ~~struck~~ become marked text the moment the closing marker is typed, and what is typed next is plain again. The content is not empty, does not start or end with a space, and holds no delimiter character, and the opening marker stands at the block's start or after a space, an opening bracket or a quote, so snake_case_name and 2*3*4 stay text. Inside a CodeBlock, which forbids marks, the markers stay the text they are. An editor placement in foldkit-richtext-dom names the rules it applies, so this package holds no editor state and the editor holds no Markdown:

ts
import { editorAt } from 'foldkit-richtext-dom/editor-bundle'
import { markdownInputRules } from 'foldkit-richtext-markdown'

const body = editorAt('article-body', { inputRules: markdownInputRules })

A fence is completed by a space, not by the line break Markdown reads it at, because Enter splits a block and a rule sees only what is typed. Converting gives the block's runs new identities. Under the standard vocabulary, whose CodeBlock forbids marks, a fence typed into a block that carries marks is refused, and the editor keeps the fence as the text it typed. A list marker typed right after a list starts a new list beside it rather than adding an item to that one.