diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-05-20 17:40:12 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2019-06-04 08:01:34 +0200 |
commit | b3cc9403c4f7814d3e14915fdacee42b3a805073 (patch) | |
tree | 903a727b9b78301b9ed7dd5031ac063f3483dc19 /tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | |
parent | 57f38bc49d43140f3b04e625a47eb1e6de8d2ae3 (diff) |
QTextMarkdownWriter: write fenced code blocks with language declaration
MD4C now makes it possible to detect indented and fenced code blocks:
https://github.com/mity/md4c/issues/81
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):
https://stackoverflow.com/questions/5134242/semantics-standards-and-using-the-lang-attribute-for-source-code-in-markup
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 <gatis.paeglis@qt.io>
Diffstat (limited to 'tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp')
-rw-r--r-- | tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp index 1935e58dec..8d38cbb18a 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp +++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp @@ -419,6 +419,9 @@ void tst_QTextMarkdownWriter::fromHtml_data() QTest::newRow("image") << "<img src=\"/url\" alt=\"foo\" title=\"title\"/>" << "![foo](/url \"title\")\n\n"; + QTest::newRow("code") << + "<pre class=\"language-pseudocode\">\n#include \"foo.h\"\n\nblock {\n statement();\n}\n\n</pre>" << + "``` pseudocode\n#include \"foo.h\"\n\nblock {\n statement();\n}\n```\n\n"; // TODO // QTest::newRow("escaped number and paren after double newline") << // "<p>(The first sentence of this paragraph is a line, the next paragraph has a number</p>13) but that's not part of an ordered list" << |