diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..f7f9e74a2 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cmark"] + path = supportlibs/cmark + url = https://github.com/commonmark/cmark.git diff --git a/appveyor.yml b/appveyor.yml index 6f26a1c67..7c13becb2 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -85,6 +85,7 @@ environment: # - cmd: echo This is batch again # - cmd: set MY_VAR=12345 install: + - git submodule update --init # Configuring MSys2 - set PATH=C:\msys64\usr\bin;%PATH% - set PATH=C:\msys64\mingw32\bin;%PATH% diff --git a/retroshare-gui/src/cmark_export.h b/retroshare-gui/src/cmark_export.h new file mode 100644 index 000000000..333e5d542 --- /dev/null +++ b/retroshare-gui/src/cmark_export.h @@ -0,0 +1,42 @@ + +#ifndef CMARK_EXPORT_H +#define CMARK_EXPORT_H + +#ifdef CMARK_STATIC_DEFINE +# define CMARK_EXPORT +# define CMARK_NO_EXPORT +#else +# ifndef CMARK_EXPORT +# ifdef libcmark_EXPORTS + /* We are building this library */ +# define CMARK_EXPORT __attribute__((visibility("default"))) +# else + /* We are using this library */ +# define CMARK_EXPORT __attribute__((visibility("default"))) +# endif +# endif + +# ifndef CMARK_NO_EXPORT +# define CMARK_NO_EXPORT __attribute__((visibility("hidden"))) +# endif +#endif + +#ifndef CMARK_DEPRECATED +# define CMARK_DEPRECATED __attribute__ ((__deprecated__)) +#endif + +#ifndef CMARK_DEPRECATED_EXPORT +# define CMARK_DEPRECATED_EXPORT CMARK_EXPORT CMARK_DEPRECATED +#endif + +#ifndef CMARK_DEPRECATED_NO_EXPORT +# define CMARK_DEPRECATED_NO_EXPORT CMARK_NO_EXPORT CMARK_DEPRECATED +#endif + +#if 0 /* DEFINE_NO_DEPRECATED */ +# ifndef CMARK_NO_DEPRECATED +# define CMARK_NO_DEPRECATED +# endif +#endif + +#endif diff --git a/retroshare-gui/src/cmark_version.h b/retroshare-gui/src/cmark_version.h new file mode 100644 index 000000000..c6fe002fb --- /dev/null +++ b/retroshare-gui/src/cmark_version.h @@ -0,0 +1,7 @@ +#ifndef CMARK_VERSION_H +#define CMARK_VERSION_H + +#define CMARK_VERSION ((0 << 16) | (28 << 8) | 0) +#define CMARK_VERSION_STRING "0.28.0" + +#endif diff --git a/retroshare-gui/src/config.h b/retroshare-gui/src/config.h new file mode 100644 index 000000000..d38c7c7a5 --- /dev/null +++ b/retroshare-gui/src/config.h @@ -0,0 +1,76 @@ +#ifndef CMARK_CONFIG_H +#define CMARK_CONFIG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define HAVE_STDBOOL_H + +#ifdef HAVE_STDBOOL_H + #include +#elif !defined(__cplusplus) + typedef char bool; +#endif + +#define HAVE___BUILTIN_EXPECT + +#define HAVE___ATTRIBUTE__ + +#ifdef HAVE___ATTRIBUTE__ + #define CMARK_ATTRIBUTE(list) __attribute__ (list) +#else + #define CMARK_ATTRIBUTE(list) +#endif + +#ifndef CMARK_INLINE + #if defined(_MSC_VER) && !defined(__cplusplus) + #define CMARK_INLINE __inline + #else + #define CMARK_INLINE inline + #endif +#endif + +/* snprintf and vsnprintf fallbacks for MSVC before 2015, + due to Valentin Milea http://stackoverflow.com/questions/2915672/ +*/ + +#if defined(_MSC_VER) && _MSC_VER < 1900 + +#include +#include + +#define snprintf c99_snprintf +#define vsnprintf c99_vsnprintf + +CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap) +{ + int count = -1; + + if (size != 0) + count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap); + if (count == -1) + count = _vscprintf(format, ap); + + return count; +} + +CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...) +{ + int count; + va_list ap; + + va_start(ap, format); + count = c99_vsnprintf(outBuf, size, format, ap); + va_end(ap); + + return count; +} + +#endif + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/retroshare-gui/src/gui/NetworkView.cpp b/retroshare-gui/src/gui/NetworkView.cpp index 44c99736d..d0e486293 100644 --- a/retroshare-gui/src/gui/NetworkView.cpp +++ b/retroshare-gui/src/gui/NetworkView.cpp @@ -28,7 +28,7 @@ #include #include -#include "gui/elastic/node.h" +#include "gui/elastic/elnode.h" /******** * #define DEBUG_NETWORKVIEW diff --git a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp index 35a6f0f54..3d98a4b62 100644 --- a/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp +++ b/retroshare-gui/src/gui/chat/ChatLobbyDialog.cpp @@ -34,7 +34,7 @@ #include "gui/FriendsDialog.h" #include "gui/MainWindow.h" #include "gui/chat/ChatWidget.h" -#include "gui/common/html.h" +#include "gui/common/rshtml.h" #include "gui/common/FriendSelectionDialog.h" #include "gui/common/RSTreeWidgetItem.h" #include "gui/gxs/GxsIdChooser.h" diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index f35c0425d..4d7c42a66 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -72,8 +72,15 @@ * #define CHAT_DEBUG 1 *****/ -ChatWidget::ChatWidget(QWidget *parent) : - QWidget(parent), sendingBlocked(false), ui(new Ui::ChatWidget) +ChatWidget::ChatWidget(QWidget *parent) + : QWidget(parent) + , completionPosition(0), newMessages(false), typing(false), peerStatus(0) + , sendingBlocked(false), useCMark(false) + , lastStatusSendTime(0) + , firstShow(true), inChatCharFormatChanged(false), firstSearch(true) + , lastUpdateCursorPos(0), lastUpdateCursorEnd(0) + , completer(NULL), notify(NULL) + , ui(new Ui::ChatWidget) { ui->setupUi(this); @@ -84,17 +91,8 @@ ChatWidget::ChatWidget(QWidget *parent) : int butt_size(iconSize.height() + fmm); QSize buttonSize = QSize(butt_size, butt_size); - newMessages = false; - typing = false; - peerStatus = 0; - firstShow = true; - firstSearch = true; - inChatCharFormatChanged = false; - completer = NULL; lastMsgDate = QDate::currentDate(); - lastStatusSendTime = 0 ; - //Resize Tool buttons ui->emoteiconButton->setFixedSize(buttonSize); ui->emoteiconButton->setIconSize(iconSize); @@ -144,7 +142,6 @@ ChatWidget::ChatWidget(QWidget *parent) : connect(ui->actionSearchWithoutLimit, SIGNAL(triggered()), this, SLOT(toogle_SeachWithoutLimit())); connect(ui->searchButton, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuSearchButton(QPoint))); - notify=NULL; ui->notifyButton->setVisible(false); ui->markButton->setToolTip(tr("Mark this selected text
Ctrl+M")); @@ -194,6 +191,7 @@ ChatWidget::ChatWidget(QWidget *parent) : fontmenu->addAction(ui->actionResetFont); fontmenu->addAction(ui->actionNoEmbed); fontmenu->addAction(ui->actionSendAsPlainText); + fontmenu->addAction(ui->actionSend_as_CommonMark); QMenu *menu = new QMenu(); menu->addAction(ui->actionClearChatHistory); @@ -207,6 +205,10 @@ ChatWidget::ChatWidget(QWidget *parent) : ui->chatTextEdit->setOnlyPlainText(ui->actionSendAsPlainText->isChecked()); connect(ui->actionSendAsPlainText, SIGNAL(toggled(bool)), ui->chatTextEdit, SLOT(setOnlyPlainText(bool)) ); + connect(ui->actionSend_as_CommonMark, SIGNAL(toggled(bool)), this, SLOT(setUseCMark(bool)) ); + ui->cmPreview->setVisible(false); + connect(ui->chatTextEdit, SIGNAL(textChanged()), this, SLOT(updateCMPreview()) ); + ui->textBrowser->resetImagesStatus(Settings->getChatLoadEmbeddedImages()); ui->textBrowser->installEventFilter(this); ui->textBrowser->viewport()->installEventFilter(this); @@ -981,6 +983,11 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx formatTextFlag |= RSHTML_FORMATTEXT_EMBED_SMILEYS; } + //Use CommonMark + if (message.contains("CMark=\"true\"")) { + formatTextFlag |= RSHTML_FORMATTEXT_USE_CMARK; + } + // Always fix colors formatTextFlag |= RSHTML_FORMATTEXT_FIX_COLORS; qreal desiredContrast = Settings->valueFromGroup("Chat", "MinimumContrast", 4.5).toDouble(); @@ -1229,7 +1236,9 @@ void ChatWidget::sendChat() text = chatWidget->toPlainText(); text.replace(QChar(-4),"");//Char used when image on text. } else { - RsHtml::optimizeHtml(chatWidget, text, (ui->actionNoEmbed->isChecked() ? RSHTML_FORMATTEXT_NO_EMBED : 0)); + RsHtml::optimizeHtml(chatWidget, text, + (ui->actionNoEmbed->isChecked() ? RSHTML_FORMATTEXT_NO_EMBED : 0) + + (ui->actionSend_as_CommonMark->isChecked() ? RSHTML_FORMATTEXT_USE_CMARK : 0) ); } std::string msg = text.toUtf8().constData(); @@ -1823,6 +1832,22 @@ bool ChatWidget::setStyle() return false; } +void ChatWidget::setUseCMark(const bool bUseCMark) +{ + useCMark = bUseCMark; + ui->cmPreview->setVisible(useCMark); + updateCMPreview(); +} + +void ChatWidget::updateCMPreview() +{ + if (!useCMark) return; + + QString message = ui->chatTextEdit->toHtml(); + QString formattedMessage = RsHtml().formatText(ui->cmPreview->document(), message, RSHTML_FORMATTEXT_USE_CMARK); + ui->cmPreview->setHtml(formattedMessage); +} + void ChatWidget::quote() { QString text = ui->textBrowser->textCursor().selection().toPlainText(); diff --git a/retroshare-gui/src/gui/chat/ChatWidget.h b/retroshare-gui/src/gui/chat/ChatWidget.h index 8de38620e..127575d73 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.h +++ b/retroshare-gui/src/gui/chat/ChatWidget.h @@ -128,6 +128,8 @@ public: public slots: void updateStatus(const QString &peer_id, int status); + void setUseCMark(const bool bUseCMark); + void updateCMPreview(); private slots: //void pasteCreateMsgLink() ; @@ -222,7 +224,8 @@ private: bool typing; int peerStatus; - bool sendingBlocked; + bool sendingBlocked; + bool useCMark; time_t lastStatusSendTime; diff --git a/retroshare-gui/src/gui/chat/ChatWidget.ui b/retroshare-gui/src/gui/chat/ChatWidget.ui index 9ea7277ef..16a411eb5 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.ui +++ b/retroshare-gui/src/gui/chat/ChatWidget.ui @@ -268,22 +268,34 @@ border-image: url(:/images/closepressed.png) - - - - 0 - 0 - + + + Qt::Horizontal - - - 0 - 30 - + + 2 - - Type a message here + + false + + + + 0 + 0 + + + + + 0 + 30 + + + + Type a message here + + + @@ -915,6 +927,21 @@ border-image: url(:/images/closepressed.png) Show Hidden Images + + + true + + + + :/icons/png/markdown-mark.png:/icons/png/markdown-mark.png + + + Send as CommonMark + + + Text will be formatted using CommonMark. + + @@ -945,8 +972,8 @@ border-image: url(:/images/closepressed.png) - + diff --git a/retroshare-gui/src/gui/common/html.cpp b/retroshare-gui/src/gui/common/rshtml.cpp similarity index 95% rename from retroshare-gui/src/gui/common/html.cpp rename to retroshare-gui/src/gui/common/rshtml.cpp index ce71518f9..e0a1cdaf6 100644 --- a/retroshare-gui/src/gui/common/html.cpp +++ b/retroshare-gui/src/gui/common/rshtml.cpp @@ -1,7 +1,7 @@ /**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2008, defnax + * This file is distributed under the following license: + * + * Copyright (c) 2008, defnax * Copyright (c) 2008, Matt Edman, Justin Hipple * * This program is free software; you can redistribute it and/or @@ -21,12 +21,12 @@ ****************************************************************/ /* -** \file html.cpp -** \version $Id: html.cpp 2362 2008-02-29 04:30:11Z edmanm $ +** \file rshtml.cpp +** \version $Id: rshtml.cpp 2362 2008-02-29 04:30:11Z edmanm $ ** \brief HTML formatting functions */ -#include "html.h" +#include "rshtml.h" /** Wraps a string in "

" tags, converts "\n" to "
" and converts "\n\n" diff --git a/retroshare-gui/src/gui/common/html.h b/retroshare-gui/src/gui/common/rshtml.h similarity index 95% rename from retroshare-gui/src/gui/common/html.h rename to retroshare-gui/src/gui/common/rshtml.h index bb217d220..627b81a59 100644 --- a/retroshare-gui/src/gui/common/html.h +++ b/retroshare-gui/src/gui/common/rshtml.h @@ -1,7 +1,7 @@ /**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2008, defnax + * This file is distributed under the following license: + * + * Copyright (c) 2008, defnax * Copyright (c) 2008, Matt Edman, Justin Hipple * * This program is free software; you can redistribute it and/or @@ -21,8 +21,8 @@ ****************************************************************/ /* -** \file html.h -** \version $Id: html.h 2362 2008-02-29 04:30:11Z edmanm $ +** \file rshtml.h +** \version $Id: rshtml.h 2362 2008-02-29 04:30:11Z edmanm $ ** \brief HTML formatting functions */ diff --git a/retroshare-gui/src/gui/common/vmessagebox.cpp b/retroshare-gui/src/gui/common/vmessagebox.cpp index 933310acd..f1465fa4f 100644 --- a/retroshare-gui/src/gui/common/vmessagebox.cpp +++ b/retroshare-gui/src/gui/common/vmessagebox.cpp @@ -1,7 +1,7 @@ /**************************************************************** - * This file is distributed under the following license: - * - * Copyright (c) 2008, defnax + * This file is distributed under the following license: + * + * Copyright (c) 2008, defnax * Copyright (c) 2008, Matt Edman, Justin Hipple * * This program is free software; you can redistribute it and/or @@ -26,7 +26,7 @@ ** \brief Provides a custom Vidalia mesage box */ -#include "html.h" +#include "rshtml.h" #include "vmessagebox.h" diff --git a/retroshare-gui/src/gui/elastic/arrow.cpp b/retroshare-gui/src/gui/elastic/arrow.cpp index 8ef0991d4..f9fc8a95b 100644 --- a/retroshare-gui/src/gui/elastic/arrow.cpp +++ b/retroshare-gui/src/gui/elastic/arrow.cpp @@ -37,7 +37,7 @@ #include #include "arrow.h" -#include "node.h" +#include "elnode.h" #include diff --git a/retroshare-gui/src/gui/elastic/edge.cpp b/retroshare-gui/src/gui/elastic/edge.cpp index e9e60f06b..cee1e1e88 100644 --- a/retroshare-gui/src/gui/elastic/edge.cpp +++ b/retroshare-gui/src/gui/elastic/edge.cpp @@ -42,7 +42,7 @@ #include #include "edge.h" -#include "node.h" +#include "elnode.h" #include diff --git a/retroshare-gui/src/gui/elastic/node.cpp b/retroshare-gui/src/gui/elastic/elnode.cpp similarity index 96% rename from retroshare-gui/src/gui/elastic/node.cpp rename to retroshare-gui/src/gui/elastic/elnode.cpp index 6a3020b21..99bbfd310 100644 --- a/retroshare-gui/src/gui/elastic/node.cpp +++ b/retroshare-gui/src/gui/elastic/elnode.cpp @@ -54,7 +54,7 @@ #include #include "edge.h" -#include "node.h" +#include "elnode.h" #include "graphwidget.h" #define IMAGE_AUTHED ":/images/accepted16.png" diff --git a/retroshare-gui/src/gui/elastic/node.h b/retroshare-gui/src/gui/elastic/elnode.h similarity index 96% rename from retroshare-gui/src/gui/elastic/node.h rename to retroshare-gui/src/gui/elastic/elnode.h index e43fa3521..6e59cf43d 100644 --- a/retroshare-gui/src/gui/elastic/node.h +++ b/retroshare-gui/src/gui/elastic/elnode.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef NODE_H -#define NODE_H +#ifndef ELNODE_H +#define ELNODE_H #include #if QT_VERSION >= 0x040600 diff --git a/retroshare-gui/src/gui/elastic/graphwidget.cpp b/retroshare-gui/src/gui/elastic/graphwidget.cpp index 9aeebbeda..aa8cbf241 100644 --- a/retroshare-gui/src/gui/elastic/graphwidget.cpp +++ b/retroshare-gui/src/gui/elastic/graphwidget.cpp @@ -41,7 +41,7 @@ #include "graphwidget.h" #include "edge.h" -#include "node.h" +#include "elnode.h" #include "fft.h" #include diff --git a/retroshare-gui/src/gui/help/browser/helptextbrowser.cpp b/retroshare-gui/src/gui/help/browser/helptextbrowser.cpp index 60d4ed427..f6b445e1c 100644 --- a/retroshare-gui/src/gui/help/browser/helptextbrowser.cpp +++ b/retroshare-gui/src/gui/help/browser/helptextbrowser.cpp @@ -30,7 +30,7 @@ #include #include #include "gui/common/vmessagebox.h" -#include "gui/common/html.h" +#include "gui/common/rshtml.h" #include #include "helptextbrowser.h" diff --git a/retroshare-gui/src/gui/icons.qrc b/retroshare-gui/src/gui/icons.qrc index aab1afb40..31e3f816a 100644 --- a/retroshare-gui/src/gui/icons.qrc +++ b/retroshare-gui/src/gui/icons.qrc @@ -241,5 +241,6 @@ icons/warning_yellow_128.png icons/yahoo.png icons/yandex.png + icons/png/markdown-mark.png diff --git a/retroshare-gui/src/gui/icons/png/markdown-mark.png b/retroshare-gui/src/gui/icons/png/markdown-mark.png new file mode 100644 index 000000000..da4bb7123 Binary files /dev/null and b/retroshare-gui/src/gui/icons/png/markdown-mark.png differ diff --git a/retroshare-gui/src/retroshare-gui.pro b/retroshare-gui/src/retroshare-gui.pro index 30b2af946..b51139ea4 100644 --- a/retroshare-gui/src/retroshare-gui.pro +++ b/retroshare-gui/src/retroshare-gui.pro @@ -2,7 +2,7 @@ TEMPLATE = app QT += network xml -CONFIG += qt gui uic qrc resources idle +CONFIG += qt gui uic qrc resources idle cmark CONFIG += console TARGET = retroshare DEFINES += TARGET=\\\"$${TARGET}\\\" @@ -478,7 +478,7 @@ HEADERS += rshare.h \ gui/common/RsUrlHandler.h \ gui/common/RsCollectionDialog.h \ gui/common/rwindow.h \ - gui/common/html.h \ + gui/common/rshtml.h \ gui/common/AvatarDefs.h \ gui/common/GroupFlagsWidget.h \ gui/common/GroupSelectionBox.h \ @@ -546,7 +546,7 @@ HEADERS += rshare.h \ gui/elastic/graphwidget.h \ gui/elastic/edge.h \ gui/elastic/arrow.h \ - gui/elastic/node.h \ + gui/elastic/elnode.h \ gui/NewsFeed.h \ gui/feeds/FeedItem.h \ gui/feeds/FeedHolder.h \ @@ -796,7 +796,7 @@ SOURCES += main.cpp \ gui/common/RsCollectionDialog.cpp \ gui/common/RsUrlHandler.cpp \ gui/common/rwindow.cpp \ - gui/common/html.cpp \ + gui/common/rshtml.cpp \ gui/common/AvatarDefs.cpp \ gui/common/AvatarDialog.cpp \ gui/common/GroupFlagsWidget.cpp \ @@ -897,7 +897,7 @@ SOURCES += main.cpp \ gui/elastic/graphwidget.cpp \ gui/elastic/edge.cpp \ gui/elastic/arrow.cpp \ - gui/elastic/node.cpp \ + gui/elastic/elnode.cpp \ gui/NewsFeed.cpp \ gui/feeds/FeedItem.cpp \ gui/feeds/FeedHolder.cpp \ @@ -1369,3 +1369,43 @@ gxsgui { } + +cmark { + + HEADERS += \ + ../../supportlibs/cmark/src/buffer.h \ + ../../supportlibs/cmark/src/chunk.h \ + ../../supportlibs/cmark/src/cmark.h \ + ../../supportlibs/cmark/src/cmark_ctype.h \ + ../../supportlibs/cmark/src/houdini.h \ + ../../supportlibs/cmark/src/inlines.h \ + ../../supportlibs/cmark/src/iterator.h \ + ../../supportlibs/cmark/src/node.h \ + ../../supportlibs/cmark/src/parser.h \ + ../../supportlibs/cmark/src/references.h \ + ../../supportlibs/cmark/src/render.h \ + ../../supportlibs/cmark/src/scanners.h \ + ../../supportlibs/cmark/src/utf8.h \ + + SOURCES += \ + ../../supportlibs/cmark/src/blocks.c \ + ../../supportlibs/cmark/src/buffer.c \ + ../../supportlibs/cmark/src/cmark.c \ + ../../supportlibs/cmark/src/cmark_ctype.c \ + ../../supportlibs/cmark/src/commonmark.c \ + ../../supportlibs/cmark/src/houdini_href_e.c \ + ../../supportlibs/cmark/src/houdini_html_e.c \ + ../../supportlibs/cmark/src/houdini_html_u.c \ + ../../supportlibs/cmark/src/html.c \ + ../../supportlibs/cmark/src/inlines.c \ + ../../supportlibs/cmark/src/iterator.c \ + ../../supportlibs/cmark/src/latex.c \ + ../../supportlibs/cmark/src/man.c \ + ../../supportlibs/cmark/src/node.c \ + ../../supportlibs/cmark/src/references.c \ + ../../supportlibs/cmark/src/render.c \ + ../../supportlibs/cmark/src/scanners.c \ + ../../supportlibs/cmark/src/utf8.c \ + ../../supportlibs/cmark/src/xml.c \ + +} diff --git a/retroshare-gui/src/rshare.cpp b/retroshare-gui/src/rshare.cpp index a87ad358f..e83d9eeb7 100644 --- a/retroshare-gui/src/rshare.cpp +++ b/retroshare-gui/src/rshare.cpp @@ -41,7 +41,7 @@ #include #include -#include +#include #include #include #include diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index 2b3e75b35..046ea47a6 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -38,6 +38,10 @@ #include "util/imageutil.h" #include "util/rstime.h" +//Include for CMark +#include +#include + #include /** @@ -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) { diff --git a/retroshare-gui/src/util/HandleRichText.h b/retroshare-gui/src/util/HandleRichText.h index a8f8d66ef..afa91f091 100644 --- a/retroshare-gui/src/util/HandleRichText.h +++ b/retroshare-gui/src/util/HandleRichText.h @@ -44,6 +44,7 @@ #define RSHTML_FORMATTEXT_REMOVE_FONT (RSHTML_FORMATTEXT_REMOVE_FONT_WEIGHT | RSHTML_FORMATTEXT_REMOVE_FONT_STYLE | RSHTML_FORMATTEXT_REMOVE_FONT_FAMILY | RSHTML_FORMATTEXT_REMOVE_FONT_SIZE) #define RSHTML_FORMATTEXT_CLEANSTYLE (RSHTML_FORMATTEXT_REMOVE_FONT | RSHTML_FORMATTEXT_REMOVE_COLOR) #define RSHTML_FORMATTEXT_NO_EMBED 0x0400//1024 +#define RSHTML_FORMATTEXT_USE_CMARK 0x0800//2048 /* Flags for RsHtml::optimizeHtml */ #define RSHTML_OPTIMIZEHTML_MASK (RSHTML_FORMATTEXT_CLEANSTYLE | RSHTML_FORMATTEXT_FIX_COLORS | RSHTML_FORMATTEXT_OPTIMIZE) diff --git a/supportlibs/cmark b/supportlibs/cmark new file mode 160000 index 000000000..b9c7a496b --- /dev/null +++ b/supportlibs/cmark @@ -0,0 +1 @@ +Subproject commit b9c7a496ba7dd9c3495bae2ff2855899e47b245d