path: root/src/gui/text/qtextmarkdownwriter_p.h
diff options
authorShawn Rutledge <>2019-05-20 17:40:12 +0200
committerShawn Rutledge <>2019-06-04 08:01:34 +0200
commitb3cc9403c4f7814d3e14915fdacee42b3a805073 (patch)
tree903a727b9b78301b9ed7dd5031ac063f3483dc19 /src/gui/text/qtextmarkdownwriter_p.h
parent57f38bc49d43140f3b04e625a47eb1e6de8d2ae3 (diff)
QTextMarkdownWriter: write fenced code blocks with language declaration
MD4C now makes it possible to detect indented and fenced code blocks: Fenced code blocks have the advantages of being easier to write by hand, and having an "info string" following the opening fence, which is commonly used to declare the language. Also, the HTML parser now recognizes tags of the form <pre class="language-foo"> which is one convention for declaring the programming language (as opposed to human language, for which the lang attribute would be used): So it's possible to read HTML and write markdown without losing this information. It's also possible to read markdown with any type of code block: fenced with ``` or ~~~, or indented, and rewrite it the same way. Change-Id: I33c2bf7d7b66c8f3ba5bdd41ab32572f09349c47 Reviewed-by: Gatis Paeglis <>
Diffstat (limited to 'src/gui/text/qtextmarkdownwriter_p.h')
1 files changed, 4 insertions, 1 deletions
diff --git a/src/gui/text/qtextmarkdownwriter_p.h b/src/gui/text/qtextmarkdownwriter_p.h
index 96ceb445cd..90310250ac 100644
--- a/src/gui/text/qtextmarkdownwriter_p.h
+++ b/src/gui/text/qtextmarkdownwriter_p.h
@@ -67,7 +67,7 @@ public:
bool writeAll(const QTextDocument *document);
void writeTable(const QAbstractItemModel *table);
- int writeBlock(const QTextBlock &block, bool table, bool ignoreFormat);
+ int writeBlock(const QTextBlock &block, bool table, bool ignoreFormat, bool ignoreEmpty);
void writeFrame(const QTextFrame *frame);
@@ -82,9 +82,12 @@ private:
QTextDocument::MarkdownFeatures m_features;
QMap<QTextList *, ListInfo> m_listInfo;
QString m_linePrefix;
+ QString m_codeBlockFence;
int m_wrappedLineIndent = 0;
int m_lastListIndent = 1;
bool m_doubleNewlineWritten = false;
+ bool m_indentedCodeBlock = false;
+ bool m_fencedCodeBlock = false;