From 2c16f701117f933c2f945d61ae3f0355042c35d0 Mon Sep 17 00:00:00 2001 From: dawn <90008@gaze.systems> Date: Sat, 30 May 2026 06:53:18 +0300 Subject: [PATCH] make tangled.org links navigate to untangled --- src/components/repo.tsx | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/src/components/repo.tsx b/src/components/repo.tsx index 90b8f09..7d57996 100644 --- a/src/components/repo.tsx +++ b/src/components/repo.tsx @@ -27,7 +27,7 @@ import { GitPullRequest, } from 'lucide-solid'; import { marked } from 'marked'; -import { A } from '@solidjs/router'; +import { A, useNavigate } from '@solidjs/router'; import { For, Show, createEffect, createMemo, createSignal, onCleanup, onMount, type Component, type JSX } from 'solid-js'; import type { RepoContext, TreeEntry } from '../lib/api/repos'; import type { Did } from '@atcute/lexicons/syntax'; @@ -901,6 +901,8 @@ export const CommentCard: Component<{ ); export const MarkdownBlock: Component<{ markdown: string; variant?: 'default' | 'readme' | 'code' }> = (props) => { + const navigate = useNavigate(); + const html = createMemo(() => DOMPurify.sanitize(marked.parse(props.markdown, { async: false }) as string, { ADD_ATTR: ['class'], @@ -914,7 +916,33 @@ export const MarkdownBlock: Component<{ markdown: string; variant?: 'default' | : 'prose prose-sm sm:prose-base min-w-0 max-w-none break-words untangled-anywhere dark:prose-invert prose-p:text-gray-800 dark:prose-p:text-gray-200 prose-li:text-gray-800 dark:prose-li:text-gray-200 prose-pre:max-w-full prose-pre:overflow-x-auto prose-pre:rounded-md prose-pre:bg-gray-950 dark:prose-pre:bg-gray-950 prose-code:break-words prose-a:break-all', ); - return
; + const onMarkdownClick = (event: MouseEvent) => { + const anchor = (event.target as HTMLElement).closest('a'); + if (!anchor || event.defaultPrevented) { + return; + } + + const href = anchor.getAttribute('href'); + if (!href || !href.startsWith('https://tangled.org/')) { + return; + } + + if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + + try { + const url = new URL(href); + if (url.hostname === 'tangled.org') { + event.preventDefault(); + navigate(url.pathname + url.search + url.hash); + } + } catch { + // ignore + } + }; + + return ; }; const splitCodeLines = (value: string): string[] => { -- 2.51.2