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>bb10
parent
fa83b30ceb
commit
0fcd782bd3
|
|
@ -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)) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
- something happens in the debugger like this:
|
||||
|
||||
```
|
||||
1 QQuickEventPoint::setGrabberItem qquickevents.cpp 869 0x7ffff7a963f2
|
||||
2 QQuickItem::grabMouse qquickitem.cpp 7599 0x7ffff7abea29
|
||||
3 QQuickWindowPrivate::deliverMatchingPointsToItem qquickwindow.cpp 2738 0x7ffff7aea34c
|
||||
4 QQuickWindowPrivate::deliverPressOrReleaseEvent qquickwindow.cpp 2692 0x7ffff7ae9e57
|
||||
5 QQuickWindowPrivate::deliverMouseEvent qquickwindow.cpp 1911 0x7ffff7ae561b
|
||||
6 QQuickWindowPrivate::deliverPointerEvent qquickwindow.cpp 2454 0x7ffff7ae888c
|
||||
7 QQuickWindowPrivate::handleMouseEvent qquickwindow.cpp 2282 0x7ffff7ae7f1a
|
||||
8 QQuickWindow::mousePressEvent qquickwindow.cpp 2249 0x7ffff7ae7bf5
|
||||
9 QQuickView::mousePressEvent qquickview.cpp 626 0x7ffff7bd6bad
|
||||
10 QWindow::event qwindow.cpp 2258 0x7ffff70b2c54
|
||||
```
|
||||
and then I want to explain something about it.
|
||||
|
||||
- something I tried to fix it:
|
||||
|
||||
```
|
||||
code goes here, probably c++
|
||||
```
|
||||
- still didn't fix it, expecting a breakthrough any day now
|
||||
- some sort of miracle
|
||||
- profit!
|
||||
|
|
@ -369,6 +369,7 @@ void tst_QTextMarkdownWriter::rewriteDocument_data()
|
|||
QTest::newRow("list items after headings") << "headingsAndLists.md";
|
||||
QTest::newRow("word wrap") << "wordWrap.md";
|
||||
QTest::newRow("links") << "links.md";
|
||||
QTest::newRow("lists and code blocks") << "listsAndCodeBlocks.md";
|
||||
}
|
||||
|
||||
void tst_QTextMarkdownWriter::rewriteDocument()
|
||||
|
|
|
|||
Loading…
Reference in New Issue