harbour-nextcloudnotes/qml/pages/NotePage.qml

78 lines
2.7 KiB
QML
Raw Normal View History

2018-10-16 18:50:58 +03:00
import QtQuick 2.0
import Sailfish.Silica 1.0
2018-11-18 13:25:28 +03:00
Dialog {
id: noteDialog
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; noteIndex: noteIndex }
2018-11-18 17:01:32 +03:00
Component.onCompleted: acceptDestinationProperties = { account: account, noteIndex: noteIndex }
onStatusChanged: {
if (status === PageStatus.Active) {
dialogHeader.title = account.model.get(noteIndex).title
contentLabel.plainText = account.model.get(noteIndex).content
contentLabel.parse()
}
}
Connections {
target: account.model.get(noteIndex)
onTitleChanged: dialogHeader.title = account.model.get(noteIndex).title
onContentChanged: {
contentLabel.plainText = account.model.get(noteIndex).content
contentLabel.parse()
}
}
2018-11-18 13:25:28 +03:00
property var account
property int noteIndex
2018-10-16 18:50:58 +03:00
2018-10-21 02:44:23 +03:00
property var markdown: [
2018-11-18 17:01:32 +03:00
{ regex: new RegExp(/^#\s(.*)$/gm), replace: '<h1>$1</h1>' },
{ regex: new RegExp(/^##\s(.*)$/gm), replace: '<h2>$1</h2>' },
{ regex: new RegExp(/^###\s(.*)$/gm), replace: '<h3>$1</h3>' },
{ regex: new RegExp(/^####\s(.*)$/gm), replace: '<h4>$1</h4>' },
{ regex: new RegExp(/^#####\s(.*)$/gm), replace: '<h5>$1</h5>' },
{ regex: new RegExp(/^######\s(.*)$/gm), replace: '<h6>$1</h6>' },
{ regex: new RegExp(/^-\s(.*)$/gm), replace: '<ul><li>$1</li></ul>' },
{ regex: new RegExp(/^\d{1,}.\s(.*)$/gm), replace: '<ol><li>$1</li></ol>' },
//{ regex: new RegExp(/(<li class="ul">[\s\S]*<\/li>)/igm), replace: '<ul>$1</ul>' },
//{ regex: new RegExp(/(<li class="ol">[\s\S]*<\/li>)/igm), replace: '<ol>$1</ol>' }
2018-10-21 02:44:23 +03:00
]
2018-10-16 18:50:58 +03:00
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column
2018-10-21 02:44:23 +03:00
width: parent.width
2018-10-16 18:50:58 +03:00
2018-11-18 13:25:28 +03:00
DialogHeader {
2018-11-18 17:01:32 +03:00
id: dialogHeader
2018-11-18 13:25:28 +03:00
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
2018-10-16 18:50:58 +03:00
}
2018-10-21 02:44:23 +03:00
LinkedLabel {
2018-11-18 17:01:32 +03:00
id: contentLabel
2018-10-21 02:44:23 +03:00
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
2018-11-18 17:01:32 +03:00
function parse() {
var lines = plainText.split('\n')
2018-11-18 13:25:28 +03:00
lines.splice(0,1);
2018-11-18 17:01:32 +03:00
var tmpText = lines.join('\n');
2018-10-21 02:44:23 +03:00
for (var i=0; i < markdown.length; i++) {
2018-11-18 17:01:32 +03:00
tmpText = tmpText.replace(markdown[i].regex, markdown[i].replace)
2018-10-21 02:44:23 +03:00
}
2018-11-18 17:01:32 +03:00
text = tmpText
console.log(text)
2018-10-21 02:44:23 +03:00
}
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 {}
}
}