Исправлен белый экран в предпросмотре: отдельный компонент CodeBlock
- CodeBlock.qml: отдельный Rectangle #2e4d6a radius 12, header с языком и кнопкой 📋 Копировать (hover/active Qt.rgba, Timer 1.5с), код в rgba(0,0,0,0.22) radius 8, JetBrains Mono, tab 4, syntax highlight тёмной темой
- MarkdownView.qml: Item с Column (width parent, spacing 8, margins 12), Repeater по parseBlocks(), delegate Item с Text (html) и CodeBlock (code), исправлен anchors.fill → width/anchors.top для корректного implicitHeight, убраны дубли visible
- MdParser: parseBlocks() сохраняет codeBlocks/counter перед render(htmlPart) чтобы не терять codeId, QRegularExpression для ```lang, highlightedCode() с forceDark
- EditorPanel: viewArea/livePreview теперь MarkdownView (markdown property), liveDebounce/markdown, убран лишний \}
- qmllint чист, ctest 21/21, offscreen/cocoa RUNNING OK
This commit is contained in:
@@ -25,7 +25,10 @@ Rectangle {
|
|||||||
|
|
||||||
Column {
|
Column {
|
||||||
id: 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
|
anchors.margins: 10
|
||||||
spacing: 6
|
spacing: 6
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Item {
|
|||||||
// Триггерим пересборку блоков
|
// Триггерим пересборку блоков
|
||||||
blocksModel.clear()
|
blocksModel.clear()
|
||||||
const blocks = mdParser.parseBlocks(markdown, vaultRoot, fileDir)
|
const blocks = mdParser.parseBlocks(markdown, vaultRoot, fileDir)
|
||||||
|
// console.log("MarkdownView update", markdown.length, blocks.length)
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
blocksModel.append(blocks[i])
|
blocksModel.append(blocks[i])
|
||||||
}
|
}
|
||||||
@@ -36,8 +37,9 @@ Item {
|
|||||||
id: column
|
id: column
|
||||||
width: parent.width
|
width: parent.width
|
||||||
spacing: 8
|
spacing: 8
|
||||||
// padding via anchors
|
anchors.top: parent.top
|
||||||
anchors.fill: parent
|
anchors.left: parent.left
|
||||||
|
anchors.right: parent.right
|
||||||
anchors.margins: 12
|
anchors.margins: 12
|
||||||
|
|
||||||
Repeater {
|
Repeater {
|
||||||
|
|||||||
@@ -762,7 +762,12 @@ QVariantList MdParser::parseBlocks(const QString &markdown, const QString &vault
|
|||||||
if (start > lastPos) {
|
if (start > lastPos) {
|
||||||
QString htmlPart = markdown.mid(lastPos, start - lastPos);
|
QString htmlPart = markdown.mid(lastPos, start - lastPos);
|
||||||
if (!htmlPart.trimmed().isEmpty()) {
|
if (!htmlPart.trimmed().isEmpty()) {
|
||||||
|
// Сохраняем codeBlocks, т.к. render() их очищает
|
||||||
|
QHash<QString, QString> savedBlocks;
|
||||||
|
int savedCounter = 0;
|
||||||
|
if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; }
|
||||||
QString html = render(htmlPart, vaultRoot, fileDir);
|
QString html = render(htmlPart, vaultRoot, fileDir);
|
||||||
|
if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; }
|
||||||
if (!html.trimmed().isEmpty())
|
if (!html.trimmed().isEmpty())
|
||||||
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
||||||
}
|
}
|
||||||
@@ -795,14 +800,22 @@ QVariantList MdParser::parseBlocks(const QString &markdown, const QString &vault
|
|||||||
if (lastPos < markdown.length()) {
|
if (lastPos < markdown.length()) {
|
||||||
QString htmlPart = markdown.mid(lastPos);
|
QString htmlPart = markdown.mid(lastPos);
|
||||||
if (!htmlPart.trimmed().isEmpty()) {
|
if (!htmlPart.trimmed().isEmpty()) {
|
||||||
|
QHash<QString, QString> savedBlocks;
|
||||||
|
int savedCounter = 0;
|
||||||
|
if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; }
|
||||||
QString html = render(htmlPart, vaultRoot, fileDir);
|
QString html = render(htmlPart, vaultRoot, fileDir);
|
||||||
|
if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; }
|
||||||
if (!html.trimmed().isEmpty())
|
if (!html.trimmed().isEmpty())
|
||||||
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Если вообще не нашли блоки, но markdown не пустой — вернём как html
|
// Если вообще не нашли блоки, но markdown не пустой — вернём как html
|
||||||
if (blocks.isEmpty() && !markdown.trimmed().isEmpty()) {
|
if (blocks.isEmpty() && !markdown.trimmed().isEmpty()) {
|
||||||
|
QHash<QString, QString> savedBlocks;
|
||||||
|
int savedCounter = 0;
|
||||||
|
if (m) { savedBlocks = m->codeBlocks; savedCounter = m->codeCounter; }
|
||||||
QString html = render(markdown, vaultRoot, fileDir);
|
QString html = render(markdown, vaultRoot, fileDir);
|
||||||
|
if (m) { m->codeBlocks = savedBlocks; m->codeCounter = savedCounter; }
|
||||||
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
blocks.append(QVariantMap{{"type", "html"}, {"html", html}});
|
||||||
}
|
}
|
||||||
return blocks;
|
return blocks;
|
||||||
|
|||||||
Reference in New Issue
Block a user