diff --git a/src/relay/index.js b/src/relay/index.js index 18b7fab6..e4bf12ae 100644 --- a/src/relay/index.js +++ b/src/relay/index.js @@ -1,9 +1,8 @@ import {liveQuery} from 'dexie' -import extractUrls from 'extract-urls' import {get} from 'svelte/store' import {uniq, pluck, intersection, sortBy, propEq, uniqBy, groupBy, concat, without, prop, isNil, identity} from 'ramda' -import {ensurePlural, first, createMap, ellipsize} from 'hurdak/lib/hurdak' -import {escapeHtml} from 'src/util/html' +import {ensurePlural, createMap, ellipsize} from 'hurdak/lib/hurdak' +import {renderContent} from 'src/util/html' import {filterTags, displayPerson, getTagValues, findReply, findRoot} from 'src/util/nostr' import {db} from 'src/relay/db' import pool from 'src/relay/pool' @@ -155,23 +154,8 @@ const renderNote = async (note, {showEntire = false}) => { // Ellipsize content = shouldEllipsize ? ellipsize(note.content, 500) : note.content - // Escape html - content = escapeHtml(content) - - // Extract urls - for (const url of extractUrls(content) || []) { - const $a = document.createElement('a') - - $a.href = url - $a.target = "_blank noopener" - $a.className = "underline" - - /* eslint no-useless-escape: 0 */ - $a.innerText = first(url.replace(/https?:\/\/(www\.)?/, '').split(/[\/\?#]/)) - - // If the url is on its own line, remove it entirely. Otherwise, replace it with the link - content = content.replace(url, $a.outerHTML) - } + // Escape html, replace urls + content = renderContent(content) // Mentions content = content diff --git a/src/routes/Person.svelte b/src/routes/Person.svelte index 10fd31b4..154d32a4 100644 --- a/src/routes/Person.svelte +++ b/src/routes/Person.svelte @@ -4,6 +4,7 @@ import {fly} from 'svelte/transition' import {navigate} from 'svelte-routing' import {now} from 'src/util/misc' + import {renderContent} from 'src/util/html' import {displayPerson} from 'src/util/nostr' import Tabs from "src/partials/Tabs.svelte" import Button from "src/partials/Button.svelte" @@ -67,7 +68,7 @@ {/if} -

{getPerson().about || ''}

+

{@html renderContent(getPerson().about || '')}

{#if $user?.pubkey === pubkey} diff --git a/src/util/html.js b/src/util/html.js index ee765f4f..1855fc2f 100644 --- a/src/util/html.js +++ b/src/util/html.js @@ -1,3 +1,6 @@ +import extractUrls from 'extract-urls' +import {first} from 'hurdak/lib/hurdak' + export const copyToClipboard = text => { const {activeElement} = document const input = document.createElement("textarea") @@ -84,3 +87,25 @@ export const fromParentOffset = (element, offset) => { offset -= child.textContent.length } } + +export const renderContent = content => { + // Escape html + content = escapeHtml(content) + + // Extract urls + for (const url of extractUrls(content) || []) { + const $a = document.createElement('a') + + $a.href = url + $a.target = "_blank noopener" + $a.className = "underline" + + /* eslint no-useless-escape: 0 */ + $a.innerText = first(url.replace(/https?:\/\/(www\.)?/, '').split(/[\/\?#]/)) + + // If the url is on its own line, remove it entirely. Otherwise, replace it with the link + content = content.replace(url, $a.outerHTML) + } + + return content +} diff --git a/src/views/SearchPeople.svelte b/src/views/SearchPeople.svelte index 4af8e8ab..9c295145 100644 --- a/src/views/SearchPeople.svelte +++ b/src/views/SearchPeople.svelte @@ -1,7 +1,9 @@