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
This commit is contained in:
Travis Briggs 2023-08-16 12:44:41 -07:00 committed by GitHub
parent 6c2c64c193
commit 4e6acc8b85
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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.
<h2 id="extend">Access to Lexer and Parser</h2>
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);