Commit 36ec0c1d authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Use correct engine

parent a776d7e0
...@@ -18,7 +18,14 @@ if (Qt5Widgets_VERSION VERSION_LESS 5.14.0) ...@@ -18,7 +18,14 @@ if (Qt5Widgets_VERSION VERSION_LESS 5.14.0)
message(STATUS "Markdown plugin not supported before qt 5.14.0") message(STATUS "Markdown plugin not supported before qt 5.14.0")
endif() endif()
else() else()
set(USE_DISCOUNT_LIB FALSE) option(FORCE_DISCOUNT_LIB "Force using discount lib for markdown bodyformatter." FALSE)
MESSAGE(STATUS "build bodyparformatter mardown with QTextDocument support") if (FORCE_DISCOUNT_LIB AND discount_FOUND)
add_subdirectory(markdown) set(USE_DISCOUNT_LIB TRUE)
MESSAGE(STATUS "build bodyparformatter mardown with discount support")
add_subdirectory(markdown)
else()
set(USE_DISCOUNT_LIB FALSE)
MESSAGE(STATUS "build bodyparformatter mardown with QTextDocument support")
add_subdirectory(markdown)
endif()
endif() endif()
set(mardown_engine_SRCS) set(mardown_engine_SRCS)
set(discount_LIB) set(discount_LIB)
if(USE_DISCOUNT_LIB) if(USE_DISCOUNT_LIB)
add_definitions(-DUSE_DISCOUNT_LIB)
set(mardown_engine_SRCS mardowndiscount.cpp) set(mardown_engine_SRCS mardowndiscount.cpp)
set(discount_LIB discount::Lib) set(discount_LIB discount::Lib)
else() else()
......
...@@ -39,8 +39,6 @@ QString MardownDiscount::toHtml() const ...@@ -39,8 +39,6 @@ QString MardownDiscount::toHtml() const
return {}; return {};
} }
const QByteArray textArray = mText.toUtf8(); const QByteArray textArray = mText.toUtf8();
qDebug( ) << "textArray" << textArray;
MMIOT *markdownHandle = mkd_string(textArray.constData(), textArray.count(), 0); MMIOT *markdownHandle = mkd_string(textArray.constData(), textArray.count(), 0);
mkd_flag_t flags = MKD_FENCEDCODE | MKD_GITHUBTAGS | MKD_AUTOLINK; mkd_flag_t flags = MKD_FENCEDCODE | MKD_GITHUBTAGS | MKD_AUTOLINK;
if (!mkd_compile(markdownHandle, flags)) { if (!mkd_compile(markdownHandle, flags)) {
......
...@@ -23,7 +23,12 @@ ...@@ -23,7 +23,12 @@
#include <MimeTreeParser/MessagePart> #include <MimeTreeParser/MessagePart>
#include <MessageViewer/HtmlWriter> #include <MessageViewer/HtmlWriter>
#include "markdownabstract.h"
#ifdef USE_DISCOUNT_LIB
#include "mardowndiscount.h"
#else
#include "mardownqtextdocument.h"
#endif
#include <grantlee/template.h> #include <grantlee/template.h>
#include <QTextDocument> #include <QTextDocument>
...@@ -56,9 +61,16 @@ public: ...@@ -56,9 +61,16 @@ public:
c.insert(QStringLiteral("block"), msgPart.data()); c.insert(QStringLiteral("block"), msgPart.data());
c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart()); c.insert(QStringLiteral("showOnlyOneMimePart"), context->showOnlyOneMimePart());
c.insert(QStringLiteral("content"), QVariant::fromValue<MessageViewer::GrantleeCallback>([=](Grantlee::OutputStream *) { c.insert(QStringLiteral("content"), QVariant::fromValue<MessageViewer::GrantleeCallback>([=](Grantlee::OutputStream *) {
QTextDocument textDocument; QString result;
textDocument.setMarkdown(msgPart->text(), QTextDocument::MarkdownNoHTML); #ifdef USE_DISCOUNT_LIB
const QString result = textDocument.toHtml(); MardownDiscount engine;
engine.setText(msgPart->text());
result = engine.toHtml();
#else
MardownQTextDocument engine;
engine.setText(msgPart->text());
result = engine.toHtml();
#endif
(*htmlWriter->stream()) << result; (*htmlWriter->stream()) << result;
})); }));
auto t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html")); auto t = MessageViewer::MessagePartRendererManager::self()->loadByName(QStringLiteral("textmessagepart.html"));
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment