diff --git a/qml/panels/CodeBlock.qml b/qml/panels/CodeBlock.qml index b931dde..377218d 100644 --- a/qml/panels/CodeBlock.qml +++ b/qml/panels/CodeBlock.qml @@ -25,7 +25,10 @@ Rectangle { Column { id: column - anchors.fill: parent + width: parent.width - 20 + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right anchors.margins: 10 spacing: 6 diff --git a/qml/panels/MarkdownView.qml b/qml/panels/MarkdownView.qml index a40edbe..632e0a0 100644 --- a/qml/panels/MarkdownView.qml +++ b/qml/panels/MarkdownView.qml @@ -17,6 +17,7 @@ Item { // Триггерим пересборку блоков blocksModel.clear() const blocks = mdParser.parseBlocks(markdown, vaultRoot, fileDir) + // console.log("MarkdownView update", markdown.length, blocks.length) for (let i = 0; i < blocks.length; i++) { blocksModel.append(blocks[i]) } @@ -36,8 +37,9 @@ Item { id: column width: parent.width spacing: 8 - // padding via anchors - anchors.fill: parent + anchors.top: parent.top + anchors.left: parent.left + anchors.right: parent.right anchors.margins: 12 Repeater { diff --git a/src/markdown/MdParser.cpp b/src/markdown/MdParser.cpp index b13f6a9..a56a289 100644 --- a/src/markdown/MdParser.cpp +++ b/src/markdown/MdParser.cpp @@ -762,7 +762,12 @@ QVariantList MdParser::parseBlocks(const QString &markdown, const QString &vault if (start > lastPos) { QString htmlPart = markdown.mid(lastPos, start - lastPos); if (!htmlPart.trimmed().isEmpty()) { + // Сохраняем codeBlocks, т.к. render() их очищает + QHash savedBlocks; + int savedCounter = 0; + if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; } QString html = render(htmlPart, vaultRoot, fileDir); + if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; } if (!html.trimmed().isEmpty()) blocks.append(QVariantMap{{"type", "html"}, {"html", html}}); } @@ -795,14 +800,22 @@ QVariantList MdParser::parseBlocks(const QString &markdown, const QString &vault if (lastPos < markdown.length()) { QString htmlPart = markdown.mid(lastPos); if (!htmlPart.trimmed().isEmpty()) { + QHash savedBlocks; + int savedCounter = 0; + if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; } QString html = render(htmlPart, vaultRoot, fileDir); + if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; } if (!html.trimmed().isEmpty()) blocks.append(QVariantMap{{"type", "html"}, {"html", html}}); } } // Если вообще не нашли блоки, но markdown не пустой — вернём как html if (blocks.isEmpty() && !markdown.trimmed().isEmpty()) { + QHash savedBlocks; + int savedCounter = 0; + if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; } QString html = render(markdown, vaultRoot, fileDir); + if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; } blocks.append(QVariantMap{{"type", "html"}, {"html", html}}); } return blocks;