marked extensions is ignored if sent renderer

54 Views Asked by At

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) how to make both work together?

1

There are 1 best solutions below

0
On

answer from GitHub https://github.com/markedjs/marked/discussions/3061#discussioncomment-7411454

marked.use({renderer: new Renderer()});
marked.use(gfmHeadingId());
const text = marked.parse(this.originalText)