import QtQuick 2.0
import Sailfish.Silica 1.0
Dialog {
id: noteDialog
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; noteIndex: noteIndex }
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()
}
}
property var account
property int noteIndex
property var markdown: [
{ regex: new RegExp(/^#\s(.*)$/gm), replace: '
$1
' },
{ regex: new RegExp(/^##\s(.*)$/gm), replace: '$1
' },
{ regex: new RegExp(/^###\s(.*)$/gm), replace: '$1
' },
{ regex: new RegExp(/^####\s(.*)$/gm), replace: '$1
' },
{ regex: new RegExp(/^#####\s(.*)$/gm), replace: '$1
' },
{ regex: new RegExp(/^######\s(.*)$/gm), replace: '$1
' },
{ regex: new RegExp(/^-\s(.*)$/gm), replace: '' },
{ regex: new RegExp(/^\d{1,}.\s(.*)$/gm), replace: '- $1
' },
//{ regex: new RegExp(/([\s\S]*<\/li>)/igm), replace: '' },
//{ regex: new RegExp(/([\s\S]*<\/li>)/igm), replace: '$1
' }
]
SilicaFlickable {
anchors.fill: parent
contentHeight: column.height
Column {
id: column
width: parent.width
DialogHeader {
id: dialogHeader
acceptText: qsTr("Edit")
cancelText: qsTr("Notes")
}
LinkedLabel {
id: contentLabel
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
function parse() {
var lines = plainText.split('\n')
lines.splice(0,1);
var tmpText = lines.join('\n');
for (var i=0; i < markdown.length; i++) {
tmpText = tmpText.replace(markdown[i].regex, markdown[i].replace)
}
text = tmpText
console.log(text)
}
}
}
VerticalScrollDecorator {}
}
}