use extensions with renderer #3061
-
simply if I used this code the extension is working fine const originalText = '## hello world';
marked.use(gfmHeadingId());
const text = marked.parse(originalText);
console.log('text') // <h2 id="hello-world">hello world</h2> but if I changed it to const originalText = '## hello world';
marked.use(gfmHeadingId());
const text = marked.parse(this.originalText, {
renderer: new Renderer(),
});
console.log('text') // <h2>hello world</h2> it stop working (the h2 doesn't have the id now) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
By passing the renderer in to the options you are overwriting the renderer in gfmHeadingId. You can set the renderer first and then overwrite the heading renderer with gfmHeadingId. marked.use({renderer: new Renderer()});
marked.use(gfmHeadingId());
const text = marked.parse(this.originalText) |
Beta Was this translation helpful? Give feedback.
-
You could try monkey patching something to get it to work but there is no other official way. gfmHeadingId overwrites the heading renderer. If the heading renderer is overwritten again than the gfmHeadingId renderer won't get called. |
Beta Was this translation helpful? Give feedback.
By passing the renderer in to the options you are overwriting the renderer in gfmHeadingId.
You can set the renderer first and then overwrite the heading renderer with gfmHeadingId.