From 4e6acc8b8517eafe0036a914f58b6f53d4b12ca6 Mon Sep 17 00:00:00 2001 From: Travis Briggs Date: Wed, 16 Aug 2023 12:44:41 -0700 Subject: [PATCH] docs: Tweaks to docs to make them clearer, regarding hooks and options to lexer/parser (#2946) * Tweaks to docs to make them clearer, regarding hooks and options to lexer/parser * Remove extraneous commas * Update description of lexer/renderer options --- docs/USING_PRO.md | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/docs/USING_PRO.md b/docs/USING_PRO.md index bd16f1a3cc..5231d9983f 100644 --- a/docs/USING_PRO.md +++ b/docs/USING_PRO.md @@ -322,19 +322,17 @@ import { marked } from 'marked'; import fm from 'front-matter'; // Override function -const hooks = { - preprocess(markdown) { - const { attributes, body } = fm(markdown); - for (const prop in attributes) { - if (prop in this.options) { - this.options[prop] = attributes[prop]; - } +function preprocess(markdown) { + const { attributes, body } = fm(markdown); + for (const prop in attributes) { + if (prop in this.options) { + this.options[prop] = attributes[prop]; } - return body; } -}; + return body; +} -marked.use({ hooks }); +marked.use({ hooks: { preprocess } }); // Run marked console.log(marked.parse(` @@ -359,13 +357,11 @@ import { marked } from 'marked'; import DOMPurify from 'isomorphic-dompurify'; // Override function -const hooks = { - postprocess(html) { - return DOMPurify.sanitize(html); - } -}; +function postprocess(html) { + return DOMPurify.sanitize(html); +} -marked.use({ hooks }); +marked.use({ hooks: { postprocess } }); // Run marked console.log(marked.parse(` @@ -615,7 +611,9 @@ The parser takes tokens as input and calls the renderer functions.

Access to Lexer and Parser

-You also have direct access to the lexer and parser if you so desire. +You also have direct access to the lexer and parser if you so desire. The lexer and parser options are the same as passed to `marked.setOptions()` except they have to be full options objects, they don't get merged with the current or default options. + + ``` js const tokens = marked.lexer(markdown, options);