Skip to content

Commit

Permalink
QTextMarkdownWriter: Don't word-wrap headings
Browse files Browse the repository at this point in the history
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
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 65c4029)
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
(cherry picked from commit a7367e6)
  • Loading branch information
ec1oud committed Feb 15, 2024
1 parent 01a86e3 commit d16ef4d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/gui/text/qtextmarkdownwriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,10 +437,12 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign
m_indentedCodeBlock = true;
}
}
if (blockFmt.headingLevel())
if (blockFmt.headingLevel()) {
m_stream << QByteArray(blockFmt.headingLevel(), '#') << ' ';
else
wrap = false;
} else {
m_stream << m_linePrefix;
}

QString wrapIndentString = m_linePrefix + QString(m_wrappedLineIndent, qtmw_Space);
// It would be convenient if QTextStream had a lineCharPos() accessor,
Expand Down
9 changes: 9 additions & 0 deletions tests/auto/gui/text/qtextmarkdownwriter/data/longHeadings.md
Original file line number Diff line number Diff line change
@@ -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.

Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,7 @@ void tst_QTextMarkdownWriter::rewriteDocument_data()
QTest::newRow("word wrap") << "wordWrap.md";
QTest::newRow("links") << "links.md";
QTest::newRow("lists and code blocks") << "listsAndCodeBlocks.md";
QTest::newRow("long headings") << "longHeadings.md";
}

void tst_QTextMarkdownWriter::rewriteDocument()
Expand Down

0 comments on commit d16ef4d

Please sign in to comment.