diff options
author | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-04-19 00:39:32 +0200 |
---|---|---|
committer | Shawn Rutledge <shawn.rutledge@qt.io> | 2020-04-20 21:08:23 +0200 |
commit | 0fcd782bd3690867f19420270bcc329325f04424 (patch) | |
tree | f74aef28ee2e86251a9188aabb779f339c401bc2 /src | |
parent | fa83b30ceb1861075e33dc8340d6754daef86b95 (diff) |
Markdown writer: don't wrap code block, and detect its end
The end of a code block nested in a list item is now detected;
and if the text of the list item continues after the code block,
it continues to be indented.
Code blocks should never be word-wrapped.
Fixes: QTBUG-80603
Change-Id: I4427f8b1d4807d819616f5cb971e2d006170d9be
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/text/qtextmarkdownwriter.cpp | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index 7bd321becc..1788999855 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -367,6 +367,14 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign const int ColumnLimit = 80; QTextBlockFormat blockFmt = block.blockFormat(); bool missedBlankCodeBlockLine = false; + const bool codeBlock = blockFmt.hasProperty(QTextFormat::BlockCodeFence) || + blockFmt.stringProperty(QTextFormat::BlockCodeLanguage).length() > 0; + if (m_fencedCodeBlock && !codeBlock) { + m_stream << m_linePrefix << QString(m_wrappedLineIndent, Space) + << m_codeBlockFence << Newline; + m_fencedCodeBlock = false; + m_codeBlockFence.clear(); + } if (block.textList()) { // it's a list-item auto fmt = block.textList()->format(); const int listLevel = fmt.indent(); @@ -427,7 +435,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign } else if (blockFmt.hasProperty(QTextFormat::BlockTrailingHorizontalRulerWidth)) { m_stream << "- - -\n"; // unambiguous horizontal rule, not an underline under a heading return 0; - } else if (blockFmt.hasProperty(QTextFormat::BlockCodeFence) || blockFmt.stringProperty(QTextFormat::BlockCodeLanguage).length() > 0) { + } else if (codeBlock) { // It's important to preserve blank lines in code blocks. But blank lines in code blocks // inside block quotes are getting preserved anyway (along with the "> " prefix). if (!blockFmt.hasProperty(QTextFormat::BlockQuoteLevel)) @@ -442,13 +450,8 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign << Space << blockFmt.stringProperty(QTextFormat::BlockCodeLanguage) << Newline; m_fencedCodeBlock = true; } + wrap = false; } else if (!blockFmt.indent()) { - if (m_fencedCodeBlock) { - m_stream << m_linePrefix << QString(m_wrappedLineIndent, Space) - << m_codeBlockFence << Newline; - m_fencedCodeBlock = false; - m_codeBlockFence.clear(); - } m_wrappedLineIndent = 0; m_linePrefix.clear(); if (blockFmt.hasProperty(QTextFormat::BlockQuoteLevel)) { |