summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2019-10-14 17:59:16 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2019-11-05 16:40:18 +0200
commitd1c6f7e5a2e0ee6c50bbf0668e44200bd8469a09 (patch)
treebd35b5f802567cb06d65b09454f6ba3ecd712f7d
parent524ab7b5357e66b935a42956ec365a511e62e5ed (diff)
QTextMarkdownWriter: preserve empty listsv5.14.0-beta3
You can save a "skeletal" document with list items to fill in later, the same as you can do in HTML or ODF format. Reading them back via QTextDocument::fromMarkdown() isn't always perfect though. Fixes: QTBUG-79217 Change-Id: Iacdb3e6792250ebdead05f314c9e3d00546eeb9f Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
-rw-r--r--src/gui/text/qtextmarkdownwriter.cpp3
-rw-r--r--tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp10
-rw-r--r--tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp9
3 files changed, 16 insertions, 6 deletions
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp
index 764c64aead..c9a63920c3 100644
--- a/src/gui/text/qtextmarkdownwriter.cpp
+++ b/src/gui/text/qtextmarkdownwriter.cpp
@@ -173,7 +173,8 @@ void QTextMarkdownWriter::writeFrame(const QTextFrame *frame)
if (lastWasList)
m_stream << Newline;
}
- int endingCol = writeBlock(block, !table, table && tableRow == 0, nextIsDifferent);
+ int endingCol = writeBlock(block, !table, table && tableRow == 0,
+ nextIsDifferent && !block.textList());
m_doubleNewlineWritten = false;
if (table) {
QTextTableCell cell = table->cellAt(block.position());
diff --git a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
index 1aa1406218..2f0b877799 100644
--- a/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownimporter/tst_qtextmarkdownimporter.cpp
@@ -171,14 +171,14 @@ void tst_QTextMarkdownImporter::lists_data()
// Some of these cases show odd behavior, which is subject to change
// as the importer and the writer are tweaked to fix bugs over time.
QTest::newRow("dot newline") << ".\n" << 0 << true << ".\n\n";
- QTest::newRow("number dot newline") << "1.\n" << 1 << true << "";
- QTest::newRow("star newline") << "*\n" << 1 << true << "";
- QTest::newRow("hyphen newline") << "-\n" << 1 << true << "";
- QTest::newRow("hyphen space newline") << "- \n" << 1 << true << "";
+ QTest::newRow("number dot newline") << "1.\n" << 1 << true << "1. \n";
+ QTest::newRow("star newline") << "*\n" << 1 << true << "* \n";
+ QTest::newRow("hyphen newline") << "-\n" << 1 << true << "- \n";
+ QTest::newRow("hyphen space newline") << "- \n" << 1 << true << "- \n";
QTest::newRow("hyphen space letter newline") << "- a\n" << 1 << false << "- a\n";
QTest::newRow("hyphen nbsp newline") <<
QString::fromUtf8("-\u00A0\n") << 0 << true << "-\u00A0\n\n";
- QTest::newRow("nested empty lists") << "*\n *\n *\n" << 1 << true << "";
+ QTest::newRow("nested empty lists") << "*\n *\n *\n" << 1 << true << " * \n";
QTest::newRow("list nested in empty list") << "-\n * a\n" << 2 << false << "- \n * a\n";
QTest::newRow("lists nested in empty lists")
<< "-\n * a\n * b\n- c\n *\n + d\n" << 5 << false
diff --git a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
index 1e6c354f17..d15e856a20 100644
--- a/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
+++ b/tests/auto/gui/text/qtextmarkdownwriter/tst_qtextmarkdownwriter.cpp
@@ -50,6 +50,7 @@ private slots:
void testWriteParagraph_data();
void testWriteParagraph();
void testWriteList();
+ void testWriteEmptyList();
void testWriteNestedBulletLists_data();
void testWriteNestedBulletLists();
void testWriteNestedNumericLists();
@@ -124,6 +125,14 @@ void tst_QTextMarkdownWriter::testWriteList()
"- ListItem 1\n- ListItem 2\n"));
}
+void tst_QTextMarkdownWriter::testWriteEmptyList()
+{
+ QTextCursor cursor(document);
+ cursor.createList(QTextListFormat::ListDisc);
+
+ QCOMPARE(documentToUnixMarkdown(), QString::fromLatin1("- \n"));
+}
+
void tst_QTextMarkdownWriter::testWriteNestedBulletLists_data()
{
QTest::addColumn<bool>("checkbox");