Repository navigation
docs: show how to supply a custom parser - #4313
friedman-max wants to merge 1 commit into
Conversation
|
@friedman-max is attempting to deploy a commit to the MarkedJS Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
UziTech
left a comment
There was a problem hiding this comment.
Thanks for adding documentation for provideParser! A few accuracy and consistency adjustments before merging:
-
Keep the return type in the Hooks table (
docs/USING_PRO.md, line 294):
ChangingprovideParser(): (tokens: Token[], options?: MarkedOptions) => stringtoprovideParser(block?: boolean)drops the return signature. Please keep the return type so readers can see the(tokens, options)callback signature andfalsefallback, e.g.:
`provideParser(block?: boolean): ((tokens: Token[], options?: MarkedOptions) => ParserOutput) | false`(or=> any). -
Include
provideLexerin the exception note:
The new paragraph states that "provideParserhooks are an exception", but bothprovideLexerandprovideParserare non-pass-through provider hooks (neither is in_Hooks.passThroughHooks), both receiveblock?: boolean, and both fall back to the previous hook onfalsewithout chaining results. Please mention bothprovideLexerandprovideParserhere (and optionally addblock?: booleanto theprovideLexertable row for consistency). -
Avoid the misleading "interactions between adjacent tokens" note and per-token
Parserinstantiation:
Marked's built-inParser.parserenders each token independently and concatenates the output (reference link definitions are resolved during lexing), so there are no built-in interactions between adjacent tokens during parsing. CallingParser.parse([token], options)insidetokens.map(...)also constructs a newParser(andTextRenderer) for every top-level token. Consider reusing a single parser instance:const parser = new Parser(options); return tokens.map((token) => ({ type: token.type, html: parser.parse([token]), }));
and removing or rewording the "adjacent tokens" sentence (e.g., noting that custom stateful renderers/extensions expecting the full token array may need
parser.parse(tokens)). -
Style consistency (optional nit):
Other examples indocs/USING_PRO.mduse a separate**Output:**block below the code snippet instead of inline// ...comments, and the Hooks examples roughly follow the table order (preprocess,postprocess,processAllTokens/provideLexer,emStrongMask). Moving this example to the end of the Hooks section with an**Output:**block would match the rest of the page.
Marked version: 18.4.0 (
471f274)Markdown flavor: n/a (documentation)
Description
Refs #4282. Add a runnable
provideParserexample that returns rendered HTML alongside each top-level token. Show how to fall back for inline parsing and explain why parser results are not chained. No runtime changes.Contributor
Disclosure: Prepared with OpenAI Codex assistance.