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
ParamType
regexpNamedRegExp<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
contextsMarkupContexts
One or more contexts this rule renders in (e.g. ["block"]). required
prioritynumber
Tier priority — higher rules override lower ones (defaults to 0).
regexpRegExp
required
render(key: string, data: EmptyDictionary, parser: MarkupParser) => ReactElement
required
contextsMarkupContexts
One or more named contexts a markup rule renders in (e.g. ["block"], ["inline", "list", "link"]). required
prioritynumber
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 to render.
  • Higher priority rules are resolved (and masked) before lower-priority ones.

Examples

const HR_RULE = createMarkupRule(/^---$/m, key => <hr key={key} />, ["block"]);