harbour-nextcloudnotes/qml/pages/NotePage.qml

57 lines
1.7 KiB
QML
Raw Normal View History

2018-10-16 18:50:58 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
Page {
id: page
property var note
2018-10-21 02:44:23 +03:00
property var markdown: [
{ regex: new RegExp(/(^#\s)(.*)$/gm), replace: '<h1>$2</h1>' },
{ regex: new RegExp(/(^##\s)(.*)$/gm), replace: '<h2>$2</h2>' },
{ regex: new RegExp(/(^###\s)(.*)$/gm), replace: '<h3>$2</h3>' },
{ regex: new RegExp(/(^####\s)(.*)$/gm), replace: '<h4>$2</h4>' },
{ regex: new RegExp(/(^#####\s)(.*)$/gm), replace: '<h5>$2</h5>' },
{ regex: new RegExp(/(^######\s)(.*)$/gm), replace: '<h6>$2</h6>' },
{ regex: new RegExp(/(^-\s)(.*)$/gm), replace: '<ul><li>$2</li></ul>' },
{ regex: new RegExp(/(^\d{1,}.\s)(.*)$/gm), replace: '<ol><li>$2</li></ol>' }
]
2018-10-16 18:50:58 +03:00
SilicaFlickable {
id: flickable
anchors.fill: parent
contentHeight: column.height
2018-10-21 02:44:23 +03:00
PullDownMenu {
quickSelect: true
MenuItem {
text: qsTr("Edit")
onClicked: pageStack.push(Qt.resolvedUrl("EditPage.qml"), { note: note } )
}
}
2018-10-16 18:50:58 +03:00
Column {
id: column
2018-10-21 02:44:23 +03:00
width: parent.width
2018-10-16 18:50:58 +03:00
PageHeader {
title: note.title
2018-10-16 18:50:58 +03:00
}
2018-10-21 02:44:23 +03:00
LinkedLabel {
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
text: note.content
2018-10-21 02:44:23 +03:00
Component.onCompleted: {
for (var i=0; i < markdown.length; i++) {
text = text.replace(markdown[i].regex, markdown[i].replace)
}
console.log(text)
}
2018-10-16 18:50:58 +03:00
}
}
2018-10-21 02:44:23 +03:00
2018-10-16 18:50:58 +03:00
VerticalScrollDecorator {}
}
}