Skip to content

Commit

Permalink
docs: Tweaks to docs to make them clearer, regarding hooks and option…
Browse files Browse the repository at this point in the history
…s 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
  • Loading branch information
audiodude authored Aug 16, 2023
1 parent 6c2c64c commit 4e6acc8
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions docs/USING_PRO.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand All @@ -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(`
Expand Down Expand Up @@ -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);
Expand Down

1 comment on commit 4e6acc8

@vercel
Copy link

@vercel vercel bot commented on 4e6acc8 Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.