fixed major rendering problem with mixed links and formattings

This commit is contained in:
azivner 2017-08-25 00:00:08 -04:00
parent 579f9eaa60
commit 4a5d29b83d
3 changed files with 27 additions and 24 deletions

View file

@ -41,7 +41,7 @@
<ul>
<li>insert - create new note on current tree level</li>
<li>shift + insert - create new sub-note</li>
<li>ctrl + insert - create new sub-note</li>
<li>delete - delete current note (and it's sub-notes)</li>
<li>shift + up - move current note up in the current tree level</li>
<li>shift + down - move current note down in the current tree level</li>

View file

@ -144,5 +144,7 @@ function html2notecase(contents, note) {
}
}
//console.log(contents);
note.detail.note_text = contents;
}

View file

@ -1,9 +1,14 @@
function notecase2html(note) {
let noteText = note.detail.note_text;
let formatting = note.formatting;
let links = note.links;
let images = note.images;
note.formatting.forEach(el => el.type = 'formatting');
note.links.forEach(el => el.type = 'link');
note.images.forEach(el => el.type = 'image');
let all = note.formatting.concat(note.links).concat(note.images);
all.sort(function compare(a, b) {
return a.note_offset - b.note_offset;
});
let offset = 0;
let lastTag = null;
@ -14,32 +19,28 @@ function notecase2html(note) {
return noteText.substr(0, position) + injected + noteText.substr(position);
}
for (let fmt of formatting) {
if (tags[fmt.fmt_tag]) {
noteText = inject(noteText, tags[fmt.fmt_tag], fmt.note_offset + offset);
for (let el of all) {
if (el.type === 'formatting') {
if (tags[el.fmt_tag]) {
noteText = inject(noteText, tags[el.fmt_tag], el.note_offset + offset);
}
}
}
else if (el.type === 'link') {
let linkHtml = '<a href="' + el.target_url + '">' + el.lnk_text + '</a>';
offset = 0;
noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length);
for (let link of links) {
let linkHtml = '<a href="' + link.target_url + '">' + link.lnk_text + '</a>';
noteText = inject(noteText, linkHtml, el.note_offset + offset);
noteText = noteText.substr(0, link.note_offset + offset) + noteText.substr(link.note_offset + offset + link.lnk_text.length);
offset -= el.lnk_text.length;
}
else if (el.type === 'image') {
let type = el.is_png ? "png" : "jpg";
noteText = inject(noteText, linkHtml, link.note_offset + offset);
let imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + el.image_data + '" />';
offset -= link.lnk_text.length;
}
offset = 0;
for (let image of images) {
let type = image.is_png ? "png" : "jpg";
let imgHtml = '<img alt="Embedded Image" src="data:image/' + type + ';base64,' + image.image_data + '" />';
noteText = inject(noteText, imgHtml, image.note_offset + offset);
noteText = inject(noteText, imgHtml, el.note_offset + offset);
}
}
noteText = noteText.replace(/(?:\r\n|\r|\n)/g, '<br />');