createMarkupRule()function
createMarkupRule(regexp: NamedRegExp<T>, render: (key: string, data: T, parser: MarkupParser) => ReactElement, contexts: MarkupContexts, priority?: number): MarkupRule
createMarkupRule(regexp: RegExp, render: (key: string, data: EmptyDictionary, parser: MarkupParser) => ReactElement, contexts: MarkupContexts, priority?: number): MarkupRule
| Param | Type | |
|---|---|---|
regexp | NamedRegExp<T> | Regular expression used to match the rule (a NamedRegExp to type the render data). required |
render | (key: string, data: T, parser: MarkupParser) => ReactElement | Renderer turning a key, the matched data, and the active parser into a ReactElement. required |
contexts | MarkupContexts | One or more contexts this rule renders in (e.g. ["block"]). required |
priority | number | Tier priority — higher rules override lower ones (defaults to 0). |
regexp | RegExp | required |
render | (key: string, data: EmptyDictionary, parser: MarkupParser) => ReactElement | required |
contexts | MarkupContexts | One or more named contexts a markup rule renders in (e.g. ["block"], ["inline", "list", "link"]). required |
priority | number |
| Return | |
|---|---|
MarkupRule | A MarkupRule ready to add to a MarkupRules list. |
MarkupRule | A single markup rule: a regular expression that matches a span of input plus a renderer that turns the match into an element. |
Create a typed MarkupRule from a NamedRegExp, a renderer, its contexts, and an optional priority.
Factory for MarkupRule.
- The overload taking a
NamedRegExp<T>infers the named capture groups handed torender. - Higher
priorityrules are resolved (and masked) before lower-priority ones.
Examples
const HR_RULE = createMarkupRule(/^---$/m, key => <hr key={key} />, ["block"]);