Closed JosefJezek closed 9 years ago
You can already use your own markdown tool. I specifically designed it that way.
Call the register
method with the first argument being the environment returned from nunjucks and the second being a method that renders markdown.
var nunjucks = require('nunjucks'),
markdown = require('nunjucks-markdown');
var env = nunjucks.configure('views');
// The second argument can be any function that renders markdown
markdown.register(env, yourRenderMethod);
CommonMark have different API than marked. :-( I get error.
Can you give me an example of what you're trying to accomplish?
require('nunjucks-markdown').register(env, require('commonmark'));
Message:
(unknown path)
TypeError: object is not a function
You are trying to pass in the commonmark module as a whole, but that doesn't work. The reason I could pass in marked
in my example is because when you do require('marked')
it actually returns a method that takes in a string of markdown and returns the rendered html.
It looks to me like you'll have to do something like this:
var nunjucks = require('nunjucks'),
markdown = require('nunjucks-markdown'),
cm = require('commonmark');
var env = nunjucks.configure('views');
var reader = new cm.Parser();
var writer = new cm.HtmlRenderer();
function render(markdown) {
var parsed = reader.parse(markdown);
return writer.render(parsed);
}
markdown.register(env, render);
This may or may not work, but it's just something I slapped together by looking at the commonmark examples.
Thank you :+1:
I will use it in this repo https://github.com/StartPolymer/polymer-starter-kit-plus
No problem. Let me know if you have any more issues.
Could you add jstransformer for load own markdown renderer? I need CommonMark.
https://github.com/jstransformers/inputformat-to-jstransformer https://github.com/jstransformers/inputformat-to-jstransformer/blob/master/dictionary.json https://github.com/jstransformers/jstransformer-commonmark
Thank you