Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jstransformer #12

Closed
JosefJezek opened this issue Sep 22, 2015 · 7 comments
Closed

jstransformer #12

JosefJezek opened this issue Sep 22, 2015 · 7 comments

Comments

@JosefJezek
Copy link

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

@zephraph
Copy link
Owner

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);

@JosefJezek
Copy link
Author

CommonMark have different API than marked. :-( I get error.

https://github.com/jgm/commonmark.js

@zephraph
Copy link
Owner

Can you give me an example of what you're trying to accomplish?

@JosefJezek
Copy link
Author

require('nunjucks-markdown').register(env, require('commonmark'));

Message:
    (unknown path)
  TypeError: object is not a function

@zephraph
Copy link
Owner

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.

@JosefJezek
Copy link
Author

Thank you 👍

I will use it in this repo https://github.com/StartPolymer/polymer-starter-kit-plus

@zephraph
Copy link
Owner

No problem. Let me know if you have any more issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants