Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
tweaking html conversion process
azivnera460c4058716
diff --git a/static/js/convert2html.js b/static/js/convert2html.jsindex ae750ddce5..5673179559 100644--- a/static/js/convert2html.js+++ b/static/js/convert2html.js@@ -1,3 +1,47 @@+function convertNoteToHtml(noteId, failedNotes) {+ $.ajax({+ url: baseUrl + 'notes/' + noteId,+ type: 'GET',+ async: false,+ success: function (note) {+ const noteNode = getNodeByKey(noteId);++ if (noteNode.data.is_clone) {+ // we shouldn't process notes twice+ return;+ }++ note.detail.note_text = notecase2html(note);+ note.formatting = [];++ for (const link of note.links) {+ delete link.type;+ }++ $.ajax({+ url: baseUrl + 'notes/' + noteId,+ type: 'PUT',+ data: JSON.stringify(note),+ contentType: "application/json",+ async: false,+ success: function () {+ console.log("Note " + noteId + " converted.")+ },+ error: function () {+ console.log("Note " + noteId + " failed when writing");++ failedNotes.push(noteId);+ }+ });+ },+ error: function () {+ console.log("Note " + noteId + " failed when reading");++ failedNotes.push(noteId);+ }+ });+}+function convertAll2Html() {const failedNotes = [];let counter = 1;@@ -6,44 +50,7 @@ function convertAll2Html() {console.log('Converting ' + counter + "/" + globalAllNoteIds.length);counter++;- $.ajax({- url: baseUrl + 'notes/' + noteId,- type: 'GET',- async: false,- success: function (note) {- note.detail.note_text = notecase2html(note);- note.formatting = [];-- for (const link of note.links) {- delete link.type;- }-- console.log(note.detail.note_text);-- $.ajax({- url: baseUrl + 'notes/' + noteId,- type: 'PUT',- data: JSON.stringify(note),- contentType: "application/json",- async: false,- success: function () {- console.log("Note " + noteId + " converted.")- },- error: function () {- console.log("Note " + noteId + " failed when writing");-- failedNotes.push(noteId);- }- });- },- error: function () {- console.log("Note " + noteId + " failed when reading");-- failedNotes.push(noteId);- }- });-- break;+ convertNoteToHtml(noteId, failedNotes);}console.log("Failed notes: ", failedNotes);diff --git a/static/js/html2notecase.js b/static/js/html2notecase.jsindex 59531083f2..54ec2b2dd1 100644--- a/static/js/html2notecase.js+++ b/static/js/html2notecase.js@@ -1,4 +1,16 @@+const globalHtmlEnabled = true;+function html2notecase(contents, note) {+ note.formatting = [];+ note.links = [];+ note.images = [];++ if (globalHtmlEnabled) {+ note.detail.note_text = contents;++ return;+ }+// remove any possible extra newlines which might be inserted - all relevant new lines should be only in <br> and <p>contents = contents.replace(/(?:\r\n|\r|\n)/, '');@@ -15,10 +27,6 @@ function html2notecase(contents, note) {let index = 0;- note.formatting = [];- note.links = [];- note.images = [];-while (index < contents.length) {let curContent = contents.substr(index);diff --git a/static/js/notecase2html.js b/static/js/notecase2html.jsindex d9cc07ce8d..335034dafb 100644--- a/static/js/notecase2html.js+++ b/static/js/notecase2html.js@@ -1,4 +1,8 @@function notecase2html(note) {+ if (globalHtmlEnabled) {+ return note.detail.note_text;+ }+let noteText = note.detail.note_text;note.formatting.forEach(el => el.type = 'formatting');