From e9d1592ba76ec5d9f75e0a00cc415d710c412ae6 Mon Sep 17 00:00:00 2001 From: Jonathan Staab Date: Thu, 30 Mar 2023 16:16:08 -0500 Subject: [PATCH] Fix some entity display stuff --- src/views/notes/NoteContent.svelte | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/views/notes/NoteContent.svelte b/src/views/notes/NoteContent.svelte index 8edf1582..86c42953 100644 --- a/src/views/notes/NoteContent.svelte +++ b/src/views/notes/NoteContent.svelte @@ -40,6 +40,8 @@ entities.push({type, value}) } + // If the link is surrounded by line breaks (or content start/end), remove + // the link along with trailing whitespace if ((!prev || prev.type === "br") && (!next || next.type === "br")) { let n = 0 @@ -56,12 +58,17 @@ } } - l += value.length + // Keep track of total characters, if we're not dealing with a string just guess + if (value instanceof String) { + l += value.length - if (shouldTruncate && l > 400 && type !== "br") { - content[i].value = value.trim() - content.splice(i + 1, content.length, {type: "text", value: "..."}) - break + if (shouldTruncate && l > 400 && type !== "br") { + content[i].value = value.trim() + content.splice(i + 1, content.length, {type: "text", value: "..."}) + break + } + } else { + l += 30 } } @@ -104,11 +111,9 @@ {value.replace(/https?:\/\/(www\.)?/, "")} {:else if type.startsWith("nostr:")} - + {#if value.pubkey} {displayPerson(getPersonWithFallback(value.pubkey))} - {:else if value.id} - event {value.id} {:else} {value.entity.slice(0, 10) + "..."} {/if}