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

View file

@ -59,19 +59,17 @@ Page {
} }
header: PageHeader { 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 { SearchField {
id: searchField id: searchField
width: parent.width width: parent.width
//enabled: notesList.count > 0
placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name placeholderText: nextcloudAccounts.itemAt(appSettings.currentAccount).name
EnterKey.iconSource: "image://theme/icon-m-enter-close" EnterKey.iconSource: "image://theme/icon-m-enter-close"
EnterKey.onClicked: focus = false EnterKey.onClicked: focus = false
onTextChanged: nextcloudAccounts.itemAt(appSettings.currentAccount).search(text.toLowerCase()) 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 currentIndex: -1

View file

@ -128,9 +128,9 @@ Page {
} }
ComboBox { ComboBox {
id: sortByComboBox 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") 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 { menu: ContextMenu {
Repeater { Repeater {
id: sortByRepeater id: sortByRepeater
@ -163,7 +163,7 @@ Page {
stepSize: 1 stepSize: 1
value: appSettings.previewLineCount value: appSettings.previewLineCount
valueText: sliderValue + " " + qsTr("lines") 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 onSliderValueChanged: appSettings.previewLineCount = sliderValue
} }
@ -171,14 +171,14 @@ Page {
text: qsTr("Editing") text: qsTr("Editing")
} }
TextSwitch { TextSwitch {
text: qsTr("Use monospaced font") text: qsTr("Monospaced font")
description: qsTr("Use a monospeced font to edit a note") description: qsTr("Use a monospeced font to edit a note")
checked: appSettings.useMonoFont checked: appSettings.useMonoFont
onCheckedChanged: appSettings.useMonoFont = checked onCheckedChanged: appSettings.useMonoFont = checked
} }
TextSwitch { TextSwitch {
text: qsTr("Use capital 'X' in checkboxes") text: qsTr("Capital 'X' in checkboxes")
description: qsTr("For compatibility with other apps such as Joplin") description: qsTr("For interoperability with other apps such as Joplin")
checked: appSettings.useCapitalX checked: appSettings.useCapitalX
onCheckedChanged: appSettings.useCapitalX = checked onCheckedChanged: appSettings.useCapitalX = checked
} }

View file

@ -16,6 +16,7 @@
- Bugfix: Adding notes is possible again - Bugfix: Adding notes is possible again
- Added: Option for monospaced font - Added: Option for monospaced font
- Added: Option for capital X in checkboxes - 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 * Tue Dec 04 2018 Scharel Clemens <harbour-nextcloudnotes@scharel.name> 0.1-5
- Implemented auto prepend for list elements - Implemented auto prepend for list elements

View file

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

View file

@ -318,18 +318,10 @@
<source>lines</source> <source>lines</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Number of lines to preview in the list view</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>every</source> <source>every</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>Date</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Category</source> <source>Category</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -343,7 +335,35 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<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> <translation type="unfinished"></translation>
</message> </message>
</context> </context>