summaryrefslogtreecommitdiffstats
path: root/src/gui/text
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2022-05-16 13:32:44 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2022-05-20 23:45:36 +0200
commit567340e1222d6be354b17ec66bf5f23066d4fa82 (patch)
tree5f5ff48e3b06c23ad3b47ce05174d5170a94d374 /src/gui/text
parentc140c37676fd55ed98eff360b1d11ac3e0d45c0b (diff)
Avoid ending Markdown fenced code blocks with gratuitous blank lines
This caused unnecessary empty <pre> blocks when converting markdown to HTML, made code blocks too large using QSyntaxHighlighter to highlight the whole block, and caused assymmetry when rewriting markdown. Also remove redundant qCDebug in QTextMarkdownImporter::cbText(). Fixes: QTBUG-101031 Change-Id: I08016577ccb92edb4afae31d7df3259cb011d5c8 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> (cherry picked from commit ff153d9874f728c9ec3ab40b87f55ccf0239e538)
Diffstat (limited to 'src/gui/text')
-rw-r--r--src/gui/text/qtextmarkdownimporter.cpp10
-rw-r--r--src/gui/text/qtextmarkdownwriter.cpp4
2 files changed, 10 insertions, 4 deletions
diff --git a/src/gui/text/qtextmarkdownimporter.cpp b/src/gui/text/qtextmarkdownimporter.cpp
index 0d672658fc..806ecb8eda 100644
--- a/src/gui/text/qtextmarkdownimporter.cpp
+++ b/src/gui/text/qtextmarkdownimporter.cpp
@@ -532,6 +532,14 @@ int QTextMarkdownImporter::cbText(int textType, const char *text, unsigned size)
case MD_BLOCK_TD:
m_nonEmptyTableCells.append(m_tableCol);
break;
+ case MD_BLOCK_CODE:
+ if (s == Newline) {
+ // defer a blank line until we see something else in the code block,
+ // to avoid ending every code block with a gratuitous blank line
+ m_needsInsertBlock = true;
+ s = QString();
+ }
+ break;
default:
break;
}
@@ -569,8 +577,6 @@ int QTextMarkdownImporter::cbText(int textType, const char *text, unsigned size)
<< "bindent" << bfmt.indent() << "tindent" << bfmt.textIndent()
<< "margins" << bfmt.leftMargin() << bfmt.topMargin() << bfmt.bottomMargin() << bfmt.rightMargin();
}
- qCDebug(lcMD) << textType << "in block" << m_blockType << s << "in list?" << m_cursor->currentList()
- << "indent" << m_cursor->blockFormat().indent();
return 0; // no error
}
diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp
index bd5f3bde95..4009b77d88 100644
--- a/src/gui/text/qtextmarkdownwriter.cpp
+++ b/src/gui/text/qtextmarkdownwriter.cpp
@@ -190,11 +190,11 @@ void QTextMarkdownWriter::writeFrame(const QTextFrame *frame)
for (int col = cell.column(); col < spanEndCol; ++col)
m_stream << "|";
} else if (m_fencedCodeBlock && ending) {
- m_stream << m_linePrefix << QString(m_wrappedLineIndent, Space)
+ m_stream << Newline << m_linePrefix << QString(m_wrappedLineIndent, Space)
<< m_codeBlockFence << Newline << Newline;
m_codeBlockFence.clear();
} else if (m_indentedCodeBlock && nextIsDifferent) {
- m_stream << Newline;
+ m_stream << Newline << Newline;
} else if (endingCol > 0) {
if (block.textList() || block.blockFormat().hasProperty(QTextFormat::BlockCodeLanguage)) {
m_stream << Newline;