{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "plugin-input-rules-docs",
  "title": "Plugin Input Rules",
  "description": "Typed editor rules for markdown shortcuts, block fences, autolinks, and text substitutions.",
  "files": [
    {
      "path": "../../content/docs/(guides)/plugin-input-rules.mdx",
      "content": "---\ntitle: Plugin Input Rules\ndescription: Typed editor rules for markdown shortcuts, block fences, autolinks, and text substitutions.\n---\n\nPlugin Input Rules convert typed editor patterns: markdown prefixes become headings, fences become code blocks, URLs become links, and `->` becomes `→`.\nUse [Plugin Rules](/docs/plugin-rules) for node behavior policy such as how `Enter` or `Backspace` works inside a block.\nThis page covers shipped markdown rules, local substitutions, custom authoring, execution order, and helper reference.\n\n## On This Page\n\n- [What Plugin Input Rules Are](#what-plugin-input-rules-are)\n- [Quick Start](#quick-start)\n- [Feature-Owned Markdown Rules](#feature-owned-markdown-rules)\n- [Local Copied Shortcuts](#local-copied-shortcuts)\n- [Custom Rules](#custom-rules)\n- [How Rule Execution Works](#how-rule-execution-works)\n- [API Reference](#api-reference)\n\n## What Plugin Input Rules Are\n\nWhen you type a character, press Enter, or paste data, Plate asks every\nregistered input rule \"does this fire?\" before running the default transform.\nEach rule declares a target (`insertText`, `insertBreak`, or `insertData`), an\noptional `enabled` gate, a `resolve` function that looks at the current\nselection and returns a match payload, and an `apply` function that performs the\ntransform. The first rule whose `resolve` returns a non-undefined payload gets\nto run; if nothing matches, the default transform runs as usual.\n\nOwnership splits cleanly into three lanes:\n\n- **Core.** Owns dispatch, selection helpers, and the low-level authoring\n  surfaces: `createMarkInputRule`, `createBlockStartInputRule`,\n  `createBlockFenceInputRule`, `createTextSubstitutionInputRule`,\n  `createRuleFactory`, and `defineInputRule`.\n- **Feature packages.** Own semantic rule families like `HeadingRules`,\n  `BlockquoteRules`, `CodeBlockRules`, `BulletedListRules`, `MathRules`,\n  `LinkRules`. Each family exports factory functions that return concrete rule\n  instances.\n- **Kits and apps.** Own activation. Nothing is turned on just because a plugin exists — you pass rule instances to `inputRules: [...]` when you configure a plugin.\n\n| Lane | Owner | Example |\n| ---- | ----- | ------- |\n| Feature markdown rule | Package | `HeadingRules.markdown()` |\n| Feature interaction rule | Package | `LinkRules.autolink({ variant: 'space' })` |\n| Local text substitution | App / local kit | `createTextSubstitutionInputRule({ patterns })` |\n| Raw custom rule | App or package | `defineInputRule({ target, trigger, resolve, apply })` |\n\n<Callout>\n**Input rules are always explicit.** Registering a plugin does not activate any\nrules; you must pass them to `inputRules`. There is no hidden default set and no\nstring-keyed activation layer.\n</Callout>\n\n## Quick Start\n\nInput rules ship as concrete instances you pass into a plugin's `inputRules` array. The two fastest setup paths are:\n\n1. Drop in feature kits that register feature-owned markdown rules — headings, marks, code blocks, lists, math, links.\n2. Drop in a local `AutoformatKit` to get common text substitutions like `->` → `→` or `(c)` → `©`.\n\nYou can use one, both, or neither.\n\n### Add Feature-Owned Markdown Rules\n\nUse the same kits you already use for nodes and marks. Each kit registers its own markdown rules on the right plugins, so you don't wire anything by hand:\n\n```tsx showLineNumbers\nimport { createPlateEditor } from 'platejs/react';\n\nimport { BasicBlocksKit } from '@/components/editor/plugins/basic-blocks-kit';\nimport { BasicMarksKit } from '@/components/editor/plugins/basic-marks-kit';\nimport { CodeBlockKit } from '@/components/editor/plugins/code-block-kit';\nimport { LinkKit } from '@/components/editor/plugins/link-kit';\nimport { ListKit } from '@/components/editor/plugins/list-kit';\nimport { MathKit } from '@/components/editor/plugins/math-kit';\n\nconst editor = createPlateEditor({\n  plugins: [\n    ...BasicBlocksKit,\n    ...BasicMarksKit,\n    ...CodeBlockKit,\n    ...ListKit,\n    ...LinkKit,\n    ...MathKit,\n  ],\n});\n```\n\nTyping `# ` creates an H1, `**bold**` turns on the bold mark, a triple-backtick\nfence creates a code block, `- ` starts a bulleted list, `[label](url)` creates\na link, and so on. Each kit owns its rule wiring — the kit source shows exactly\nwhich rules it registers and on which plugins.\n\n### Add Local Text Substitutions\n\n`AutoformatKit` is copied registry code that lives in your app and uses\n`createTextSubstitutionInputRule` under the hood. You own the code and can edit\nthe patterns.\n\n```tsx showLineNumbers\nimport { createPlateEditor } from 'platejs/react';\n\nimport { AutoformatKit } from '@/components/editor/plugins/autoformat-kit';\n\nconst editor = createPlateEditor({\n  plugins: [...AutoformatKit],\n});\n```\n\nType `->` and get `→`. Type `(c)` and get `©`. The full pattern list is visible in the kit source — change it however you like.\n\n<Callout>\n**Feature-owned rules and text substitutions are different lanes.** Markdown\nshortcuts live in the feature packages that own the semantics\n(`@platejs/basic-nodes`, `@platejs/link`, `@platejs/math`, ...). Text\nsubstitutions are glyph-for-glyph replacements that live in your app.\n</Callout>\n\nKits are the quick path. If you'd rather wire rules by hand — pick which\nmarkdown variants are active, override priorities, or gate a rule per-app — jump\nto [Feature-Owned Markdown Rules](#feature-owned-markdown-rules) for the manual\npath.\n\nThat's the whole surface in under a minute. Type `# `, type `->`, watch them land.\n\n## Feature-Owned Markdown Rules\n\nFeature packages export semantic rule families. Each family exposes one or more\nfactory functions that return a concrete rule you pass into the matching\nplugin's `inputRules`.\n\n### Basic Blocks\n\nBasic block rules ship with `@platejs/basic-nodes`. Register them per plugin.\n\n**Headings.** `HeadingRules.markdown()` is the same factory for H1 through H6.\nIt derives the markdown prefix from the plugin key (`#`, `##`, `###`, ...), so\nyou pass it once on each heading plugin.\n\n```tsx showLineNumbers\nimport { HeadingRules } from '@platejs/basic-nodes';\nimport {\n  H1Plugin,\n  H2Plugin,\n  H3Plugin,\n  H4Plugin,\n  H5Plugin,\n  H6Plugin,\n} from '@platejs/basic-nodes/react';\n\nH1Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nH2Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nH3Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nH4Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nH5Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nH6Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\n```\n\n**Blockquote.** `BlockquoteRules.markdown()` fires on `>` followed by space and\nwraps the current block. Because blockquote is a wrapper/container node, the\nrule nests cleanly inside an existing quote instead of trying to retag the\nparagraph in place. The rule is gated with `enabled` so it won't fire inside a\ncode block.\n\n```tsx showLineNumbers\nimport { BlockquoteRules } from '@platejs/basic-nodes';\nimport { BlockquotePlugin } from '@platejs/basic-nodes/react';\n\nBlockquotePlugin.configure({\n  inputRules: [BlockquoteRules.markdown()],\n}),\n```\n\n**Horizontal rule.** `HorizontalRuleRules.markdown()` takes a `variant` so you can register more than one trigger.\n\n```tsx showLineNumbers\nimport { HorizontalRuleRules } from '@platejs/basic-nodes';\nimport { HorizontalRulePlugin } from '@platejs/basic-nodes/react';\n\nHorizontalRulePlugin.configure({\n  inputRules: [\n    HorizontalRuleRules.markdown({ variant: '-' }),\n    HorizontalRuleRules.markdown({ variant: '_' }),\n  ],\n}),\n```\n\n`---` and `___` both create a horizontal rule. Register only the variants you want to support.\n\n### Basic Marks\n\nMark rules live in the same package. Each factory returns a single rule, so register one per trigger you want to support.\n\n**Bold, italic, underline.**\n\n```tsx showLineNumbers\nimport {\n  BoldRules,\n  ItalicRules,\n  UnderlineRules,\n} from '@platejs/basic-nodes';\nimport {\n  BoldPlugin,\n  ItalicPlugin,\n  UnderlinePlugin,\n} from '@platejs/basic-nodes/react';\n\nBoldPlugin.configure({\n  inputRules: [\n    BoldRules.markdown({ variant: '*' }),\n    BoldRules.markdown({ variant: '_' }),\n  ],\n}),\nItalicPlugin.configure({\n  inputRules: [\n    ItalicRules.markdown({ variant: '*' }),\n    ItalicRules.markdown({ variant: '_' }),\n  ],\n}),\nUnderlinePlugin.configure({\n  inputRules: [UnderlineRules.markdown()],\n}),\n```\n\nRegister both `*` and `_` variants to accept `**bold**` and `__bold__`. Underline uses a fixed `__x__` form, so its factory takes no options.\n\n**Combos.** `MarkComboRules.markdown()` is a single factory that covers\nmulti-delimiter patterns like `***bold italic***`. Register combos alongside the\nsingle-mark rules on the plugin that owns the dominant mark.\n\n```tsx showLineNumbers\nimport { BoldRules, MarkComboRules } from '@platejs/basic-nodes';\nimport { BoldPlugin } from '@platejs/basic-nodes/react';\n\nBoldPlugin.configure({\n  inputRules: [\n    BoldRules.markdown({ variant: '*' }),\n    BoldRules.markdown({ variant: '_' }),\n    MarkComboRules.markdown({ variant: 'boldItalic' }),\n    MarkComboRules.markdown({ variant: 'boldUnderline' }),\n    MarkComboRules.markdown({ variant: 'boldItalicUnderline' }),\n    MarkComboRules.markdown({ variant: 'italicUnderline' }),\n  ],\n}),\n```\n\nCombo variants: `'boldItalic' | 'boldUnderline' | 'boldItalicUnderline' | 'italicUnderline'`.\n\n**Inline code, strikethrough, subscript, superscript, highlight.**\n\n```tsx showLineNumbers\nimport {\n  CodeRules,\n  HighlightRules,\n  StrikethroughRules,\n  SubscriptRules,\n  SuperscriptRules,\n} from '@platejs/basic-nodes';\nimport {\n  CodePlugin,\n  HighlightPlugin,\n  StrikethroughPlugin,\n  SubscriptPlugin,\n  SuperscriptPlugin,\n} from '@platejs/basic-nodes/react';\n\nCodePlugin.configure({\n  inputRules: [CodeRules.markdown()],\n}),\nStrikethroughPlugin.configure({\n  inputRules: [StrikethroughRules.markdown()],\n}),\nSubscriptPlugin.configure({\n  inputRules: [SubscriptRules.markdown()],\n}),\nSuperscriptPlugin.configure({\n  inputRules: [SuperscriptRules.markdown()],\n}),\nHighlightPlugin.configure({\n  inputRules: [\n    HighlightRules.markdown({ variant: '==' }),\n    HighlightRules.markdown({ variant: '≡' }),\n  ],\n}),\n```\n\nInline code uses `` `x` ``. Strikethrough uses `~~x~~`. Subscript is `~x~`.\nSuperscript is `^x^`. Highlight accepts `==x==` or `≡x≡` — pick either, both,\nor pass a different variant.\n\n### Code Blocks\n\nCode blocks are fenced, which makes them different from simple marks or block prefixes. They ship as a **block fence rule**, and you must pass `on` to pick when the fence commits.\n\n```tsx showLineNumbers\nimport { CodeBlockRules } from '@platejs/code-block';\nimport { CodeBlockPlugin } from '@platejs/code-block/react';\n\nCodeBlockPlugin.configure({\n  inputRules: [CodeBlockRules.markdown({ on: 'match' })],\n}),\n```\n\n`on: 'match'` commits the moment the fence text becomes complete — typing the third backtick of the opening fence converts the paragraph to a code block immediately.\n\n```tsx showLineNumbers\nCodeBlockPlugin.configure({\n  inputRules: [CodeBlockRules.markdown({ on: 'break' })],\n}),\n```\n\n`on: 'break'` waits for you to press Enter after the fence is complete. Same matcher, different commit point.\n\n<Callout>\n**Why `on` is required.** `match` and `break` are meaningfully different UX choices — instant vs deferred. The factory refuses to guess which one you want.\n</Callout>\n\nIf you need to suppress code blocks inside a specific context, pass `enabled`:\n\n```tsx\nCodeBlockRules.markdown({\n  on: 'match',\n  enabled: ({ editor }) => !isInsideSomeCustomContainer(editor),\n}),\n```\n\n### Lists\n\nList rules live in `@platejs/list` and register on the single `ListPlugin`. Each factory targets one shape.\n\n```tsx showLineNumbers\nimport {\n  BulletedListRules,\n  OrderedListRules,\n  TaskListRules,\n} from '@platejs/list';\nimport { ListPlugin } from '@platejs/list/react';\n\nListPlugin.configure({\n  inputRules: [\n    BulletedListRules.markdown({ variant: '-' }),\n    BulletedListRules.markdown({ variant: '*' }),\n    OrderedListRules.markdown({ variant: '.' }),\n    OrderedListRules.markdown({ variant: ')' }),\n    TaskListRules.markdown({ checked: false }),\n    TaskListRules.markdown({ checked: true }),\n  ],\n}),\n```\n\n- `BulletedListRules.markdown({ variant })` accepts `'-'` or `'*'`.\n- `OrderedListRules.markdown({ variant })` accepts `'.'` or `')'`. The rule parses the leading number and starts the list from it, so `3. ` creates a list that begins at 3.\n- `TaskListRules.markdown({ checked })` maps `[]` to an unchecked task and `[x]` to a checked task.\n\nAll list rules use `enabled` to opt out inside code blocks.\n\n### Math\n\nMath has two shapes: inline `$x$` and block `$$x$$`. They're intentionally split so apps can enable one without the other.\n\n```tsx showLineNumbers\nimport { MathRules } from '@platejs/math';\nimport { EquationPlugin, InlineEquationPlugin } from '@platejs/math/react';\n\nInlineEquationPlugin.configure({\n  inputRules: [MathRules.markdown({ variant: '$' })],\n}),\nEquationPlugin.configure({\n  inputRules: [MathRules.markdown({ variant: '$$', on: 'break' })],\n}),\n```\n\n`variant: '$'` is inline — a delimited mark rule. `variant: '$$'` is a block\nfence, so — like `CodeBlockRules` — it takes `on: 'match' | 'break'`. The\nexample uses `on: 'break'`, which commits the block equation when you press\nEnter after the fence.\n\n### Links\n\nLink rules are not just substitutions — they validate URLs and wrap text with a full link node.\n\n```tsx showLineNumbers\nimport { LinkRules } from '@platejs/link';\nimport { LinkPlugin } from '@platejs/link/react';\n\nLinkPlugin.configure({\n  inputRules: [\n    LinkRules.markdown(),\n    LinkRules.autolink({ variant: 'paste' }),\n    LinkRules.autolink({ variant: 'space' }),\n    LinkRules.autolink({ variant: 'break' }),\n  ],\n}),\n```\n\n- `LinkRules.markdown()` handles `[label](https://...)`.\n- `LinkRules.autolink({ variant: 'paste' })` turns a pasted URL into a link.\n- `LinkRules.autolink({ variant: 'space' })` detects a URL when you type a trailing space.\n- `LinkRules.autolink({ variant: 'break' })` detects a URL when you press Enter.\n\nRegister whichever variants you want — you can pick one, two, or all four.\n\nThat's the full feature-owned catalog. Every package you add contributes its own rules; the editor picks them up the moment you register them.\n\n## Local Copied Shortcuts\n\nSometimes you want small text substitutions — smart quotes, arrows, fractions,\ntrademarks — that don't belong to any feature package. Use\n`createTextSubstitutionInputRule` for this.\n\n### createTextSubstitutionInputRule\n\nThe helper takes a `patterns` array and builds a single `insertText` rule. Each pattern has a `match` (what you type) and a `format` (what you end up with).\n\n```tsx showLineNumbers\nimport {\n  createSlatePlugin,\n  createTextSubstitutionInputRule,\n  KEYS,\n  type SlateEditor,\n} from 'platejs';\n\nconst isInCodeBlock = (editor: SlateEditor) =>\n  editor.api.some({\n    match: { type: [editor.getType(KEYS.codeBlock)] },\n  });\n\nconst arrowsRule = createTextSubstitutionInputRule({\n  enabled: ({ editor }) => !isInCodeBlock(editor),\n  patterns: [\n    { format: '→', match: '->' },\n    { format: '←', match: '<-' },\n    { format: '⇒', match: '=>' },\n    { format: '⇐', match: ['<=', '≤='] },\n  ],\n});\n\nexport const ArrowsShortcutsPlugin = createSlatePlugin({\n  key: 'arrowsShortcuts',\n  inputRules: [arrowsRule],\n});\n```\n\nA few details worth knowing:\n\n- `match` can be a string or an array of strings — all entries are checked before formatting.\n- `format` can be a single string or a `[open, close]` tuple. A tuple wraps the typed text as `open + content + close`, useful for smart quotes and brackets.\n- `trigger` defaults to the last character of each match, which is almost always what you want. Override it only if you need a distinct commit char.\n- `enabled` gates the whole rule, so you don't have to guard each pattern individually.\n\n### Use AutoformatKit As A Starting Point\n\nThe `autoformat-kit.tsx` file in Plate's registry wires up a full set of\nsubstitutions — arrows, comparisons, equalities, fractions, legal symbols, smart\nquotes, sub/superscript numerals — all gated against code blocks. Copy it into\nyour app and edit the patterns.\n\n```tsx showLineNumbers title=\"autoformat-kit.tsx\"\nimport {\n  createSlatePlugin,\n  createTextSubstitutionInputRule,\n  KEYS,\n  type SlateEditor,\n} from 'platejs';\n\nconst isTextSubstitutionBlocked = (editor: SlateEditor) =>\n  editor.api.some({\n    match: { type: [editor.getType(KEYS.codeBlock)] },\n  });\n\nconst createAutoformatTextSubstitutionRule = ({\n  patterns,\n}: {\n  patterns: Parameters<typeof createTextSubstitutionInputRule>[0]['patterns'];\n}) =>\n  createTextSubstitutionInputRule({\n    enabled: ({ editor }) => !isTextSubstitutionBlocked(editor),\n    patterns,\n  });\n\nconst legalRule = createAutoformatTextSubstitutionRule({\n  patterns: [\n    { format: '™', match: ['(tm)', '(TM)'] },\n    { format: '®', match: ['(r)', '(R)'] },\n    { format: '©', match: ['(c)', '(C)'] },\n  ],\n});\n\nconst smartQuotesRule = createAutoformatTextSubstitutionRule({\n  patterns: [\n    { format: ['“', '”'], match: '\"' },\n    { format: ['‘', '’'], match: \"'\" },\n  ],\n});\n\nconst AutoformatShortcutsPlugin = createSlatePlugin({\n  key: 'autoformatShortcuts',\n  inputRules: [legalRule, smartQuotesRule],\n});\n\nexport const AutoformatKit = [AutoformatShortcutsPlugin];\n```\n\n<Callout>\n**Use copied code for local substitutions.** `@platejs/autoformat` still ships\nas a compatibility package for autoformat imports. Author project-specific\nsubstitutions in copied registry code or your own local kit so the rules stay\nvisible and editable.\n</Callout>\n\n### When To Reach For defineInputRule\n\nText substitution covers the glyph-for-glyph case. When you need more — reading\nthe current block, dispatching a richer transform, or detecting a pattern that\nisn't a simple character match — drop down to `defineInputRule` or one of the\nlow-level builders.\n\n## Custom Rules\n\nEverything above is sugar on top of three low-level authoring surfaces:\n\n- `defineInputRule`, an identity function that types a raw rule inline.\n- The specialized builders: `createMarkInputRule`, `createBlockStartInputRule`,\n  `createBlockFenceInputRule`, `createTextSubstitutionInputRule`.\n- `createRuleFactory`, the package-authoring helper used to expose semantic\n  families like `MathRules.markdown(...)` or `LinkRules.autolink(...)` without\n  re-declaring shared runtime fields.\n\nUse this section when none of the shipped families fit your need or when you're authoring your own reusable rule family.\n\n### Register Explicit Rule Instances\n\nRules are concrete objects. You pass them into `inputRules` exactly as-is. To\noverride a field like `priority` or `enabled` on a finished instance, spread the\nrule and replace the field:\n\n```tsx showLineNumbers\nimport { HeadingRules } from '@platejs/basic-nodes';\nimport { LinkRules } from '@platejs/link';\nimport { H1Plugin } from '@platejs/basic-nodes/react';\nimport { LinkPlugin } from '@platejs/link/react';\n\nH1Plugin.configure({\n  inputRules: [HeadingRules.markdown()],\n}),\nLinkPlugin.configure({\n  inputRules: [\n    LinkRules.markdown(),\n    { ...LinkRules.autolink({ variant: 'paste' }), priority: 200 },\n  ],\n}),\n```\n\nWhy the spread? Package factories are intentionally narrow — most don't take a\n`priority` option. Overriding is the caller's job, and spreading the returned\nrule keeps it obvious that you're changing one field on an already-built\ninstance.\n\nThe same pattern works for `enabled`. If a family ships with a sensible default but you need stricter gating in one app, spread the rule and override:\n\n```tsx\n{\n  ...BlockquoteRules.markdown(),\n  enabled: ({ editor }) => !isInsideCallout(editor),\n},\n```\n\n### Plugin-Side Factories\n\nFor plugin authors, the `inputRules` option also accepts a function that\nreceives a `rule` builder. Use this form when your rules depend on plugin-local\nstate or when you want your rule wiring to live next to the plugin's types.\n\n```tsx showLineNumbers\nimport { createSlatePlugin, KEYS } from 'platejs';\n\nconst CustomPlugin = createSlatePlugin({\n  key: 'custom',\n  inputRules: ({ rule }) => [\n    rule.mark({\n      trigger: '*',\n      start: '*',\n    }),\n    rule.blockStart({\n      trigger: ' ',\n      match: '>',\n      mode: 'wrap',\n      node: 'blockquote',\n    }),\n    rule.blockFence({\n      fence: '```',\n      on: 'match',\n      apply: (context, match) => {\n        context.editor.tf.delete({ at: match.range });\n        context.editor.tf.setNodes(\n          { type: context.editor.getType(KEYS.codeBlock) },\n          { at: match.path }\n        );\n      },\n    }),\n  ],\n});\n```\n\nThe `rule` builder exposes six primitives:\n\n| Method | Wraps |\n| ------ | ----- |\n| `rule.mark(config)` | `createMarkInputRule` |\n| `rule.blockStart(config)` | `createBlockStartInputRule` |\n| `rule.blockFence(config)` | `createBlockFenceInputRule` |\n| `rule.insertText(rule)` | typed `defineInputRule` for `insertText` |\n| `rule.insertBreak(rule)` | typed `defineInputRule` for `insertBreak` |\n| `rule.insertData(rule)` | typed `defineInputRule` for `insertData` |\n\nUse the factory form when you need that co-location; use the array form when you just want to register a handful of concrete instances.\n\n### Author A Rule Family\n\nWhen you're shipping a package, you usually want a public factory like\n`MyNodeRules.markdown(...)` that takes a narrow options object and hides the\nlow-level rule plumbing. Reach for `createRuleFactory`.\n\n```tsx showLineNumbers\nimport { createRuleFactory, KEYS } from 'platejs';\n\nexport const BlockquoteRules = {\n  markdown: createRuleFactory<{}, { marker: string }>({\n    type: 'blockStart',\n    marker: '>',\n    trigger: ' ',\n    mode: 'wrap',\n    match: ({ marker }) => marker,\n    enabled: ({ editor }) =>\n      !editor.api.some({ match: { type: [editor.getType(KEYS.codeBlock)] } }),\n  }),\n};\n```\n\nA few things to notice:\n\n- `type` picks the underlying builder. Use `'mark'`, `'blockStart'`, `'blockFence'`, or `'textSubstitution'`.\n- The two generic parameters model your public API: `TRequired` (the first) are\n  options callers must pass; `TDefaults` (the second) are options you supply a\n  default for — here, `marker: '>'`.\n- Factory values can be plain values (`'>'`) or functions of the input\n  (`({ marker }) => marker`). The input includes the runtime context, your\n  defaults, and any required options the caller passes.\n- For `blockStart`, core already owns the base match payload: `{ range, text }`.\n  If you provide `resolveMatch`, return only your extra fields — core merges\n  them onto the base payload before `apply` runs.\n- `enabled` and `priority` stay available as runtime overrides on the returned rule instance — callers can override them even when your factory sets a default.\n\nThat's the pattern every `*Rules.markdown(...)` family in Plate uses. Clone it when you need your own.\n\nDone. Between `defineInputRule`, the four specialized builders, the plugin-side\n`rule` builder, and `createRuleFactory`, every rule in Plate — yours included —\ncomes from the same small core.\n\n## How Rule Execution Works\n\nInput rules run inside the `insertText`, `insertBreak`, and `insertData`\ntransforms. For each call, the runtime walks every registered rule for that\ntarget in priority order, and the first rule that passes `enabled` and produces\na non-undefined `resolve` gets to call `apply`.\n\n### Targets\n\nA rule's `target` field picks which lane it runs in.\n\n| Target | Fires on |\n| ------ | -------- |\n| `insertText` | Each character typed into the editor |\n| `insertBreak` | Each time the user presses `Enter` |\n| `insertData` | Each time data is pasted or dropped |\n\nThe high-level factories set `target` for you:\n\n- `createMarkInputRule` and `createBlockStartInputRule` always produce `insertText` rules.\n- `createBlockFenceInputRule` produces an `insertText` rule when `on: 'match'` and an `insertBreak` rule when `on: 'break'`.\n- `createTextSubstitutionInputRule` always produces an `insertText` rule.\n\n`defineInputRule` lets you pick any target by setting the `target` field directly.\n\n### Selection Context\n\nEvery `enabled`, `resolve`, and `apply` call receives a context object with the live editor, the selection state, and a handful of lazy helpers.\n\n| Field | Returns |\n| ----- | ------- |\n| `editor` | The current `SlateEditor` |\n| `isCollapsed` | Whether the selection is collapsed |\n| `pluginKey` | The key of the plugin the rule is attached to |\n| `getBlockEntry()` | The current block's `NodeEntry`, or `undefined` |\n| `getBlockStartRange()` | The range from block start to current selection |\n| `getBlockStartText()` | The text from block start to current selection |\n| `getBlockTextBeforeSelection()` | The text in the current block before the cursor |\n| `getCharBefore()` | The character immediately before the cursor |\n| `getCharAfter()` | The character immediately after the cursor |\n\nThe `get*` helpers are memoized — calling them twice inside the same rule evaluation doesn't recompute. That matters because multiple rules can share the same evaluation pass.\n\nTarget-specific context fields:\n\n- `insertText` rules additionally receive `text`, `cause: 'insertText'`, and an `insertText` callback for default fallthrough.\n- `insertBreak` rules receive `cause: 'insertBreak'` and an `insertBreak` callback.\n- `insertData` rules receive `data: DataTransfer`, `text`, `cause: 'insertData'`, and an `insertData` callback.\n\n### Lifecycle\n\nFor each transform call, the runtime walks rules in priority order (highest first). For each rule, it runs the following steps:\n\n1. **`enabled`.** A boolean gate. If it returns `false`, skip to the next rule.\n2. **`resolve`.** Computes a match payload. If it returns `undefined`, skip to the next rule.\n3. **`apply`.** Performs the transform. If it returns `false`, the runtime\n   treats the rule as not consumed and continues; any other return value\n   consumes the input and short-circuits the rest of the walk.\n\nIf no rule consumes the input, the default Slate transform runs as normal.\n\n| Field | Purpose |\n| ----- | ------- |\n| `trigger` | Restricts an `insertText` rule to fire only when the typed character matches (string or array) |\n| `enabled` | Policy gate, evaluated first |\n| `resolve` | Computes the match payload passed to `apply` |\n| `apply` | Performs the transform |\n| `priority` | Sort order for rules on the same target |\n| `on` | Block-fence commit mode: `'match'` or `'break'` |\n| `mimeTypes` | Narrows an `insertData` rule to specific MIME types |\n\n<Callout>\n**Use `enabled` for policy, not `match`.** The matcher should own the *syntax*\nof a rule (what pattern counts as a hit). Gating — \"don't fire in code blocks\",\n\"only fire when this plugin is active\" — belongs in `enabled`. Returning\n`undefined` from `resolve` just to suppress a rule works, but it hides intent\nand makes rules harder to compose.\n</Callout>\n\n## API Reference\n\nLow-level surface. Reach for this when the high-level factories don't cover your case. Everything below is exported from `platejs`.\n\n### Rule Targets\n\n```ts\ntype InputRuleTarget = 'insertText' | 'insertBreak' | 'insertData';\n```\n\n### defineInputRule\n\nIdentity function that types a rule inline.\n\n```ts\nfunction defineInputRule<TRule extends AnyInputRule>(rule: TRule): TRule;\n```\n\n```ts\nimport { defineInputRule } from 'platejs';\n\nconst copyrightRule = defineInputRule({\n  target: 'insertText',\n  trigger: ')',\n  resolve: (context) => {\n    if (context.text !== ')') return;\n    if (!context.getBlockTextBeforeSelection().endsWith('(c')) return;\n\n    return { replacement: '©' };\n  },\n  apply: ({ editor }, match) => {\n    editor.tf.delete({ distance: 2, reverse: true, unit: 'character' });\n    editor.tf.insertText(match.replacement);\n  },\n});\n```\n\nUse it when you want a raw rule object typed against `InsertTextInputRule`, `InsertBreakInputRule`, or `InsertDataInputRule` without going through a builder.\n\n### createRuleFactory\n\nPackage-facing helper for semantic rule families. Use it when you want to expose\na narrow public factory like `BlockquoteRules.markdown(...)`, keep shared\nruntime fields like `enabled` and `priority`, and hide the low-level rule\nconstruction details.\n\n```ts\nimport { createRuleFactory, KEYS } from 'platejs';\n\nexport const BlockquoteRules = {\n  markdown: createRuleFactory<{}, { marker: string }>({\n    type: 'blockStart',\n    marker: '>',\n    trigger: ' ',\n    match: ({ marker }) => marker,\n    mode: 'wrap',\n    enabled: ({ editor }) =>\n      !editor.api.some({\n        match: { type: [editor.getType(KEYS.codeBlock)] },\n      }),\n  }),\n};\n```\n\nThe returned function is your public rule family. Concrete values in the config\nbecome default public options (`marker: '>'`), while the generic type parameters\nlet you model required options and defaults for the family. The created rule\ninstance still supports the shared runtime overrides: `enabled` and `priority`.\n\n### createMarkInputRule\n\nDelimited inline marks (`**bold**`, `` `code` ``, `~~strike~~`).\n\n```ts\nfunction createMarkInputRule(config: {\n  start: string;\n  end?: string;\n  trigger: string;\n  mark?: string;\n  marks?: string[];\n  trim?: 'allow' | 'reject';\n  enabled?: (context: InsertTextInputRuleContext) => boolean;\n  priority?: number;\n}): InsertTextInputRule;\n```\n\n```ts\nimport { createMarkInputRule } from 'platejs';\n\ncreateMarkInputRule({\n  start: '**',\n  end: '*',\n  trigger: '*',\n});\n```\n\n`start` is the opening delimiter. `end` is an optional closing delimiter; when\nomitted, the rule does not look for a separate closing delimiter before the\ntrigger. `trigger` is the character that commits the match. `trim: 'reject'`\nrefuses spans with leading or trailing whitespace. `mark` and `marks` restrict\nwhich mark(s) the rule applies.\n\n### createBlockStartInputRule\n\nBlock-start patterns typed at the beginning of a block (`# `, `> `, `- `, `1. `).\n\n```ts\nfunction createBlockStartInputRule<TMatch extends object = {}>(config: {\n  trigger: string;\n  match:\n    | RegExp\n    | string\n    | ((context: InsertTextInputRuleContext) => RegExp | string | undefined);\n  mode?: 'set' | 'toggle' | 'wrap';\n  node?: string;\n  removeMatchedText?: boolean;\n  resolveMatch?: (args: {\n    match: RegExpMatchArray | string;\n    range: TRange;\n    text: string;\n  }) => TMatch | undefined;\n  apply?: (\n    context: InsertTextInputRuleContext,\n    match: BlockStartInputRuleMatch & TMatch\n  ) => boolean | void;\n  enabled?: (context: InsertTextInputRuleContext) => boolean;\n  priority?: number;\n}): InsertTextInputRule<TMatch>;\n```\n\n```ts\nimport { createBlockStartInputRule } from 'platejs';\n\ncreateBlockStartInputRule({\n  trigger: ' ',\n  match: '>',\n  mode: 'wrap',\n});\n```\n\n- `trigger` is the commit character — typically `' '`.\n- `match` is the block-start text: a string, a `RegExp`, or a function that returns one based on context.\n- `mode` picks the transform: `'set'` replaces the block type, `'toggle'` flips it, `'wrap'` wraps the block in a new element.\n- `node` is the target element type used by `mode`.\n- `apply` overrides the built-in transform entirely — supply your own when none\n  of the modes fit. That also means you own matched-text cleanup; if you still\n  want the shorthand removed, delete `match.range` yourself.\n- `resolveMatch` returns extra fields only. Core still provides the base `{ range, text }` payload automatically, and `apply` receives the merged object.\n\n### createBlockFenceInputRule\n\nFenced block patterns like triple-backtick code fences or `$$` math fences.\n\n```ts\nfunction createBlockFenceInputRule<TMatch>(config: {\n  fence: string;\n  on: 'break' | 'match';\n  apply: (context: SelectionInputRuleContext, match: TMatch) => boolean | void;\n  block?: string;\n  resolveMatch?: (args: {\n    fence: string;\n    path: Path;\n    range: TRange;\n    text: string;\n  }) => TMatch | undefined;\n  enabled?: (context: SelectionInputRuleContext) => boolean;\n  priority?: number;\n}): InsertTextInputRule<TMatch> | InsertBreakInputRule<TMatch>;\n```\n\n```ts\nimport { createBlockFenceInputRule, KEYS } from 'platejs';\n\ncreateBlockFenceInputRule({\n  fence: '```',\n  on: 'match',\n  apply: (context, match) => {\n    context.editor.tf.delete({ at: match.range });\n    context.editor.tf.setNodes(\n      { type: context.editor.getType(KEYS.codeBlock) },\n      { at: match.path }\n    );\n  },\n});\n```\n\n`on: 'match'` commits when the fence becomes complete inside the current\nparagraph. `on: 'break'` commits when Enter is pressed after the fence is\ncomplete — useful when the user may want to type more before committing.\n\nThe runtime owns the matcher: it checks that the selection is collapsed, the\ncursor is at the block's end, and the block text equals `fence`. If you pass\n`block`, the matcher also requires that block type. You own `apply`, which\nperforms the replacement. The returned rule targets `insertText` when\n`on: 'match'` and `insertBreak` when `on: 'break'`.\n\n### createTextSubstitutionInputRule\n\nGlyph-for-glyph substitutions.\n\n```ts\nfunction createTextSubstitutionInputRule(config: {\n  patterns: Array<{\n    format: readonly [string, string] | string;\n    match: readonly string[] | string;\n    trigger?: readonly string[] | string;\n  }>;\n  enabled?: (context: InsertTextInputRuleContext) => boolean;\n  priority?: number;\n}): InsertTextInputRule;\n```\n\n```ts\nimport { createTextSubstitutionInputRule } from 'platejs';\n\ncreateTextSubstitutionInputRule({\n  patterns: [\n    { format: '→', match: '->' },\n    { format: ['«', '»'], match: '<<' },\n  ],\n});\n```\n\n`format` is either a replacement string or a `[open, close]` tuple that wraps\nthe typed content. `match` is a string or array of strings that trigger the\nreplacement. `trigger` defaults to the last character of each match and rarely\nneeds overriding.\n\n### matchDelimitedInline\n\nLow-level matcher used under `createMarkInputRule`. Returns a `{ content, deleteRange }` match for a delimited inline pattern, or `undefined`.\n\n```ts\nimport { matchDelimitedInline } from 'platejs';\n\nconst match = matchDelimitedInline(context, {\n  open: '**',\n  close: '*',\n  requireClosingDelimiter: true,\n  trim: 'reject',\n});\n```\n\nUse it when you're authoring a custom `insertText` rule that needs the same matching shape as a mark without going through `createMarkInputRule`.\n\n### matchBlockStart / matchBlockFence\n\nCompanion matchers for block-start and block-fence rules. Both take the current\ncontext plus a matcher config and return a match payload or `undefined`. Use\nthem when you want the matcher logic without the factory's `apply` wiring.\n\n```ts\nimport { matchBlockFence, matchBlockStart } from 'platejs';\n\nconst startMatch = matchBlockStart(context, { match: '>' });\nconst fenceMatch = matchBlockFence(context, { fence: '```' });\n```\n\n### Package Rule Families\n\nEvery family below is a single export from its package. Each `.markdown()` (or `.autolink()`) call returns a concrete rule you pass into the matching plugin's `inputRules`.\n\n| Family | Package | Description |\n| ------ | ------- | ----------- |\n| `HeadingRules` | `@platejs/basic-nodes` | Markdown prefix rules for H1–H6, derived from plugin key |\n| `BlockquoteRules` | `@platejs/basic-nodes` | `>` block-wrap rule, gated out of code blocks |\n| `HorizontalRuleRules` | `@platejs/basic-nodes` | `---` and `___` variant rules |\n| `BoldRules` | `@platejs/basic-nodes` | `**x**` / `__x__` mark rule |\n| `ItalicRules` | `@platejs/basic-nodes` | `*x*` / `_x_` mark rule |\n| `UnderlineRules` | `@platejs/basic-nodes` | `__x__` mark rule |\n| `CodeRules` | `@platejs/basic-nodes` | `` `x` `` inline code mark rule |\n| `StrikethroughRules` | `@platejs/basic-nodes` | `~~x~~` mark rule |\n| `SubscriptRules` | `@platejs/basic-nodes` | `~x~` mark rule |\n| `SuperscriptRules` | `@platejs/basic-nodes` | `^x^` mark rule |\n| `HighlightRules` | `@platejs/basic-nodes` | `==x==` / `≡x≡` mark rule |\n| `MarkComboRules` | `@platejs/basic-nodes` | Multi-mark combo rules (bold/italic/underline) |\n| `CodeBlockRules` | `@platejs/code-block` | Triple-backtick block fence rule, requires `on` |\n| `BulletedListRules` | `@platejs/list` | `-` / `*` bulleted list rule |\n| `OrderedListRules` | `@platejs/list` | `1.` / `1)` ordered list rule, preserves start number |\n| `TaskListRules` | `@platejs/list` | `[]` / `[x]` task list rule |\n| `MathRules` | `@platejs/math` | Inline `$x$` and block `$$x$$` rules |\n| `LinkRules` | `@platejs/link` | Markdown `[label](url)` and autolink rules |\n\nEach family's factory takes a narrow options object — see the per-section examples above for the exact shape.\n",
      "type": "registry:file",
      "target": "content/docs/plate/(guides)/plugin-input-rules.mdx"
    }
  ],
  "type": "registry:file"
}