First fix for #17 even if it generates some ugly html. But the QML element seems to handle it fine.

This commit is contained in:
Scharel Clemens 2018-12-05 16:38:07 +01:00
parent 120464f954
commit cda3c4059a

View file

@ -41,20 +41,21 @@ 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>(<p>)?\[ \] (.*)<\/li>$/gm, convertedText = convertedText.replace(/^<li>(<p>)?\[ \] (.*)(<.*)$/gmi,
function(match, p1, p2, offset) { function(match, p1, p2, p3, offset) {
occurence++ occurence++
return '<li><font size="' + 4 + '"><a href="tasklist:checkbox_' + occurence + '">' + (p1 ? p1 : "") + '☐ ' + p2 + '</a></font></li>' return '<li class="tasklist"><a href="tasklist:checkbox_' + occurence + '">' + (p1 ? p1 : "") + '☐ ' + p2 + '</a>' + p3
} ) } )
occurence = -1 occurence = -1
convertedText = convertedText.replace(/^<li>(<p>)?\[[xX]\] (.*)<\/li>$/gm, convertedText = convertedText.replace(/^<li>(<p>)?\[[xX]\] (.*)(<.*)$/gmi,
function(match, p1, p2, offset) { function(match, p1, p2, p3, offset) {
occurence++ occurence++
return '<li><font size="' + 4 + '"><a href="tasklist:uncheckbox_' + occurence + '">' + (p1 ? p1 : "") + '☑ ' + p2 + '</a></font></li>' return '<li class="tasklist"><a href="tasklist:uncheckbox_' + occurence + '">' + (p1 ? p1 : "") + '☑ ' + p2 + '</a>' + p3
} ) } )
convertedText = convertedText.replace("<table>", "<table border='1' cellpadding='" + Theme.paddingMedium + "'>") 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" + contentLabel.text = "<style>ul,ol,table,img { margin-bottom: " + Theme.paddingLarge + "px; margin-top: " + Theme.paddingLarge + "px; }\n" +
"a:link { color: " + Theme.primaryColor + "; }\n" + "a:link { color: " + Theme.primaryColor + "; }\n" +
"li.tasklist { font-size:large; margin-bottom: " + Theme.paddingMedium + "px; margin-top: " + Theme.paddingMedium + "px; }\n" +
"table { border-color: " + Theme.secondaryColor + "; }</style>" + convertedText "table { border-color: " + Theme.secondaryColor + "; }</style>" + convertedText
console.log(contentLabel.text) console.log(contentLabel.text)
} }
@ -113,10 +114,11 @@ Dialog {
linkColor: Theme.primaryColor linkColor: Theme.primaryColor
defaultLinkActions: false defaultLinkActions: false
onLinkActivated: { onLinkActivated: {
console.log(link)
var occurence = -1 var occurence = -1
var newContent = note.content var newContent = note.content
if (/^tasklist:checkbox_(\d+)$/m.test(link)) { if (/^tasklist:checkbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/^- \[ \] (.*)$/gm, newContent = newContent.replace(/- \[ \] (.*)$/gm,
function(match, p1, offset, string) { function(match, p1, offset, string) {
occurence++ occurence++
if (occurence === parseInt(link.split('_')[1])) { if (occurence === parseInt(link.split('_')[1])) {
@ -128,7 +130,7 @@ Dialog {
account.updateNote(note.id, { 'content': note.content } ) account.updateNote(note.id, { 'content': note.content } )
} }
else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) { else if (/^tasklist:uncheckbox_(\d+)$/m.test(link)) {
newContent = newContent.replace(/^- \[[xX]\] (.*)$/gm, newContent = newContent.replace(/- \[[xX]\] (.*)$/gm,
function(match, p1, offset, string) { function(match, p1, offset, string) {
occurence++ occurence++
if (occurence === parseInt(link.split('_')[1])) { if (occurence === parseInt(link.split('_')[1])) {