diff --git a/src/gui/text/qtextmarkdownwriter.cpp b/src/gui/text/qtextmarkdownwriter.cpp index 26e41149b2f..e99242218cf 100644 --- a/src/gui/text/qtextmarkdownwriter.cpp +++ b/src/gui/text/qtextmarkdownwriter.cpp @@ -370,8 +370,7 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign 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_stream << m_linePrefix << m_codeBlockFence << Newline; m_fencedCodeBlock = false; m_codeBlockFence.clear(); } @@ -445,8 +444,10 @@ int QTextMarkdownWriter::writeBlock(const QTextBlock &block, bool wrap, bool ign if (fenceChar.isEmpty()) fenceChar = QLatin1String("`"); m_codeBlockFence = QString(3, fenceChar.at(0)); + if (blockFmt.hasProperty(QTextFormat::BlockIndent)) + m_codeBlockFence = QString(m_wrappedLineIndent, Space) + m_codeBlockFence; // A block quote can contain an indented code block, but not vice-versa. - m_stream << m_linePrefix << QString(m_wrappedLineIndent, Space) << m_codeBlockFence + m_stream << m_linePrefix << m_codeBlockFence << blockFmt.stringProperty(QTextFormat::BlockCodeLanguage) << Newline; m_fencedCodeBlock = true; } diff --git a/tests/auto/gui/text/qtextmarkdownwriter/data/listsAndCodeBlocks.md b/tests/auto/gui/text/qtextmarkdownwriter/data/listsAndCodeBlocks.md index 54e3f25afa4..b3539167abc 100644 --- a/tests/auto/gui/text/qtextmarkdownwriter/data/listsAndCodeBlocks.md +++ b/tests/auto/gui/text/qtextmarkdownwriter/data/listsAndCodeBlocks.md @@ -22,3 +22,10 @@ - still didn't fix it, expecting a breakthrough any day now - some sort of miracle - profit! +- Alternatively we can have a non-indented fenced code block under a list item: + +```qml +import QtQuick +Text { text: "hello world" } +``` +- but that means the code block is not part of the list item.