mproved markdown rendering

This commit is contained in:
Scharel Clemens 2018-12-04 15:22:57 +01:00
parent 30947fb251
commit 9b9b75cff8
6 changed files with 95 additions and 73 deletions

View file

@ -10,24 +10,28 @@ Dialog {
property var showdown: ShowDown.showdown
property var converter: new showdown.Converter(
{ noHeaderId: true,
simplifiedAutoLink: true,
{ simplifiedAutoLink: true,
excludeTrailingPunctuationFromURLs: true,
strikethrough: true,
tables: true,
tasklists: false, // this is handled by the function parseContent() because LinkedLabel HTML support is to basic
parseImgDimensions: true,
simpleLineBreaks: true,
emoji: true } )
acceptDestination: Qt.resolvedUrl("EditPage.qml")
acceptDestinationProperties: { account: account; note: note }
Component.onCompleted: {
parseContent()
acceptDestinationProperties = { account: account, note: note }
//showdown.setFlavor('original')
parseContent()
}
Connections {
target: account
onBusyChanged: {
if (account.busy === false) {
note = account.getNote(note.id, false)
acceptDestinationProperties = { account: account, note: note }
parseContent()
}
}
@ -37,19 +41,22 @@ Dialog {
note = account.getNote(note.id, false)
var convertedText = converter.makeHtml(note.content)
var occurence = -1
convertedText = convertedText.replace(/^<li>\[ \] (.*)<\/li>$/gm,
function(match, p1, offset) {
convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)<\/li>$/gm,
function(match, p1, p2, offset) {
occurence++
return '<li><font size="' + 4 + '"><a href="tasklist:checkbox_' + occurence + '">☐ ' + p1 + '</a></font></li>'
return '<li><font size="' + 4 + '"><a href="tasklist:checkbox_' + occurence + '">' + (p1 ? p1 : "") + '☐ ' + p2 + '</a></font></li>'
} )
occurence = -1
convertedText = convertedText.replace(/^<li>\[[xX]\] (.*)<\/li>$/gm,
function(match, p1, offset) {
convertedText = convertedText.replace(/^<li>(<p>)?\[[xX]\] (.*)<\/li>$/gm,
function(match, p1, p2, offset) {
occurence++
return '<li><font size="' + 4 + '"><a href="tasklist:uncheckbox_' + occurence + '">☑ ' + p1 + '</a></font></li>'
return '<li><font size="' + 4 + '"><a href="tasklist:uncheckbox_' + occurence + '">' + (p1 ? p1 : "") + '☑ ' + p2 + '</a></font></li>'
} )
contentLabel.text = convertedText
//console.log(contentLabel.text)
convertedText = convertedText.replace("<table>", "<table border='1' cellpadding='" + Theme.paddingMedium + "'>")
contentLabel.text = "<style>ul,ol,table,img { margin-bottom: " + Theme.paddingLarge + "px; margin-top: " + Theme.paddingLarge + "px; }\n" +
"a:link { color: " + Theme.primaryColor + "; }\n" +
"table { border-color: " + Theme.secondaryColor + "; }</style>" + convertedText
console.log(contentLabel.text)
}
SilicaFlickable {
@ -102,7 +109,8 @@ Dialog {
id: contentLabel
x: Theme.horizontalPageMargin
width: parent.width - 2*x
textFormat: Text.StyledText
textFormat: Text.RichText
linkColor: Theme.primaryColor
defaultLinkActions: false
onLinkActivated: {
var occurence = -1
@ -137,12 +145,6 @@ Dialog {
}
}
DetailItem {
id: modifiedDetail
label: qsTr("Modified")
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
Separator {
id: separator
width: parent.width
@ -150,45 +152,46 @@ Dialog {
horizontalAlignment: Qt.AlignHCenter
}
Row {
x: Theme.horizontalPageMargin
width: parent.width - x
IconButton {
id: favoriteButton
property bool selected: note.favorite
width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: {
account.updateNote(note.id, {'favorite': !note.favorite})
Column {
width: parent.width
Row {
x: Theme.horizontalPageMargin
width: parent.width - x
IconButton {
id: favoriteButton
property bool selected: note.favorite
width: Theme.iconSizeMedium
icon.source: (selected ? "image://theme/icon-m-favorite-selected?" : "image://theme/icon-m-favorite?") +
(favoriteButton.highlighted ? Theme.secondaryHighlightColor : Theme.secondaryColor)
onClicked: {
account.updateNote(note.id, {'favorite': !note.favorite})
}
}
}
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note.category
placeholderText: qsTr("No category")
label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
categoryField.focus = false
}
onFocusChanged: {
if (focus === false) {
account.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
TextField {
id: categoryField
width: parent.width - favoriteButton.width
text: note.category
placeholderText: qsTr("No category")
label: qsTr("Category")
EnterKey.iconSource: "image://theme/icon-m-enter-accept"
EnterKey.onClicked: {
categoryField.focus = false
}
onFocusChanged: {
if (focus === false) {
account.updateNote(note.id, {'content': note.content, 'category': text}) // This does not seem to work without adding the content
}
}
}
}
}
/*DetailItem {
id: favoriteDetail
label: qsTr("Favorite")
}
DetailItem {
id: categoryDetail
label: qsTr("Category")
visible: value.length > 0
}*/
id: modifiedDetail
label: qsTr("Modified")
value: new Date(note.modified * 1000).toLocaleString(Qt.locale(), Locale.ShortFormat)
}
}
}
}

View file

@ -59,19 +59,17 @@ Page {
}
header: PageHeader {
//title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
description: searchField.text === "" ? nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server :
searchField.placeholderText
SearchField {
id: searchField
width: parent.width
//enabled: notesList.count > 0
placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name
EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false
onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase())
}
//title: nextcloudAccounts.itemAt(appSettings.currentAccount).name //qsTr("Nextclound Notes")
description: searchField.text === "" ? nextcloudAccounts.itemAt(appSettings.currentAccount).username + "@" + nextcloudAccounts.itemAt(appSettings.currentAccount).server :
searchField.placeholderText
}
currentIndex: -1

View file

@ -128,9 +128,9 @@ Page {
}
ComboBox {
id: sortByComboBox
property var names: [qsTr("Date"), qsTr("Category"), qsTr("Title alphabetically")]
property var names: [qsTr("Last edited"), qsTr("Category"), qsTr("Title alphabetically")]
label: qsTr("Sort notes by")
description: qsTr("This will also change how the notes are segmented")
description: qsTr("This will also change how the notes are grouped")
menu: ContextMenu {
Repeater {
id: sortByRepeater
@ -163,7 +163,7 @@ Page {
stepSize: 1
value: appSettings.previewLineCount
valueText: sliderValue + " " + qsTr("lines")
label: qsTr("Number of lines to preview in the list view")
label: qsTr("Number of lines in the preview")
onSliderValueChanged: appSettings.previewLineCount = sliderValue
}
@ -171,14 +171,14 @@ Page {
text: qsTr("Editing")
}
TextSwitch {
text: qsTr("Use monospaced font")
text: qsTr("Monospaced font")
description: qsTr("Use a monospeced font to edit a note")
checked: appSettings.useMonoFont
onCheckedChanged: appSettings.useMonoFont = checked
}
TextSwitch {
text: qsTr("Use capital 'X' in checkboxes")
description: qsTr("For compatibility with other apps such as Joplin")
text: qsTr("Capital 'X' in checkboxes")
description: qsTr("For interoperability with other apps such as Joplin")
checked: appSettings.useCapitalX
onCheckedChanged: appSettings.useCapitalX = checked
}

View file

@ -16,6 +16,7 @@
- Bugfix: Adding notes is possible again
- Added: Option for monospaced font
- Added: Option for capital X in checkboxes
- Improved markdown parsing (espessialy lists, tables and images)
* Tue Dec 04 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-5
- Implemented auto prepend for list elements

View file

@ -14,7 +14,7 @@ Name: harbour-nextcloudnotes
%{?qtc_builddir:%define _builddir %qtc_builddir}
Summary: Nextcloud Notes
Version: 0.1
Release: 5
Release: 6
Group: Qt/Qt
License: LICENSE
URL: http://example.org/

View file

@ -318,18 +318,10 @@
<source>lines</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Number of lines to preview in the list view</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>every</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Date</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Category</source>
<translation type="unfinished"></translation>
@ -343,7 +335,35 @@
<translation type="unfinished"></translation>
</message>
<message>
<source>This will also change how the notes are segmented</source>
<source>Last edited</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>This will also change how the notes are grouped</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Number of lines in the preview</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Editing</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Monospaced font</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Use a monospeced font to edit a note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Capital &apos;X&apos; in checkboxes</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>For interoperability with other apps such as Joplin</source>
<translation type="unfinished"></translation>
</message>
</context>