|
|
@ -15,6 +15,7 @@ define([
|
|
|
|
|
|
|
|
|
|
|
|
var DiffDOM = window.diffDOM;
|
|
|
|
var DiffDOM = window.diffDOM;
|
|
|
|
var renderer = new Marked.Renderer();
|
|
|
|
var renderer = new Marked.Renderer();
|
|
|
|
|
|
|
|
var restrictedRenderer = new Marked.Renderer();
|
|
|
|
|
|
|
|
|
|
|
|
var Mermaid = {
|
|
|
|
var Mermaid = {
|
|
|
|
init: function () {}
|
|
|
|
init: function () {}
|
|
|
@ -61,13 +62,18 @@ define([
|
|
|
|
return h('div.cp-md-toc', content).outerHTML;
|
|
|
|
return h('div.cp-md-toc', content).outerHTML;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DiffMd.render = function (md, sanitize) {
|
|
|
|
DiffMd.render = function (md, sanitize, restrictedMd) {
|
|
|
|
|
|
|
|
Marked.setOptions({
|
|
|
|
|
|
|
|
renderer: restrictedMd ? restrictedRenderer : renderer,
|
|
|
|
|
|
|
|
});
|
|
|
|
var r = Marked(md, {
|
|
|
|
var r = Marked(md, {
|
|
|
|
sanitize: sanitize
|
|
|
|
sanitize: sanitize
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Add Table of Content
|
|
|
|
// Add Table of Content
|
|
|
|
|
|
|
|
if (!restrictedMd) {
|
|
|
|
r = r.replace(/<div class="cp-md-toc"><\/div>/g, getTOC());
|
|
|
|
r = r.replace(/<div class="cp-md-toc"><\/div>/g, getTOC());
|
|
|
|
|
|
|
|
}
|
|
|
|
toc = [];
|
|
|
|
toc = [];
|
|
|
|
|
|
|
|
|
|
|
|
return r;
|
|
|
|
return r;
|
|
|
@ -83,6 +89,7 @@ define([
|
|
|
|
return defaultCode.apply(renderer, arguments);
|
|
|
|
return defaultCode.apply(renderer, arguments);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictedRenderer.code = renderer.code;
|
|
|
|
|
|
|
|
|
|
|
|
var stripTags = function (text) {
|
|
|
|
var stripTags = function (text) {
|
|
|
|
var div = document.createElement("div");
|
|
|
|
var div = document.createElement("div");
|
|
|
@ -109,6 +116,9 @@ define([
|
|
|
|
});
|
|
|
|
});
|
|
|
|
return "<h" + level + " id=\"" + id + "\"><a href=\"#" + id + "\" class=\"anchor\"></a>" + text + "</h" + level + ">";
|
|
|
|
return "<h" + level + " id=\"" + id + "\"><a href=\"#" + id + "\" class=\"anchor\"></a>" + text + "</h" + level + ">";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictedRenderer.heading = function (text) {
|
|
|
|
|
|
|
|
return text;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Tasks list
|
|
|
|
// Tasks list
|
|
|
|
var checkedTaskItemPtn = /^\s*(<p>)?\[[xX]\](<\/p>)?\s*/;
|
|
|
|
var checkedTaskItemPtn = /^\s*(<p>)?\[[xX]\](<\/p>)?\s*/;
|
|
|
@ -138,6 +148,13 @@ define([
|
|
|
|
var cls = (isCheckedTaskItem || isUncheckedTaskItem || hasBogusInput) ? ' class="todo-list-item"' : '';
|
|
|
|
var cls = (isCheckedTaskItem || isUncheckedTaskItem || hasBogusInput) ? ' class="todo-list-item"' : '';
|
|
|
|
return '<li'+ cls + '>' + text + '</li>\n';
|
|
|
|
return '<li'+ cls + '>' + text + '</li>\n';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictedRenderer.listitem = function (text) {
|
|
|
|
|
|
|
|
if (bogusCheckPtn.test(text)) {
|
|
|
|
|
|
|
|
text = text.replace(bogusCheckPtn, '');
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return '<li>' + text + '</li>\n';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
renderer.image = function (href, title, text) {
|
|
|
|
renderer.image = function (href, title, text) {
|
|
|
|
if (href.slice(0,6) === '/file/') {
|
|
|
|
if (href.slice(0,6) === '/file/') {
|
|
|
|
// DEPRECATED
|
|
|
|
// DEPRECATED
|
|
|
@ -162,12 +179,19 @@ define([
|
|
|
|
out += this.options.xhtml ? '/>' : '>';
|
|
|
|
out += this.options.xhtml ? '/>' : '>';
|
|
|
|
return out;
|
|
|
|
return out;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictedRenderer.image = renderer.image;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var renderParagraph = function (p) {
|
|
|
|
|
|
|
|
return /<media\-tag[\s\S]*>/i.test(p)? p + '\n': '<p>' + p + '</p>\n';
|
|
|
|
|
|
|
|
};
|
|
|
|
renderer.paragraph = function (p) {
|
|
|
|
renderer.paragraph = function (p) {
|
|
|
|
if (p === '[TOC]') {
|
|
|
|
if (p === '[TOC]') {
|
|
|
|
return '<p><div class="cp-md-toc"></div></p>';
|
|
|
|
return '<p><div class="cp-md-toc"></div></p>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return /<media\-tag[\s\S]*>/i.test(p)? p + '\n': '<p>' + p + '</p>\n';
|
|
|
|
return renderParagraph(p);
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
restrictedRenderer.paragraph = function (p) {
|
|
|
|
|
|
|
|
return renderParagraph(p);
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
var MutationObserver = window.MutationObserver;
|
|
|
|
var MutationObserver = window.MutationObserver;
|
|
|
|