mirror of
https://github.com/zadam/trilium.git
synced 2025-06-06 18:08:33 +02:00
tweaking html conversion process
This commit is contained in:
parent
d6ffae2035
commit
a460c40587
@ -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() {
|
function convertAll2Html() {
|
||||||
const failedNotes = [];
|
const failedNotes = [];
|
||||||
let counter = 1;
|
let counter = 1;
|
||||||
@ -6,44 +50,7 @@ function convertAll2Html() {
|
|||||||
console.log('Converting ' + counter + "/" + globalAllNoteIds.length);
|
console.log('Converting ' + counter + "/" + globalAllNoteIds.length);
|
||||||
counter++;
|
counter++;
|
||||||
|
|
||||||
$.ajax({
|
convertNoteToHtml(noteId, failedNotes);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Failed notes: ", failedNotes);
|
console.log("Failed notes: ", failedNotes);
|
||||||
|
@ -1,4 +1,16 @@
|
|||||||
|
const globalHtmlEnabled = true;
|
||||||
|
|
||||||
function html2notecase(contents, note) {
|
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>
|
// 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)/, '');
|
contents = contents.replace(/(?:\r\n|\r|\n)/, '');
|
||||||
|
|
||||||
@ -15,10 +27,6 @@ function html2notecase(contents, note) {
|
|||||||
|
|
||||||
let index = 0;
|
let index = 0;
|
||||||
|
|
||||||
note.formatting = [];
|
|
||||||
note.links = [];
|
|
||||||
note.images = [];
|
|
||||||
|
|
||||||
while (index < contents.length) {
|
while (index < contents.length) {
|
||||||
let curContent = contents.substr(index);
|
let curContent = contents.substr(index);
|
||||||
|
|
||||||
|
@ -1,4 +1,8 @@
|
|||||||
function notecase2html(note) {
|
function notecase2html(note) {
|
||||||
|
if (globalHtmlEnabled) {
|
||||||
|
return note.detail.note_text;
|
||||||
|
}
|
||||||
|
|
||||||
let noteText = note.detail.note_text;
|
let noteText = note.detail.note_text;
|
||||||
|
|
||||||
note.formatting.forEach(el => el.type = 'formatting');
|
note.formatting.forEach(el => el.type = 'formatting');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user