MarkupParserclass

new MarkupParser({ rules = MARKUP_RULES, rel, url, root, schemes = HTTP_SCHEMES, context = "block" }: MarkupOptions = {})
ParamType
optionsMarkupOptions
Options configuring a MarkupParser (represents the current state of the parsing). Defaults to {}
    .rulesMarkupRules
The active list of parsing rules. Defaults to MARKUP_RULES readonly
    .relstring
Set the rel="" property used for any links (e.g. rel="nofollow ugc"). readonly
    .urlImmutableURL
Current page URL — used as the base for resolving relative refs (./foo, #x, bare segments) in link hrefs. readonly
    .rootImmutableURL
Site root URL — used as the base for resolving site-absolute path hrefs (/foo), honoring its subfolder. readonly
    .schemesURISchemes
Valid URI schemes/protocols for URLs and URIs. Defaults to ["http:", "https:"] readonly
    .contextstring
Default context to use if one isn't set. Defaults to "block" readonly
Return
MarkupParser
Parses a Markdownish markup string and renders it as a React node using a tiered, masking rule engine.
PropertyType
.rulesMarkupRules
The list of parsing rules this parser applies. required readonly
.prioritiesImmutableArray<number>
Calculated list of priorities to iterate over (extracted from the rules), e.g. [10, 0, -10] required readonly
.relstring
Set the rel="" property used for any links (e.g. rel="nofollow ugc"). readonly
.urlImmutableURL
Current page URL — used as the base for resolving relative refs (./foo, #x, bare segments) in link hrefs. Falls back to root if not set. readonly
.rootImmutableURL
Site root URL — used as the base for resolving site-absolute path hrefs (/foo), honoring its subfolder. Falls back to url if not set. readonly
.schemesURISchemes
Valid URI schemes/protocols for URLs and URIs. Defaults to ["http:", "https:"] readonly
.contextstring
Default context to use if one isn't set. Defaults to "block" required readonly

Parses a Markdownish markup string and renders it as a React node using a tiered, masking rule engine.

  • The syntax isn't hardcoded — it's defined entirely by the rules supplied (defaults to MARKUP_RULES).
  • Rules are grouped into priority tiers and resolved highest tier first; a claimed region is masked so lower-priority rules can't match into or across it.
  • Rules own the recursion into their own children by calling parse() again, optionally with a different context.

Examples

const node = new MarkupParser().parse("This is a *bold* string.");

Methods

Go

MarkupParser.parse()method

Parse a text string as Markdownish markup syntax and render it as a React node.

parse(input: string, context = this.context): ReactNode
Go

MarkupParser.getRules()method

Yield the rules active in context that sit in the given priority tier.

getRules(context: string, priority: number): Iterable<MarkupRule>
Go

MarkupParser.getLink()method

Resolve a link href against this parser's url and root, returning it only if its scheme is allowed.

getLink(href: Nullish<PossibleLink>): ImmutableURI | undefined