diff --git a/README.md b/README.md index e80bfff7..32494f9e 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ Bugs - [ ] Fix scrolling on note detail -- [ ] Ellipsize and hyperlink links - [ ] Be sure to deduplicate all events if needed - [ ] Format text with line breaks - pre, or split/br - [ ] Remove dexie, or use it instead of localstorage for cached data diff --git a/src/partials/Note.svelte b/src/partials/Note.svelte index 6f0883c7..673cf1d8 100644 --- a/src/partials/Note.svelte +++ b/src/partials/Note.svelte @@ -4,7 +4,7 @@ import {fly} from 'svelte/transition' import {navigate} from 'svelte-routing' import {ellipsize} from 'hurdak/src/core' - import {hasParent} from 'src/util/html' + import {hasParent, toHtml} from 'src/util/html' import Anchor from 'src/partials/Anchor.svelte' import {dispatch} from "src/state/dispatch" import {accounts, modal} from "src/state/app" @@ -14,6 +14,7 @@ export let note export let isReply = false + export let showEntire = false export let interactive = false export let invertColors = false @@ -105,7 +106,13 @@ Reply to {parentId.slice(0, 8)} {/if} -

{ellipsize(note.content, 240)}

+

+ {#if note.content.length > 240 && !showEntire} + {ellipsize(note.content, 240)} + {:else} + {@html toHtml(note.content)} + {/if} +

{#if note.pubkey} - + {#each note.replies as r (r.id)}
diff --git a/src/routes/ChatRoom.svelte b/src/routes/ChatRoom.svelte index 0a7f2a95..73db323b 100644 --- a/src/routes/ChatRoom.svelte +++ b/src/routes/ChatRoom.svelte @@ -5,6 +5,7 @@ import {prop, last} from 'ramda' import {switcherFn} from 'hurdak/src/core' import {formatTimestamp} from 'src/util/misc' + import {toHtml} from 'src/util/html' import UserBadge from 'src/partials/UserBadge.svelte' import {channels} from 'src/state/nostr' import {rooms, accounts, ensureAccounts} from 'src/state/app' @@ -117,7 +118,7 @@

{formatTimestamp(m.created_at)}

{/if} -
{m.content}
+
{@html toHtml(m.content)}
{/each} diff --git a/src/util/html.js b/src/util/html.js index 929f2982..6d0425b6 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -60,3 +60,19 @@ export const hasParent = (tagOrClass, $el) => { return false } + +export const escapeHtml = html => { + const div = document.createElement("div") + + div.innerText = html + + return div.innerHTML +} + +export const toHtml = content => { + return escapeHtml(content) + .replace(/\n/g, '
') + .replace(/https?:\/\/([\w\.-]+)[^ ]*/g, (url, domain) => { + return `${domain}` + }) +}