diff --git a/resources/template.html b/resources/template.html index 14a3af1e..2e169414 100644 --- a/resources/template.html +++ b/resources/template.html @@ -2,9 +2,9 @@
- - - + + + diff --git a/veditor.cpp b/veditor.cpp index dc2de4c7..65e3509e 100644 --- a/veditor.cpp +++ b/veditor.cpp @@ -169,7 +169,7 @@ void VEditor::setupMarkdownPreview() QWebChannel *channel = new QWebChannel(this); channel->registerObject(QStringLiteral("content"), &document); page->setWebChannel(channel); - webPreviewer->setUrl(QUrl(VNote::templateUrl)); + webPreviewer->setHtml(VNote::templateHtml, QUrl::fromLocalFile(noteFile->path + QDir::separator())); addWidget(webPreviewer); } diff --git a/vnote.cpp b/vnote.cpp index 8d5ead69..1254dde3 100644 --- a/vnote.cpp +++ b/vnote.cpp @@ -8,11 +8,22 @@ const QString VNote::appName = QString("VNote"); const QString VNote::welcomePagePath = QString(":/resources/welcome.html"); const QString VNote::preTemplatePath = QString(":/resources/pre_template.html"); const QString VNote::postTemplatePath = QString(":/resources/post_template.html"); -const QString VNote::templateUrl = QString("qrc:/resources/template.html"); +const QString VNote::templatePath = QString(":/resources/template.html"); +const QString VNote::defaultCssUrl = QString("qrc:/resources/markdown.css"); + +QString VNote::templateHtml; +QString VNote::cssUrl = VNote::defaultCssUrl; VNote::VNote() : curNotebookIndex(0) { + decorateTemplate(); +} + +void VNote::decorateTemplate() +{ + templateHtml = VUtils::readFileFromDisk(templatePath); + templateHtml.replace("CSS_PLACE_HOLDER", cssUrl); } void VNote::readGlobalConfig() diff --git a/vnote.h b/vnote.h index 0b464aba..bc38aba8 100644 --- a/vnote.h +++ b/vnote.h @@ -17,10 +17,14 @@ public: int getCurNotebookIndex() const; void setCurNotebookIndex(int index); + static void decorateTemplate(); + static const QString orgName; static const QString appName; static const QString welcomePagePath; - static const QString templateUrl; + static const QString templatePath; + + static QString templateHtml; private: // Write notebooks section of global config @@ -32,6 +36,10 @@ private: int curNotebookIndex; static const QString preTemplatePath; static const QString postTemplatePath; + static const QString defaultCssUrl; + + // For self CSS definition + static QString cssUrl; }; #endif // VNOTE_H