Rich text / foldkit-richtext-markdown
Type Markdown shortcuts with input rules
markdownInputRules converts completed Markdown markers into rich-text blocks and marks as the user types:
- Block prefixes:
#through######retype the block as a heading;>,-,*,+, and1./3)wrap the block in a quote or list;```tsfollowed by a space converts to aCodeBlock;[ ]or[x]at the start of a list item's first block converts it to aTaskItem. - Inline delimiters:
**bold**,*italic*,_italic_,`code`, and~~struck~~apply the mark when the closing delimiter is typed, leaving subsequent text unmarked. Opening markers require the start of a block, whitespace, an opening bracket, or a quote, sosnake_case_nameand2*3*4stay plain text.
Pass the rules to an editor placement in foldkit-richtext-dom:
ts
import { editorAt } from 'foldkit-richtext-dom/editor-bundle'
import { markdownInputRules } from 'foldkit-richtext-markdown'
const body = editorAt('article-body', { inputRules: markdownInputRules })Fences trigger on a space rather than Enter because Enter splits blocks before the rule runs. Under the standard vocabulary, CodeBlock forbids marks, so a fence typed on a block with marks is refused and kept as plain text. A list marker typed immediately after an existing list starts a separate list beside it.