Files
Flora/qml/panels/MarkdownView.qml
T

98 lines
3.3 KiB
QML
Raw Normal View History

import QtQuick
import QtQuick.Controls
import Flora
Item {
id: root
property string markdown: ""
property string vaultRoot: ""
property string fileDir: ""
property string emptyText: qsTr("Пустой файл — начните писать в режиме редактирования")
implicitHeight: column.implicitHeight + 24
signal linkActivated(string href)
// Для обновления
function update() {
// Триггерим пересборку блоков
blocksModel.clear()
const blocks = mdParser.parseBlocks(markdown, vaultRoot, fileDir)
for (let i = 0; i < blocks.length; i++) {
blocksModel.append(blocks[i])
}
// Позиция скролла в начало
// contentItem.contentY = 0
}
onMarkdownChanged: update()
onVaultRootChanged: update()
onFileDirChanged: update()
Component.onCompleted: update()
ListModel { id: blocksModel }
Column {
id: column
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
anchors.margins: 12
spacing: 8
Repeater {
model: blocksModel
delegate: Item {
required property var model
required property int index
width: parent.width
height: childrenRect.height
property string blockType: model.type || ""
property string blockHtml: model.html || ""
property string blockCode: model.codeText || ""
property string blockLang: model.language || "text"
property string blockCodeId: model.codeId || ""
property string blockHighlighted: model.highlightedText || ""
// HTML block
Text {
visible: blockType === "html" && blockHtml
width: parent.width
text: blockHtml
textFormat: Text.RichText
wrapMode: Text.Wrap
color: Theme.text
font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace"
font.pixelSize: 14
onLinkActivated: (href) => root.linkActivated(href)
}
// Code block - separate component
CodeBlock {
visible: blockType === "code"
width: parent.width
code: blockCode
language: blockLang
codeId: blockCodeId
highlightedText: blockHighlighted
onCopyRequested: (id) => {
const txt = mdParser.getCodeBlock(id)
if (txt.length > 0) {
mdParser.copyToClipboard(txt)
root.linkActivated("flora://copycode/" + id)
}
}
}
}
}
Label {
width: parent.width
text: markdown.trim().length === 0 ? emptyText : ""
color: Theme.textFaint
wrapMode: Text.Wrap
font.italic: true
visible: markdown.trim().length === 0 && blocksModel.count === 0
}
}
}