Files
Paradise/html/browser/marked-paradise.js
moxian dce6e5b4af Fix paperwork acquiring extra line breaks when you change register (#12652)
* Move paradise-specific customization of marked.js to separate file.

This makes marked.js easily updatable from upstream if need be.

* Fix extra paragraphs being inserted when doing paperwork
2020-05-21 20:12:18 -06:00

28 lines
860 B
JavaScript

// Paradise-specific handling of marked.js.
// Basically we call it on element with id=markdown, and play with paragraphization a bit
// Requires marked.js to be loaded in order to be useful.
var $ = document.querySelector.bind(document);
function parse(node) {
for (var i = 0; i < node.childNodes.length; i++) {
parse(node.childNodes[i]);
}
if (!node.innerHTML) {
return;
}
node.innerHTML = marked(node.innerHTML.replace(/<br>/gi, '\n').replace(/\t/gi, ''), { breaks: false, gfm: false })
// marked.js wraps content into <p> tags, which is looks atrocious when we call it recursively.
// The following line unwraps it.
if (node.children.length == 1) {
node.innerHTML = node.children[0].innerHTML;
}
}
window.onload = function() {
if ($('#markdown')) {
parse($('#markdown'));
}
}