mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-03 20:06:08 +01:00 
			
		
		
		
	fixed major rendering problem with mixed links and formattings
This commit is contained in:
		@@ -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 />');
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user