mirror of
https://github.com/loikein/hugo-tufte.git
synced 2024-12-25 14:59:44 +01:00
23 lines
809 B
JavaScript
23 lines
809 B
JavaScript
|
(function() {
|
||
|
var i, text, code, codes = document.getElementsByTagName('code');
|
||
|
for (i = 0; i < codes.length;) {
|
||
|
code = codes[i];
|
||
|
if (code.parentNode.tagName !== 'PRE' && code.childElementCount === 0 && !(code.classList.contains("nolatex")) ) {
|
||
|
text = code.textContent;
|
||
|
if (/^\$[^$]/.test(text) && /[^$]\$$/.test(text)) {
|
||
|
text = text.replace(/^\$/, '\\(').replace(/\$$/, '\\)');
|
||
|
code.textContent = text;
|
||
|
}
|
||
|
if (/^\\\((.|\s)+\\\)$/.test(text) || /^\\\[(.|\s)+\\\]$/.test(text) ||
|
||
|
/^\$(.|\s)+\$$/.test(text) ||
|
||
|
/^\\begin\{([^}]+)\}(.|\s)+\\end\{[^}]+\}$/.test(text)) {
|
||
|
code.outerHTML = code.innerHTML; // remove <code></code>
|
||
|
continue;
|
||
|
}
|
||
|
}
|
||
|
i++;
|
||
|
}
|
||
|
})();
|
||
|
|
||
|
// https://yihui.org/en/2018/07/latex-math-markdown/
|