Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

316
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda