Merge pull request #167 from gazpachoking/markdown-it

Switch from marked to markdown-it markdown renderer
This commit is contained in:
Matthew Scragg 2016-09-05 13:23:14 -04:00 committed by GitHub
commit c6db7909b8
3 changed files with 32 additions and 23 deletions

View file

@ -10,7 +10,8 @@
"keymaster": "madrobby/keymaster",
"ace-builds": "~1.2.3",
"parsleyjs": "~2.3.10",
"marked": "~0.3.2",
"markdown-it": "~7.0.0",
"markdown-it-anchor": "https://wzrd.in/standalone/markdown-it-anchor@2.5.0",
"js-yaml": "~3.6.0",
"store-js": "~1.3.16",
"bootswatch-dist": "3.3.6-flatly",

View file

@ -231,7 +231,8 @@ assets.register('main.js',
'vendor/components-bootstrap/js/bootstrap.js',
'vendor/handlebars/handlebars.js',
'vendor/js-yaml/dist/js-yaml.js',
'vendor/marked/lib/marked.js',
'vendor/markdown-it/dist/markdown-it.js',
'vendor/markdown-it-anchor/index.0',
'js/html-sanitizer-minified.js', # don't minify?
'vendor/highlightjs/highlight.pack.js',
'vendor/parsleyjs/dist/parsley.js',

View file

@ -38,15 +38,28 @@ var metaMarked = function(src, opt, callback) {
}
};
marked.setOptions({
renderer: new marked.Renderer(),
gfm: true,
tables: true,
breaks: false,
pedantic: false,
sanitize: false,
smartLists: true,
smartypants: false
var markdownit = window.markdownit({
html: true,
linkify: true,
typographer: true,
highlight: function (str, lang) {
if (lang && hljs.getLanguage(lang)) {
try {
return hljs.highlight(lang, str).value;
} catch (__) {
}
}
return ''; // use external default escaping
}
}).use(markdownItAnchor, {
level: 1,
// slugify: string => string,
permalink: false,
// renderPermalink: (slug, opts, state, permalink) => {},
permalinkClass: 'header-anchor',
permalinkSymbol: '¶',
permalinkBefore: false
});
// Markdown Renderer
@ -54,9 +67,8 @@ var MDR = {
meta: null,
md: null,
sanitize: true, // Override
renderer: new marked.Renderer(),
parse: function(md){
return marked(md, { renderer: this.renderer });
return markdownit.render(md);
},
convert: function(md, sanitize) {
if (this.sanitize !== null) {
@ -108,13 +120,8 @@ var MDR = {
}
};
MDR.renderer.table = function(header, body) {
return '<table class="table table-bordered">\n'
+ '<thead>\n'
+ header
+ '</thead>\n'
+ '<tbody>\n'
+ body
+ '</tbody>\n'
+ '</table>\n';
};
// Add some custom classes to table tags
markdownit.renderer.rules.table_open = function (tokens, idx, options, env, self) {
tokens[idx].attrPush(['class', 'table table-bordered']);
return self.renderToken(tokens, idx, options);
};