Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
User defined renderer object causes a TypeError - marked.js

Right now I'm familiarizing myself with marked.js. I want to add html attributes to the elements that are rendered when marked.parse() is called. In doing so a custom renderer object has been defined which overrides the code method.

When the renderer object is passed to marked.parse(string, {'renderer': renderer}), and I start typing in the TextArea that marked.js is supposed to parse the following error is raised:

  • Uncaught TypeError: t.text is not a function

https://marked.js.org/using_pro#renderer

The renderer defines the HTML output of a given token. If you supply a renderer object to the Marked options, it will be merged with the built-in renderer and any functions inside will override the default handling of that token type.

What is causing this error to be raised?

const renderer = {
  code(code, infoString) {
    return `
      <code class="block_code_snippet fill_block_width">${string}</code
    `
  },
};
post_content_body.addEventListener("keyup", (event) => {
  let marked_post_content = marked.parse(
    post_content_body.value, {"renderer": renderer}
  );
  post_preview.innerHTML = marked_post_content
})
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

I believe the renderer object passed in is not merged with the default renderer, but replaces it completely. As a result, the renderer only handles code, but loses all other rendereing capabilities - see "Block-level renderer methods" and "Inline-level renderer methods" here.

Try changing your code to something like:

const renderer = new marked.Renderer();
renderer.code = function(code, infoString) {
  return `
    <code class="block_code_snippet fill_block_width">${string}</code
  `
};
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!