QTextMarkdownWriter: Don't word-wrap headings

If it wraps, the text on the next line is no longer part of the heading.

Fixes: QTBUG-106526
Change-Id: I8015c948d875c6944422ef3439e3128af5b2a2e2
Pick-to: 6.5 6.6 6.7
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Shawn Rutledge 2024-02-07 01:11:18 -07:00
parent 908fc2e72b
commit 65c40290b4
3 changed files with 13 additions and 1 deletions

View File

@ -481,8 +481,10 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign
m_linePrefixWritten = true;
}
}
if (blockFmt.headingLevel())
if (blockFmt.headingLevel()) {
m_stream << QByteArray(blockFmt.headingLevel(), '#') << ' ';
wrap = false;
}
QString wrapIndentString = m_linePrefix + QString(m_wrappedLineIndent, qtmw_Space);
// It would be convenient if QTextStream had a lineCharPos() accessor,

View File

@ -0,0 +1,9 @@
# The quick brown fox jumped over the lazy dog while the cat played the fiddle and the cow jumped over the moon
Hey diddle diddle
## This document has a verbose subheading too, which we do not expect to wrap in the output
Qt can write it right. Long text here in this paragraph will actually wrap,
even though its heading doesn't.

View File

@ -634,6 +634,7 @@ void tst_QTextMarkdownWriter::rewriteDocument_data()
QTest::newRow("links") << "links.md";
QTest::newRow("lists and code blocks") << "listsAndCodeBlocks.md";
QTest::newRow("front matter") << "yaml.md";
QTest::newRow("long headings") << "longHeadings.md";
}
void tst_QTextMarkdownWriter::rewriteDocument()