Files
Paradise/html/browser/marked-paradise.js
Mikhail Dzianishchyts c129ac3076 Edit max line length (#25071)
* Edit max line length

* oh god

* ts also

* rebuild tgui

* Format again after conflicts resolving

* Me rebuild tgui

* this is minified

* this is removed

* rebuild tgui
2024-06-29 18:17:26 +00:00

22 lines
854 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;
if (node.children.length == 0) {
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.children[0].tagName == 'P') node.innerHTML = node.children[0].innerHTML;
}
}
window.onload = function () {
if ($('#markdown')) parse($('#markdown'));
};