mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-07-22 22:21:09 -04:00
Add CommonMark in ChatLobbyDialog
This commit is contained in:
parent
82c9084ca4
commit
d03ee1c0b0
26 changed files with 318 additions and 58 deletions
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue