mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
MdEditor: turn equation from zhihu.com to MathJax when fetching images
This commit is contained in:
parent
3196ef8512
commit
203544632e
@ -792,6 +792,11 @@ QString VUtils::generateHtmlTemplate(const QString &p_template,
|
|||||||
"processClass: \"tex2jax_process|language-mathjax|lang-mathjax\"},\n"
|
"processClass: \"tex2jax_process|language-mathjax|lang-mathjax\"},\n"
|
||||||
" showProcessingMessages: false,\n"
|
" showProcessingMessages: false,\n"
|
||||||
" skipStartupTypeset: " + QString("%1,\n").arg(mathjaxTypeSetOnLoad ? "false" : "true") +
|
" skipStartupTypeset: " + QString("%1,\n").arg(mathjaxTypeSetOnLoad ? "false" : "true") +
|
||||||
|
" TeX: {\n"
|
||||||
|
" Macros: {\n"
|
||||||
|
" bm: [\"\\\\boldsymbol{#1}\", 1]\n"
|
||||||
|
" }\n"
|
||||||
|
" },\n"
|
||||||
" messageStyle: \"none\"});\n"
|
" messageStyle: \"none\"});\n"
|
||||||
"MathJax.Hub.Register.StartupHook(\"End\", function() { handleMathjaxReady(); });\n"
|
"MathJax.Hub.Register.StartupHook(\"End\", function() { handleMathjaxReady(); });\n"
|
||||||
"</script>\n"
|
"</script>\n"
|
||||||
@ -894,6 +899,11 @@ with 2em, if there are Chinese characters in it, the font will be a mess.
|
|||||||
"}\n"
|
"}\n"
|
||||||
#endif
|
#endif
|
||||||
"}\n"
|
"}\n"
|
||||||
|
"},\n"
|
||||||
|
"TeX: {\n"
|
||||||
|
" Macros: {\n"
|
||||||
|
" bm: [\"\\\\boldsymbol{#1}\", 1]\n"
|
||||||
|
" }\n"
|
||||||
"}\n"
|
"}\n"
|
||||||
"});\n"
|
"});\n"
|
||||||
"</script>\n";
|
"</script>\n";
|
||||||
@ -955,6 +965,11 @@ QString VUtils::generateMathJaxPreviewTemplate()
|
|||||||
" scale: " + mathjaxScale + "\n"
|
" scale: " + mathjaxScale + "\n"
|
||||||
" },\n"
|
" },\n"
|
||||||
" showProcessingMessages: false,\n"
|
" showProcessingMessages: false,\n"
|
||||||
|
" TeX: {\n"
|
||||||
|
" Macros: {\n"
|
||||||
|
" bm: [\"\\\\boldsymbol{#1}\", 1]\n"
|
||||||
|
" }\n"
|
||||||
|
" },\n"
|
||||||
" messageStyle: \"none\"});\n"
|
" messageStyle: \"none\"});\n"
|
||||||
"</script>\n";
|
"</script>\n";
|
||||||
|
|
||||||
|
@ -2042,6 +2042,8 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
|
|||||||
proDlg.setWindowModality(Qt::WindowModal);
|
proDlg.setWindowModality(Qt::WindowModal);
|
||||||
proDlg.setWindowTitle(tr("Fetching Images To Local Folder"));
|
proDlg.setWindowTitle(tr("Fetching Images To Local Folder"));
|
||||||
|
|
||||||
|
QRegExp zhihuRegExp("^https?://www\\.zhihu\\.com/equation\\?tex=(.+)$");
|
||||||
|
|
||||||
QRegExp regExp(VUtils::c_imageLinkRegExp);
|
QRegExp regExp(VUtils::c_imageLinkRegExp);
|
||||||
for (int i = regs.size() - 1; i >= 0; --i) {
|
for (int i = regs.size() - 1; i >= 0; --i) {
|
||||||
proDlg.setValue(regs.size() - 1 - i);
|
proDlg.setValue(regs.size() - 1 - i);
|
||||||
@ -2065,6 +2067,25 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
|
|||||||
}
|
}
|
||||||
proDlg.setLabelText(tr("Fetching image: %1").arg(urlToDisplay));
|
proDlg.setLabelText(tr("Fetching image: %1").arg(urlToDisplay));
|
||||||
|
|
||||||
|
// Handle equation from zhihu.com like http://www.zhihu.com/equation?tex=P.
|
||||||
|
if (zhihuRegExp.indexIn(imageUrl) != -1) {
|
||||||
|
QString tex = zhihuRegExp.cap(1).trimmed();
|
||||||
|
|
||||||
|
// Remove the +.
|
||||||
|
tex.replace(QChar('+'), " ");
|
||||||
|
|
||||||
|
tex = QUrl::fromPercentEncoding(tex.toUtf8());
|
||||||
|
if (tex.isEmpty()) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
tex = "$" + tex + "$";
|
||||||
|
p_text.replace(reg.m_startPos,
|
||||||
|
reg.m_endPos - reg.m_startPos,
|
||||||
|
tex);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QString destImagePath, urlInLink;
|
QString destImagePath, urlInLink;
|
||||||
|
|
||||||
// Only handle absolute file path or network path.
|
// Only handle absolute file path or network path.
|
||||||
@ -2119,8 +2140,6 @@ void VMdEditor::replaceTextWithLocalImages(QString &p_text)
|
|||||||
p_text.replace(reg.m_startPos,
|
p_text.replace(reg.m_startPos,
|
||||||
reg.m_endPos - reg.m_startPos,
|
reg.m_endPos - reg.m_startPos,
|
||||||
newLink);
|
newLink);
|
||||||
|
|
||||||
qDebug() << "replace link" << linkText << "to" << newLink;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
proDlg.setValue(regs.size());
|
proDlg.setValue(regs.size());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user