function notecase2html(note) { let noteText = note.detail.note_text; note.formatting.forEach(el => el.type = 'formatting'); note.links.forEach(el => el.type = 'link'); note.images.forEach(el => el.type = 'image'); const allTags = note.formatting.concat(note.links).concat(note.images); allTags.sort(function compare(a, b) { return a.note_offset - b.note_offset; }); let offset = 0; function inject(target, injected, position) { offset += injected.length; return noteText.substr(0, position) + injected + noteText.substr(position); } for (const el of allTags) { 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 targetUrl; if (el.target_url) { targetUrl = el.target_url; } else { targetUrl = "app#" + el.target_note_id; } const linkHtml = '' + el.lnk_text + ''; noteText = noteText.substr(0, el.note_offset + offset) + noteText.substr(el.note_offset + offset + el.lnk_text.length); noteText = inject(noteText, linkHtml, el.note_offset + offset); offset -= el.lnk_text.length; } else if (el.type === 'image') { const type = el.is_png ? "png" : "jpg"; const imgHtml = 'Embedded Image'; noteText = inject(noteText, imgHtml, el.note_offset + offset); } } noteText = noteText.replace(/(?:\r\n|\r)/g, '\n'); noteText = noteText.replace(/(.+)\n/g, '

$1

'); noteText = noteText.replace(/\n/g, '


'); noteText = noteText.replace(/ /g, '  '); return noteText; }