diff --git a/src/components/EmbeddedNote/EmbeddedNote.tsx b/src/components/EmbeddedNote/EmbeddedNote.tsx index b635cbe..3e35490 100644 --- a/src/components/EmbeddedNote/EmbeddedNote.tsx +++ b/src/components/EmbeddedNote/EmbeddedNote.tsx @@ -176,7 +176,7 @@ const EmbeddedNote: Component<{ note: PrimalNote, mentionedUsers?: Record { +export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly?: 'links' | 'text') => { const regex = /\bnostr:((npub|nprofile)1\w+)\b|#\[(\d+)\]/g; @@ -80,14 +80,16 @@ export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly = f const user = note.mentionedUsers && note.mentionedUsers[hex]; - let link = highlightOnly ? - @{truncateNpub(npub)} : - @{truncateNpub(npub)}; + const label = user ? userName(user) : truncateNpub(npub); - if (user) { - link = highlightOnly ? - @{userName(user)} : - MentionedUserLink({ user }); + let link = @{label}; + + if (highlightOnly === 'links') { + link = @{label}; + } + + if (!highlightOnly) { + link = user ? @{label} : MentionedUserLink({ user }); } // @ts-ignore @@ -99,7 +101,13 @@ export const parseNpubLinks = (text: string, note: PrimalNote, highlightOnly = f }; -const ParsedNote: Component<{ note: PrimalNote, ignoreMentionedNotes?: boolean, id?: string }> = (props) => { +const ParsedNote: Component<{ + note: PrimalNote, + ignoreMentionedNotes?: boolean, + id?: string, + ignoreMedia?: boolean, + noLinks?: 'links' | 'text', +}> = (props) => { const media = useMediaContext(); @@ -156,12 +164,17 @@ const ParsedNote: Component<{ note: PrimalNote, ignoreMentionedNotes?: boolean, }; - const highlightHashtags = (text: string) => { + const highlightHashtags = (text: string, noLinks?: 'links' | 'text') => { const regex = /(?:\s|^)#[^\s!@#$%^&*(),.?":{}|<>]+/ig; return text.replace(regex, (token) => { const [space, term] = token.split('#'); - const embeded = ( + const embeded = noLinks === 'text' ? ( + + {space} + #{term} + + ) : ( {space} (content()); + const smallContent = () => { + return parseNoteLinks( + parseNpubLinks( + parsedContent( + highlightHashtags( + props.note.post.content, + props.noLinks, + ), + ), + props.note, + props.noLinks, + ), + props.note, + ); + }; + + const [displayedContent, setDisplayedContent] = createSignal(props.ignoreMedia ? smallContent() : content()); createEffect(() => { const newContent = replaceLinkPreviews(displayedContent(), { ...linkPreviews }); diff --git a/src/components/SmallNote/SmallNote.tsx b/src/components/SmallNote/SmallNote.tsx index c0d6ff1..005bf44 100644 --- a/src/components/SmallNote/SmallNote.tsx +++ b/src/components/SmallNote/SmallNote.tsx @@ -10,6 +10,7 @@ import { authorName } from '../../stores/profile'; import { note as t } from '../../translations'; import { useIntl } from '@cookbook/solid-intl'; import { hookForDev } from '../../lib/devTools'; +import ParsedNote from '../ParsedNote/ParsedNote'; const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: string }> = (props) => { @@ -95,7 +96,8 @@ const SmallNote: Component<{ note: PrimalNote, children?: JSXElement, id?: strin