mirror of
https://gitee.com/vnotex/vnote.git
synced 2025-07-05 13:59:52 +08:00
support MathJax
Work well with Hoedown and Markdown-it.
This commit is contained in:
parent
b9f8144f29
commit
a9b34955ee
@ -23,5 +23,9 @@ var updateHtml = function(html) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (VEnableMathjax && (typeof MathJax != 'undefined')) {
|
||||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -169,5 +169,8 @@ var updateText = function(text) {
|
||||
placeholder.innerHTML = html;
|
||||
handleToc(needToc);
|
||||
renderMermaid('lang-mermaid');
|
||||
if (VEnableMathjax) {
|
||||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -24,6 +24,10 @@ if (typeof VEnableMermaid == 'undefined') {
|
||||
});
|
||||
}
|
||||
|
||||
if (typeof VEnableMathjax == 'undefined') {
|
||||
VEnableMathjax = false;
|
||||
}
|
||||
|
||||
var scrollToAnchor = function(anchor) {
|
||||
var anc = document.getElementById(anchor);
|
||||
if (anc != null) {
|
||||
|
@ -122,5 +122,8 @@ var updateText = function(text) {
|
||||
placeholder.innerHTML = html;
|
||||
handleToc(needToc);
|
||||
renderMermaid('lang-mermaid');
|
||||
if (VEnableMathjax) {
|
||||
MathJax.Hub.Queue(["Typeset", MathJax.Hub, placeholder]);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -14,6 +14,7 @@ editor_font_size=12
|
||||
; 0 - Hoedown, 1 - Marked, 2 - Markdown-it
|
||||
markdown_converter=2
|
||||
enable_mermaid=true
|
||||
enable_mathjax=true
|
||||
|
||||
[session]
|
||||
tools_dock_checked=true
|
||||
|
@ -49,7 +49,7 @@ void VConfigManager::initialize()
|
||||
|
||||
markdownExtensions = hoedown_extensions(HOEDOWN_EXT_TABLES | HOEDOWN_EXT_FENCED_CODE |
|
||||
HOEDOWN_EXT_HIGHLIGHT | HOEDOWN_EXT_AUTOLINK |
|
||||
HOEDOWN_EXT_QUOTE | HOEDOWN_EXT_MATH);
|
||||
HOEDOWN_EXT_QUOTE | HOEDOWN_EXT_MATH | HOEDOWN_EXT_MATH_EXPLICIT);
|
||||
mdConverterType = (MarkdownConverterType)getConfigFromSettings("global", "markdown_converter").toInt();
|
||||
|
||||
tabStopWidth = getConfigFromSettings("global", "tab_stop_width").toInt();
|
||||
@ -85,6 +85,8 @@ void VConfigManager::initialize()
|
||||
m_language = getConfigFromSettings("global", "language").toString();
|
||||
|
||||
m_enableMermaid = getConfigFromSettings("global", "enable_mermaid").toBool();
|
||||
|
||||
m_enableMathjax = getConfigFromSettings("global", "enable_mathjax").toBool();
|
||||
}
|
||||
|
||||
void VConfigManager::readPredefinedColorsFromSettings()
|
||||
|
@ -120,6 +120,9 @@ public:
|
||||
inline bool getEnableMermaid() const;
|
||||
inline void setEnableMermaid(bool p_enabled);
|
||||
|
||||
inline bool getEnableMathjax() const;
|
||||
inline void setEnableMathjax(bool p_enabled);
|
||||
|
||||
private:
|
||||
void updateMarkdownEditStyle();
|
||||
QVariant getConfigFromSettings(const QString §ion, const QString &key);
|
||||
@ -181,6 +184,9 @@ private:
|
||||
// Enable Mermaid.
|
||||
bool m_enableMermaid;
|
||||
|
||||
// Enable Mathjax.
|
||||
bool m_enableMathjax;
|
||||
|
||||
// The name of the config file in each directory
|
||||
static const QString dirConfigFileName;
|
||||
// The name of the default configuration file
|
||||
@ -512,4 +518,18 @@ inline void VConfigManager::setEnableMermaid(bool p_enabled)
|
||||
setConfigToSettings("global", "enable_mermaid", m_enableMermaid);
|
||||
}
|
||||
|
||||
inline bool VConfigManager::getEnableMathjax() const
|
||||
{
|
||||
return m_enableMathjax;
|
||||
}
|
||||
|
||||
inline void VConfigManager::setEnableMathjax(bool p_enabled)
|
||||
{
|
||||
if (m_enableMathjax == p_enabled) {
|
||||
return;
|
||||
}
|
||||
m_enableMathjax = p_enabled;
|
||||
setConfigToSettings("global", "enable_mathjax", m_enableMathjax);
|
||||
}
|
||||
|
||||
#endif // VCONFIGMANAGER_H
|
||||
|
@ -304,6 +304,17 @@ void VEditTab::setupMarkdownPreview()
|
||||
"<script>var VEnableMermaid = true;</script>\n";
|
||||
}
|
||||
|
||||
if (vconfig.getEnableMathjax()) {
|
||||
extraFile += "<script type=\"text/x-mathjax-config\">"
|
||||
"MathJax.Hub.Config({\n"
|
||||
" tex2jax: {inlineMath: [['$','$'], ['\\\\(','\\\\)']]},\n"
|
||||
" showProcessingMessages: false,\n"
|
||||
" messageStyle: \"none\"});\n"
|
||||
"</script>\n"
|
||||
"<script type=\"text/javascript\" async src=\"" + VNote::c_mathjaxJsFile + "\"></script>\n" +
|
||||
"<script>var VEnableMathjax = true;</script>\n";
|
||||
}
|
||||
|
||||
QString htmlTemplate = VNote::s_markdownTemplate;
|
||||
htmlTemplate.replace(jsHolder, jsFile);
|
||||
if (!extraFile.isEmpty()) {
|
||||
|
@ -330,6 +330,15 @@ void VMainWindow::initMarkdownMenu()
|
||||
markdownMenu->addAction(mermaidAct);
|
||||
|
||||
mermaidAct->setChecked(vconfig.getEnableMermaid());
|
||||
|
||||
QAction *mathjaxAct = new QAction(tr("Math&jax"), this);
|
||||
mathjaxAct->setStatusTip(tr("Enable Mathjax for math support in Markdown"));
|
||||
mathjaxAct->setCheckable(true);
|
||||
connect(mathjaxAct, &QAction::triggered,
|
||||
this, &VMainWindow::enableMathjax);
|
||||
markdownMenu->addAction(mathjaxAct);
|
||||
|
||||
mathjaxAct->setChecked(vconfig.getEnableMathjax());
|
||||
}
|
||||
|
||||
void VMainWindow::initViewMenu()
|
||||
@ -607,6 +616,11 @@ void VMainWindow::enableMermaid(bool p_checked)
|
||||
vconfig.setEnableMermaid(p_checked);
|
||||
}
|
||||
|
||||
void VMainWindow::enableMathjax(bool p_checked)
|
||||
{
|
||||
vconfig.setEnableMathjax(p_checked);
|
||||
}
|
||||
|
||||
void VMainWindow::changeHighlightCursorLine(bool p_checked)
|
||||
{
|
||||
vconfig.setHighlightCursorLine(p_checked);
|
||||
|
@ -62,6 +62,7 @@ private slots:
|
||||
void handleFindDialogTextChanged(const QString &p_text, uint p_options);
|
||||
void openFindDialog();
|
||||
void enableMermaid(bool p_checked);
|
||||
void enableMathjax(bool p_checked);
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent *event) Q_DECL_OVERRIDE;
|
||||
|
@ -22,6 +22,7 @@ const QString VNote::c_mermaidApiJsFile = ":/utils/mermaid/mermaidAPI.min.js";
|
||||
const QString VNote::c_mermaidCssFile = ":/utils/mermaid/mermaid.css";
|
||||
const QString VNote::c_mermaidDarkCssFile = ":/utils/mermaid/mermaid.dark.css";
|
||||
const QString VNote::c_mermaidForestCssFile = ":/utils/mermaid/mermaid.forest.css";
|
||||
const QString VNote::c_mathjaxJsFile = "https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML";
|
||||
|
||||
VNote::VNote(QObject *parent)
|
||||
: QObject(parent), m_mainWindow(dynamic_cast<VMainWindow *>(parent))
|
||||
|
@ -46,6 +46,9 @@ public:
|
||||
static const QString c_mermaidDarkCssFile;
|
||||
static const QString c_mermaidForestCssFile;
|
||||
|
||||
// Mathjax
|
||||
static const QString c_mathjaxJsFile;
|
||||
|
||||
inline const QVector<QPair<QString, QString> > &getPalette() const;
|
||||
void initPalette(QPalette palette);
|
||||
QString getColorFromPalette(const QString &p_name) const;
|
||||
|
Loading…
x
Reference in New Issue
Block a user