Skip to content

Instantly share code, notes, and snippets.

@ando-takahiro
Created October 13, 2014 12:56
Show Gist options
  • Select an option

  • Save ando-takahiro/179d4f5a09f22c9085d8 to your computer and use it in GitHub Desktop.

Select an option

Save ando-takahiro/179d4f5a09f22c9085d8 to your computer and use it in GitHub Desktop.
this shows how to implement a ruby feature ( http://conv.denshochan.com/markdown#ruby ). tested on node 0.10.30 & markdown-js 0.5.0
var Markdown = require('markdown').markdown.Markdown;
var MyDialect = Markdown.subclassDialect(Markdown.dialects.Gruber);
MyDialect.inline['{'] = function inline_ruby(text, matches, out) {
var m = text.match(/^\{(.+)\|(.+)\}/);
if (m) {
return [m[0].length, ['ruby', m[2], m[1]]];
} else {
// no match
return [1, '{'];
}
};
Markdown.buildBlockOrder(MyDialect.block);
Markdown.buildInlinePatterns(MyDialect.inline);
var parser = new Markdown(MyDialect);
console.log(parser.toTree('{hello|world}'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment