mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
fix MathJax v3 support
1. Support MathJax inside a fenced code block; 2. Support scale factor in preview;
This commit is contained in:
parent
5df695c1ea
commit
7d3732c58f
@ -256,13 +256,6 @@ var postProcessMathJaxWhenMathjaxReady = function() {
|
||||
content.setLog("err: " + err);
|
||||
}
|
||||
}
|
||||
|
||||
if (node.tagName.toLowerCase() == 'code') {
|
||||
var pre = node.parentNode;
|
||||
var p = document.createElement('p');
|
||||
p.innerHTML = node.innerHTML;
|
||||
pre.parentNode.replaceChild(p, pre);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1269,6 +1269,7 @@ var renderCodeBlockLineNumber = function() {
|
||||
|
||||
var addClassToCodeBlock = function() {
|
||||
var codes = document.getElementsByTagName('code');
|
||||
var mathCodes = [];
|
||||
for (var i = 0; i < codes.length; ++i) {
|
||||
var code = codes[i];
|
||||
var pare = code.parentElement;
|
||||
@ -1278,13 +1279,20 @@ var addClassToCodeBlock = function() {
|
||||
if (VEnableMathjax
|
||||
&& (code.classList.contains("lang-mathjax")
|
||||
|| code.classList.contains("language-mathjax"))) {
|
||||
// Add the class to pre.
|
||||
pare.classList.add("lang-mathjax");
|
||||
pare.classList.add("language-mathjax");
|
||||
pare.classList.add("tex-to-render");
|
||||
mathCodes.push(code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Replace math codes with <x-eqn>.
|
||||
for (var i = mathCodes.length - 1; i >= 0; --i) {
|
||||
var code = mathCodes[i];
|
||||
var pare = code.parentElement;
|
||||
var xeqn = document.createElement('x-eqn');
|
||||
xeqn.classList.add("tex-to-render");
|
||||
xeqn.innerHTML = code.innerHTML;
|
||||
pare.parentNode.replaceChild(xeqn, pare);
|
||||
}
|
||||
};
|
||||
|
||||
var addCopyButtonToCodeBlock = function() {
|
||||
|
@ -16,7 +16,8 @@
|
||||
inlineMath: [['$', '$'], ['\\(', '\\)']]
|
||||
},
|
||||
chtml: {
|
||||
scale: 1 // http://docs.mathjax.org/en/latest/options/output/index.html#options-common-to-all-output-processors
|
||||
// http://docs.mathjax.org/en/latest/options/output/index.html#options-common-to-all-output-processors
|
||||
scale: SCALE_FACTOR_PLACE_HOLDER
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
@ -967,8 +967,6 @@ QString VUtils::generateMathJaxPreviewTemplate()
|
||||
|
||||
QString extraFile;
|
||||
|
||||
QString mathjaxScale = QString::number((int)(100 * VUtils::calculateScaleFactor()));
|
||||
|
||||
/*
|
||||
// Mermaid.
|
||||
extraFile += "<link rel=\"stylesheet\" type=\"text/css\" href=\"" + g_config->getMermaidCssStyleUrl() + "\"/>\n" +
|
||||
|
@ -45,6 +45,7 @@ namespace HtmlHolder
|
||||
static const QString c_cssHolder = "CSS_PLACE_HOLDER";
|
||||
static const QString c_codeBlockCssHolder = "HIGHLIGHTJS_CSS_PLACE_HOLDER";
|
||||
static const QString c_commonCssHolder = "COMMON_CSS_PLACE_HOLDER";
|
||||
static const QString c_scaleFactorHolder = "SCALE_FACTOR_PLACE_HOLDER";
|
||||
static const QString c_globalStyleHolder = "/* STYLE_GLOBAL_PLACE_HOLDER */";
|
||||
static const QString c_extraHolder = "<!-- EXTRA_PLACE_HOLDER -->";
|
||||
static const QString c_bodyHolder = "<!-- BODY_PLACE_HOLDER -->";
|
||||
|
@ -195,6 +195,8 @@ QString VNote::generateMathJaxPreviewTemplate()
|
||||
|
||||
templ.replace(HtmlHolder::c_cssHolder, g_config->getCssStyleUrl());
|
||||
|
||||
templ.replace(HtmlHolder::c_scaleFactorHolder, QString::number(VUtils::calculateScaleFactor()));
|
||||
|
||||
return templ;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user