From 04a60bb033f57099b048b0d6f99f68a08dcd1483 Mon Sep 17 00:00:00 2001 From: Shawn Rutledge Date: Fri, 18 Feb 2022 21:58:35 +0100 Subject: Convert
 to Markdown ``` and vice-versa with nonBreakableLines

The HTML parser calls QTextBlockFormat::setNonBreakableLines(true) when
it sees a 
 tag; so for symmetry, the markdown reader now does the
same when it sees a fenced code block, and the markdown writer honors
the nonBreakableLines property by writing a fenced code block. This
preserves the meaning better when reading HTML and writing markdown or
vice-versa, without modifying HTML reading or writing code.

Added a test tst_QTextMarkdownImporter::fencedCodeBlocks() which
unfortunately also highlights a known bug in the markdown reader: each
fenced code block ends with an extra empty block. That can be fixed
separately.

tst_QTextMarkdownWriter::fromHtml(preformats with embedded backticks)
that we re-enabled in 1abaf9d5d6ea9c6554362e851903ddd214a6f659 was not a
very useful test: ``` with a space and some words but no newline is not
a fence: it's just like a `monospace` span. We have had trouble with
those in CI because of missing monospace fonts, or inconsistency when
a supposedly mono font's QFontInfo::fixedPitch() returns false.
So just test proper 
/fence conversion for now.

Pick-to: 6.3
Fixes: QTBUG-100515
Fixes: QTBUG-100981
Task-number: QTBUG-101031
Change-Id: I88f0ede0810d8a9480b30eb0cd780e1af67cc5f2
Reviewed-by: Allan Sandfeld Jensen 
---
 tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'tests/auto/gui/text/qtextmarkdownwriter')

diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
index b9230be465..c5e4829533 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
@@ -500,8 +500,8 @@ void tst_QTextMarkdownWriter::fromHtml_data()
 //        "

(The first sentence of this paragraph is a line, the next paragraph has a number

13) but that's not part of an ordered list" << // "(The first sentence of this paragraph is a line, the next paragraph has a number\n\n13\\) but that's not part of an ordered list\n\n"; QTest::newRow("preformats with embedded backticks") << - "
none `one` ``two``
```three``` ````four````
plain" << - "``` none `one` ``two`` ```\n\n````` ```three``` ````four```` `````\n\nplain\n\n"; + "
none `one` ``two``
plain
```three``` ````four````
plain" << + "```\nnone `one` ``two``\n\n```\nplain\n\n```\n```three``` ````four````\n\n```\nplain\n\n"; } void tst_QTextMarkdownWriter::fromHtml() -- cgit v1.2.3