Add CommonMark in ChatLobbyDialog

This commit is contained in:
Phenom 2017-08-19 19:18:58 +02:00
parent 82c9084ca4
commit d03ee1c0b0
26 changed files with 318 additions and 58 deletions

View file

@ -38,6 +38,10 @@
#include "util/imageutil.h"
#include "util/rstime.h"
//Include for CMark
#include <gui/../../../supportlibs/cmark/src/cmark.h>
#include <gui/../../../supportlibs/cmark/src/node.h>
#include <iostream>
/**
@ -582,6 +586,29 @@ QString RsHtml::formatText(QTextDocument *textDocument, const QString &text, ulo
// Save Space and Tab because doc loose it.
formattedText=saveSpace(formattedText);
if (flag & RSHTML_FORMATTEXT_USE_CMARK) {
// Transform html to plain text
QTextBrowser textBrowser;
textBrowser.setHtml(text);
formattedText = textBrowser.toPlainText();
// Parse CommonMark
int options = CMARK_OPT_DEFAULT;
cmark_parser *parser = cmark_parser_new(options);
cmark_parser_feed(parser, formattedText.toStdString().c_str(),formattedText.length());
cmark_node *document = cmark_parser_finish(parser);
cmark_parser_free(parser);
char *result;
result = cmark_render_html(document, options);
// Get result as html
formattedText = QString::fromUtf8(result);
//Clean
cmark_node_mem(document)->free(result);
cmark_node_free(document);
//Get document formed HTML
textBrowser.setHtml(formattedText);
formattedText=textBrowser.toHtml();
}
QString errorMsg; int errorLine; int errorColumn;
QDomDocument doc;
@ -981,6 +1008,12 @@ static void styleCreate(QDomDocument& doc
noEmbedAttr.setValue("true");
styleElem.attributes().setNamedItem(noEmbedAttr);
}
if (flag & RSHTML_FORMATTEXT_USE_CMARK) {
QDomAttr cMarkAttr;
cMarkAttr = doc.createAttribute("CMark");
cMarkAttr.setValue("true");
styleElem.attributes().setNamedItem(cMarkAttr);
}
}
while(styleElem.childNodes().count()>0) {