mirror of
https://github.com/zadam/trilium.git
synced 2025-03-03 18:49:27 +08:00
tweaking html conversion process
This commit is contained in:
parent
d6ffae2035
commit
a460c40587
3 changed files with 61 additions and 42 deletions
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in a new issue