MathJaxPreview: fix preview while using local mathjax

This commit is contained in:
Le Tan 2018-09-01 11:05:03 +08:00
parent b49d5a968f
commit 22489137ae
7 changed files with 18 additions and 5 deletions

View File

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

View File

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

View File

@ -67,7 +67,6 @@ void VDocument::setHtml(const QString &html)
void VDocument::setLog(const QString &p_log) void VDocument::setLog(const QString &p_log)
{ {
qDebug() << "JS:" << 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) void VDocument::keyPressEvent(int p_key, bool p_ctrl, bool p_shift, bool p_meta)

View File

@ -139,8 +139,6 @@ signals:
void htmlChanged(const QString &html); 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 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); void requestHighlightText(const QString &p_text, int p_id, unsigned long long p_timeStamp);

View File

@ -5,6 +5,9 @@
#include "utils/vutils.h" #include "utils/vutils.h"
#include "vmathjaxwebdocument.h" #include "vmathjaxwebdocument.h"
#include "vconfigmanager.h"
extern VConfigManager *g_config;
VMathJaxPreviewHelper::VMathJaxPreviewHelper(QWidget *p_parentWidget, QObject *p_parent) VMathJaxPreviewHelper::VMathJaxPreviewHelper(QWidget *p_parentWidget, QObject *p_parent)
: QObject(p_parent), : QObject(p_parent),
@ -67,7 +70,8 @@ void VMathJaxPreviewHelper::doInit()
// setHtml() will change focus if it is not disabled. // setHtml() will change focus if it is not disabled.
m_webView->setEnabled(false); 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); m_webView->setEnabled(true);
} }

View File

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

View File

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