diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2017-12-19 15:25:55 +0100 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-01 14:31:27 +0000 |
commit | 23c2da3cc23a2e04a0b3b3c8ad7fa9cc6126ff23 (patch) | |
tree | 849770044988425cf290b8599b44440653bcddd0 /src/gui/text/qtextdocument.cpp | |
parent | 9ec564b0bfc94c2d33f02b24ca081b64ff9ebb9b (diff) |
Add QTextMarkdownWriter, QTextEdit::markdown property etc.
A QTextDocument can now be written out in Markdown format.
- Add the QTextMarkdownWriter as a private class for now
- Add QTextDocument::toMarkdown()
- QTextDocumentWriter uses QTextMarkdownWriter if setFormat("markdown")
is called or if the file suffix is .md or .mkd
- Add QTextEdit::toMarkdown() and the markdown property
[ChangeLog][QtGui][Text] Markdown (CommonMark or GitHub dialect) is now
a supported format for reading into and writing from QTextDocument.
Change-Id: I663a77017fac7ae1b3f9a400f5cd357bb40750af
Reviewed-by: Gatis Paeglis <gatis.paeglis@qt.io>
Diffstat (limited to 'src/gui/text/qtextdocument.cpp')
-rw-r--r-- | src/gui/text/qtextdocument.cpp | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/gui/text/qtextdocument.cpp b/src/gui/text/qtextdocument.cpp index 87c8f1ba8a..0a59bfb838 100644 --- a/src/gui/text/qtextdocument.cpp +++ b/src/gui/text/qtextdocument.cpp @@ -73,6 +73,9 @@ #if QT_CONFIG(textmarkdownreader) #include <private/qtextmarkdownimporter_p.h> #endif +#if QT_CONFIG(textmarkdownwriter) +#include <private/qtextmarkdownwriter_p.h> +#endif #include <limits.h> @@ -3289,6 +3292,22 @@ QString QTextDocument::toHtml(const QByteArray &encoding) const #endif // QT_NO_TEXTHTMLPARSER /*! + Returns a string containing a Markdown representation of the document, + or an empty string if writing fails for any reason. +*/ +#if QT_CONFIG(textmarkdownwriter) +QString QTextDocument::toMarkdown(QTextDocument::MarkdownFeatures features) const +{ + QString ret; + QTextStream s(&ret); + QTextMarkdownWriter w(s, features); + if (w.writeAll(*this)) + return ret; + return QString(); +} +#endif + +/*! Replaces the entire contents of the document with the given Markdown-formatted text in the \a markdown string, with the given \a features supported. By default, all supported GitHub-style @@ -3301,8 +3320,19 @@ QString QTextDocument::toHtml(const QByteArray &encoding) const Parsing of HTML included in the \a markdown string is handled in the same way as in \l setHtml; however, Markdown formatting inside HTML blocks is - not supported. The \c MarkdownNoHTML feature flag can be set to disable - HTML parsing. + not supported. + + Some features of the parser can be enabled or disabled via the \a features + argument: + + \value MarkdownNoHTML + Any HTML tags in the Markdown text will be discarded + \value MarkdownDialectCommonMark + The parser supports only the features standardized by CommonMark + \value MarkdownDialectGitHub + The parser supports the GitHub dialect + + The default is \c MarkdownDialectGitHub. The undo/redo history is reset when this function is called. */ |