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; > , - , * , + , and 1. / 3) wrap the block in a quote or list; ```ts followed by a space converts to a CodeBlock; [ ] or [x] at the start of a list item's first block converts it to a TaskItem.
  • 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, so snake_case_name and 2*3*4 stay 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.