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

149
Visualizações
markdown is not a function

markdown is not a function , though i have installed it using npm install marked In the app.js i have used app.use in which res.local.filterUserHTML is a function, which uses markdown function, But when this is invoked it gives error, stating it doesn't recognize the markdown function.

app.js

const sanitizeHTML = require('sanitize-html')
const markdown = require('marked')

app.use(function(req, res, next) {
  
  res.locals.filterUserHTML = function(content) {
    return sanitizeHTML(markdown(content), {allowedTags: ['bold', 'i'], allowedAttributes: {}})
  }
}

single-post-screen.ejs

...
 <div class="body-content">
    <%- filterUserHTML(post.body) %>
  </div>
...

Output gives an error

TypeError: E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\views\single-post-screen.ejs:44
    42| 
    43|   <div class="body-content">
 >> 44|     <%- filterUserHTML(post.body) %>
    45|   </div>
    46| 
    47|   

markdown is not a function
    at Object.res.locals.filterUserHTML (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\app.js:41:25)
    at eval (eval at compile (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\ejs\lib\ejs.js:662:12), <anonymous>:47:17)
    at single-post-screen (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\ejs\lib\ejs.js:692:17)
    at tryHandleCache (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\ejs\lib\ejs.js:272:36)
    at View.exports.renderFile [as engine] (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\ejs\lib\ejs.js:489:10)
    at View.render (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\express\lib\view.js:135:8)
    at tryRender (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\express\lib\application.js:640:10)
    at Function.render (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\node_modules\express\lib\response.js:1017:7)
    at exports.viewSingle (E:\Web Development\Javascript\Javascript Full Stack from Scratch\ComplexApp\controllers\postController.js:25:9)
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

From the docs:

import { marked } from 'marked';
// or const { marked } = require('marked');

const html = marked.parse('# Marked in Node.js\n\nRendered by **marked**.');

So instead of using markdown(), try using markdown.parse().

about 4 years ago · Juan Pablo Isaza Relatório

0

I meet the problem when run observablehq/runtime.js in local environment. I don't know why it doesn't work on my computer but worked on another. I have to modify the runtime.js like @VaiTon suggested.

r.innerHTML = t.parse(n, { langPrefix: "" }).trim(); // call parse method of object t i.e. marked
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