Фаза 6: просмотр Markdown — MdParser (cmark-gfm AST→HTML: таблицы/ссылки/вики/картинки data-URI/задачи-чекбоксы), подсветка кода KSyntaxHighlighting (алиасы «С»/«С++»/python), RichText-просмотр в EditorPane (onLinkActivated); тест mdparser (15/15)
This commit is contained in:
@@ -237,18 +237,61 @@ Item {
|
||||
id: viewer
|
||||
anchors.fill: parent
|
||||
visible: !pane.editMode
|
||||
text: documentManager.contentAt(pane.docIndex)
|
||||
textFormat: TextEdit.RichText
|
||||
text: ""
|
||||
readOnly: true
|
||||
selectByMouse: true
|
||||
font.family: "Menlo, Consolas, 'DejaVu Sans Mono', monospace"
|
||||
font.pixelSize: 14
|
||||
wrapMode: TextEdit.Wrap
|
||||
padding: 12
|
||||
onLinkActivated: (href) => pane.handleViewLink(href)
|
||||
placeholderText: qsTr("Документ не выбран")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---------- Просмотр (режим просмотра) ----------
|
||||
function pathDir(p) {
|
||||
const idx = p.lastIndexOf("/")
|
||||
return idx >= 0 ? p.substring(0, idx) : p
|
||||
}
|
||||
function renderView() {
|
||||
if (pane.editMode || pane.docIndex < 0)
|
||||
return
|
||||
viewer.text = mdParser.render(documentManager.contentAt(pane.docIndex),
|
||||
fileStore.vault,
|
||||
pathDir(documentManager.pathAt(pane.docIndex)))
|
||||
}
|
||||
function handleViewLink(href) {
|
||||
if (href.startsWith("flora://task/")) {
|
||||
const line = Number(href.substring("flora://task/".length))
|
||||
if (line > 0) pane.toggleTaskLine(line)
|
||||
return
|
||||
}
|
||||
if (href.startsWith("flora://open/")) {
|
||||
const path = decodeURIComponent(href.substring("flora://open/".length))
|
||||
if (path.length > 0) documentManager.openDocument(path)
|
||||
return
|
||||
}
|
||||
if (href.startsWith("flora://wiki/")) {
|
||||
// Фаза 8: создание через базу связей; пока — статус.
|
||||
console.log("wiki:", decodeURIComponent(href))
|
||||
return
|
||||
}
|
||||
console.log("внешняя ссылка:", href)
|
||||
}
|
||||
function toggleTaskLine(line) {
|
||||
const text = documentManager.contentAt(pane.docIndex)
|
||||
const lines = text.split("\n")
|
||||
const ln = lines[line - 1]
|
||||
if (ln === undefined) return
|
||||
if (/\[ \]/.test(ln))
|
||||
lines[line - 1] = ln.replace("[ ]", "[x]")
|
||||
else if (/\[x\]/.test(ln))
|
||||
lines[line - 1] = ln.replace("[x]", "[ ]")
|
||||
documentManager.updateContent(pane.docIndex, lines.join("\n"))
|
||||
pane.renderView()
|
||||
}
|
||||
|
||||
// Свежий заголовок при смене признака «изменено»
|
||||
Connections {
|
||||
target: documentManager
|
||||
@@ -262,10 +305,17 @@ Item {
|
||||
target: documentManager
|
||||
function onContentChanged(i) {
|
||||
if (i === pane.docIndex && !pane.editMode)
|
||||
viewer.text = documentManager.contentAt(i)
|
||||
pane.renderView()
|
||||
}
|
||||
}
|
||||
|
||||
onDocIndexChanged: pane.refreshHeader()
|
||||
onDocIndexChanged: {
|
||||
pane.refreshHeader()
|
||||
pane.renderView()
|
||||
}
|
||||
onEditModeChanged: {
|
||||
if (!pane.editMode)
|
||||
pane.renderView()
|
||||
}
|
||||
Component.onCompleted: pane.refreshHeader()
|
||||
}
|
||||
Reference in New Issue
Block a user