zephraph / nunjucks-markdown

Markdown extension for Nunjucks. Use your own renderer!
MIT License
49 stars 12 forks source link

Getting: TypeError: renderMarkdown is not a function #30

Open andyjones81 opened 2 years ago

andyjones81 commented 2 years ago

Followed these exact instructions to add it to my project and get the error: TypeError: renderMarkdown is not a function

Even tried it in a blank new project and get the same error.

zephraph commented 2 years ago

Hey @andyjones81, I'll need more information to be able to help. The error your getting is because the second argument of the .register method is supposed to be a function that takes markdown text and returns html text. You're likely not passing the correct thing to it, but I can't tell without more details.

andyjones81 commented 2 years ago

@zephraph Just tried this in another project same problem:

app.js

const nunjucks = require('nunjucks');
const markdown = require('nunjucks-markdown');
const marked = require('marked');

// Nunjucks configuration
const appViews = [
  path.join(__dirname, '/app/views/')
];

const env = nunjucks.configure(appViews, {
  autoescape: true,
  express: app,
  noCache: true,
  watch: true,
});

markdown.register(env, marked);

content.md

# demo title

Body content

view

{% markdown "includes/content.md" %}

I've also tried in the view

{% markdown %}

# Title

Body content

{% endmarkdown %}

Result:

Template render error: (C:\source\demoapp\app\views\accessibility\accessibility-statement.njk) [Line 8, Column 3]
  TypeError: renderMarkdown is not a function
    at Object._prettifyError (C:\source\demoapp\node_modules\nunjucks\src\lib.js:36:11)
    at C:\source\demoapp\node_modules\nunjucks\src\environment.js:563:19
    at eval (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:481:13)
    at eval (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:78:11)
    at b_bodyContent (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:92:3)
    at eval (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:77:32)
    at eval (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:128:1)
    at eval (eval at _compile (C:\source\demoapp\node_modules\nunjucks\src\environment.js:633:18), <anonymous>:124:1)
    at fn (C:\source\demoapp\node_modules\a-sync-waterfall\index.js:26:24)
    at C:\source\demoapp\node_modules\a-sync-waterfall\index.js:66:22
zephraph commented 2 years ago

It looks like the api for marked has changed.

Try this instead:

markdown.register(env, marked.parse);
andyjones81 commented 2 years ago

It has indeed, yes this does now work.

It looks like the api for marked has changed.

Try this instead:

markdown.register(env, marked.parse);