Browse Source

MathJaxPreview: fix preview while using local mathjax

Le Tan 7 years ago
parent
commit
22489137ae

+ 1 - 0
src/dialog/vsettingsdialog.cpp

@@ -1041,6 +1041,7 @@ VMarkdownTab::VMarkdownTab(QWidget *p_parent)
     m_mathjaxConfigEdit = new VLineEdit();
     m_mathjaxConfigEdit->setToolTip(tr("Location of MathJax JavaScript and its configuration "
                                        "(restart VNote to make it work in in-place preview)"));
+    m_mathjaxConfigEdit->setPlaceholderText(tr("Need to prepend \"file://\" to local path"));
 
     // PlantUML.
     m_plantUMLModeCombo = VUtils::getComboBox();

+ 2 - 1
src/utils/vutils.cpp

@@ -908,8 +908,9 @@ with 2em, if there are Chinese characters in it, the font will be a mess.
 
 QString VUtils::generateMathJaxPreviewTemplate()
 {
+    QString mj = g_config->getMathjaxJavascript();
     QString templ = VNote::generateMathJaxPreviewTemplate();
-    templ.replace(HtmlHolder::c_JSHolder, g_config->getMathjaxJavascript());
+    templ.replace(HtmlHolder::c_JSHolder, mj);
 
     QString extraFile;
 

+ 0 - 1
src/vdocument.cpp

@@ -67,7 +67,6 @@ void VDocument::setHtml(const QString &html)
 void VDocument::setLog(const QString &p_log)
 {
     qDebug() << "JS:" << p_log;
-    emit logChanged(p_log);
 }
 
 void VDocument::keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta)

+ 0 - 2
src/vdocument.h

@@ -139,8 +139,6 @@ signals:
 
     void htmlChanged(const QString &html);
 
-    void logChanged(const QString &p_log);
-
     void keyPressed(int p_key, bool p_ctrl, bool p_shift, bool p_meta);
 
     void requestHighlightText(const QString &p_text, int p_id, unsigned long long p_timeStamp);

+ 5 - 1
src/vmathjaxpreviewhelper.cpp

@@ -5,6 +5,9 @@
 
 #include "utils/vutils.h"
 #include "vmathjaxwebdocument.h"
+#include "vconfigmanager.h"
+
+extern VConfigManager *g_config;
 
 VMathJaxPreviewHelper::VMathJaxPreviewHelper(QWidget *p_parentWidget, QObject *p_parent)
     : QObject(p_parent),
@@ -67,7 +70,8 @@ void VMathJaxPreviewHelper::doInit()
 
     // setHtml() will change focus if it is not disabled.
     m_webView->setEnabled(false);
-    m_webView->setHtml(VUtils::generateMathJaxPreviewTemplate(), QUrl("qrc:/resources"));
+    QUrl baseUrl(QUrl::fromLocalFile(g_config->getDocumentPathOrHomePath() + QDir::separator()));
+    m_webView->setHtml(VUtils::generateMathJaxPreviewTemplate(), baseUrl);
     m_webView->setEnabled(true);
 }
 

+ 8 - 0
src/vmathjaxwebdocument.cpp

@@ -1,5 +1,7 @@
 #include "vmathjaxwebdocument.h"
 
+#include <QDebug>
+
 VMathJaxWebDocument::VMathJaxWebDocument(QObject *p_parent)
     : QObject(p_parent)
 {
@@ -44,3 +46,9 @@ void VMathJaxWebDocument::previewDiagram(int p_identifier,
                                p_lang,
                                p_text);
 }
+
+void VMathJaxWebDocument::setLog(const QString &p_log)
+{
+    qDebug() << "JS:" << p_log;
+}
+

+ 2 - 0
src/vmathjaxwebdocument.h

@@ -38,6 +38,8 @@ public slots:
                             const QString &p_format,
                             const QString &p_data);
 
+    void setLog(const QString &p_log);
+
 signals:
     void requestPreviewMathJax(int p_identifier,
                                int p_id,