Merge pull request #167 from gazpachoking/markdown-it
Switch from marked to markdown-it markdown renderer
This commit is contained in:
commit
c6db7909b8
|
@ -10,7 +10,8 @@
|
||||||
"keymaster": "madrobby/keymaster",
|
"keymaster": "madrobby/keymaster",
|
||||||
"ace-builds": "~1.2.3",
|
"ace-builds": "~1.2.3",
|
||||||
"parsleyjs": "~2.3.10",
|
"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",
|
"js-yaml": "~3.6.0",
|
||||||
"store-js": "~1.3.16",
|
"store-js": "~1.3.16",
|
||||||
"bootswatch-dist": "3.3.6-flatly",
|
"bootswatch-dist": "3.3.6-flatly",
|
||||||
|
|
|
@ -231,7 +231,8 @@ assets.register('main.js',
|
||||||
'vendor/components-bootstrap/js/bootstrap.js',
|
'vendor/components-bootstrap/js/bootstrap.js',
|
||||||
'vendor/handlebars/handlebars.js',
|
'vendor/handlebars/handlebars.js',
|
||||||
'vendor/js-yaml/dist/js-yaml.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?
|
'js/html-sanitizer-minified.js', # don't minify?
|
||||||
'vendor/highlightjs/highlight.pack.js',
|
'vendor/highlightjs/highlight.pack.js',
|
||||||
'vendor/parsleyjs/dist/parsley.js',
|
'vendor/parsleyjs/dist/parsley.js',
|
||||||
|
|
|
@ -38,15 +38,28 @@ var metaMarked = function(src, opt, callback) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
marked.setOptions({
|
var markdownit = window.markdownit({
|
||||||
renderer: new marked.Renderer(),
|
html: true,
|
||||||
gfm: true,
|
linkify: true,
|
||||||
tables: true,
|
typographer: true,
|
||||||
breaks: false,
|
highlight: function (str, lang) {
|
||||||
pedantic: false,
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
sanitize: false,
|
try {
|
||||||
smartLists: true,
|
return hljs.highlight(lang, str).value;
|
||||||
smartypants: false
|
} 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
|
// Markdown Renderer
|
||||||
|
@ -54,9 +67,8 @@ var MDR = {
|
||||||
meta: null,
|
meta: null,
|
||||||
md: null,
|
md: null,
|
||||||
sanitize: true, // Override
|
sanitize: true, // Override
|
||||||
renderer: new marked.Renderer(),
|
|
||||||
parse: function(md){
|
parse: function(md){
|
||||||
return marked(md, { renderer: this.renderer });
|
return markdownit.render(md);
|
||||||
},
|
},
|
||||||
convert: function(md, sanitize) {
|
convert: function(md, sanitize) {
|
||||||
if (this.sanitize !== null) {
|
if (this.sanitize !== null) {
|
||||||
|
@ -108,13 +120,8 @@ var MDR = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
MDR.renderer.table = function(header, body) {
|
// Add some custom classes to table tags
|
||||||
return '<table class="table table-bordered">\n'
|
markdownit.renderer.rules.table_open = function (tokens, idx, options, env, self) {
|
||||||
+ '<thead>\n'
|
tokens[idx].attrPush(['class', 'table table-bordered']);
|
||||||
+ header
|
return self.renderToken(tokens, idx, options);
|
||||||
+ '</thead>\n'
|
};
|
||||||
+ '<tbody>\n'
|
|
||||||
+ body
|
|
||||||
+ '</tbody>\n'
|
|
||||||
+ '</table>\n';
|
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in a new issue