From c9b8e7869629df72184317fae4b5cee1ebfe6f96 Mon Sep 17 00:00:00 2001 From: Silberengel Date: Mon, 10 Nov 2025 20:46:02 +0100 Subject: [PATCH] reinstate the web previews --- .../Note/AsciidocArticle/AsciidocArticle.tsx | 43 ++++++++++++++++++- .../Note/MarkdownArticle/MarkdownArticle.tsx | 16 ++----- 2 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/components/Note/AsciidocArticle/AsciidocArticle.tsx b/src/components/Note/AsciidocArticle/AsciidocArticle.tsx index 94c9066..0c9164c 100644 --- a/src/components/Note/AsciidocArticle/AsciidocArticle.tsx +++ b/src/components/Note/AsciidocArticle/AsciidocArticle.tsx @@ -401,7 +401,12 @@ export default function AsciidocArticle({ const relayPath = `/relays/${encodeURIComponent(href)}` return `${linkText}` } - // For regular links, store original text for truncation in DOM manipulation + // For regular HTTP/HTTPS links, replace with WebPreview placeholder + if (href.startsWith('http://') || href.startsWith('https://')) { + const cleanedUrl = cleanUrl(href) + return `
` + } + // For other links (like relative links), keep as-is const escapedLinkText = linkText.replace(/"/g, '"') return match.replace(/ tags, not YouTube, not relay) - convert to WebPreview placeholders + const httpUrlRegex = /https?:\/\/[^\s<>"']+/g + htmlString = htmlString.replace(httpUrlRegex, (match) => { + // Only replace if not already in a tag (basic check) + if (!match.includes('<') && !match.includes('>')) { + // Skip if it's a YouTube URL or relay URL (already handled) + if (isYouTubeUrl(match) || isWebsocketUrl(match)) { + return match + } + // Skip if it's an image or media URL (handled separately) + if (isImage(match) || isVideo(match) || isAudio(match)) { + return match + } + const cleanedUrl = cleanUrl(match) + return `
` + } + return match + }) + setParsedHtml(htmlString) } catch (error) { logger.error('Failed to parse AsciiDoc', error as Error) @@ -539,6 +563,23 @@ export default function AsciidocArticle({ reactRootsRef.current.set(container, root) }) + // Process WebPreview placeholders - replace with React components + const webpreviewPlaceholders = contentRef.current.querySelectorAll('.webpreview-placeholder[data-webpreview-url]') + webpreviewPlaceholders.forEach((element) => { + const url = element.getAttribute('data-webpreview-url') + if (!url) return + + // Create a container for React component + const container = document.createElement('div') + container.className = 'my-2' + element.parentNode?.replaceChild(container, element) + + // Use React to render the component + const root = createRoot(container) + root.render() + reactRootsRef.current.set(container, root) + }) + // Process hashtags in text nodes - convert #tag to links const walker = document.createTreeWalker( contentRef.current, diff --git a/src/components/Note/MarkdownArticle/MarkdownArticle.tsx b/src/components/Note/MarkdownArticle/MarkdownArticle.tsx index 7cccddb..8f04e83 100644 --- a/src/components/Note/MarkdownArticle/MarkdownArticle.tsx +++ b/src/components/Note/MarkdownArticle/MarkdownArticle.tsx @@ -526,19 +526,11 @@ function parseMarkdownContent( ) } else { - // Render as green link (will show WebPreview at bottom for HTTP/HTTPS) + // Render as WebPreview component (shows opengraph data or fallback card) parts.push( -
e.stopPropagation()} - title={text.length > 200 ? text : undefined} - > - {displayText} - +
+ +
) } } else if (pattern.type === 'youtube-url') {