From 98723a25aa9c2118d6dc18d9706106f3b689892b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Mon, 15 Dec 2025 16:59:57 +0100 Subject: [PATCH] refactor: consolidate markdown renderer --- src/components/Markdown.tsx | 233 --------------------------------- src/components/NipRenderer.tsx | 4 +- 2 files changed, 2 insertions(+), 235 deletions(-) delete mode 100644 src/components/Markdown.tsx diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx deleted file mode 100644 index 703d1b2..0000000 --- a/src/components/Markdown.tsx +++ /dev/null @@ -1,233 +0,0 @@ -import ReactMarkdown from "react-markdown"; -import type { Components } from "react-markdown"; -import { useMemo } from "react"; -import { useGrimoire } from "@/core/state"; -import { MediaEmbed } from "@/components/nostr/MediaEmbed"; -import remarkGfm from "remark-gfm"; - -interface MarkdownProps { - content: string; - className?: string; -} - -export function Markdown({ content, className = "" }: MarkdownProps) { - const { addWindow } = useGrimoire(); - - const components: Components = useMemo( - () => ({ - // Headings - h1: ({ children }) => ( -

- {children} -

- ), - h2: ({ children }) => ( -

- {children} -

- ), - h3: ({ children }) => ( -

- {children} -

- ), - h4: ({ children }) => ( -

- {children} -

- ), - h5: ({ children }) => ( -
- {children} -
- ), - h6: ({ children }) => ( -
- {children} -
- ), - - // Paragraphs and text - p: ({ children }) => ( -

- {children} -

- ), - - // Links - a: ({ href, children }) => { - console.log("[Markdown Link]", { href, children }); - - // Check if it's a relative NIP link (e.g., "./01.md" or "01.md" or "30.md") - // Must be relative (not start with http:// or https://) - const isRelativeLink = - href && !href.startsWith("http://") && !href.startsWith("https://"); - if (isRelativeLink && (href.endsWith(".md") || href.includes(".md#"))) { - console.log("[Markdown] Detected relative .md link:", href); - - // Extract NIP number from various formats (numeric 1-3 digits or hex A0-FF) - const nipMatch = href.match(/([0-9A-F]{1,3})\.md/i); - console.log("[Markdown] Regex match result:", nipMatch); - - if (nipMatch) { - const nipNumber = nipMatch[1].toUpperCase(); - console.log("[Markdown] Creating NIP link for NIP-" + nipNumber); - - return ( - { - e.preventDefault(); - e.stopPropagation(); - console.log("[Markdown] NIP link clicked! NIP-" + nipNumber); - console.log("[Markdown] Calling addWindow directly"); - addWindow("nip", { number: nipNumber }, `NIP ${nipNumber}`); - console.log("[Markdown] addWindow called"); - }} - className="text-accent underline decoration-dotted cursor-crosshair hover:text-accent/80 transition-colors" - > - {children} - - ); - } - } - - // Regular external link - console.log("[Markdown] Creating regular external link for:", href); - return ( - - {children} - - ); - }, - - // Lists - ul: ({ children }) => ( - - ), - ol: ({ children }) => ( -
    - {children} -
- ), - li: ({ children }) => ( -
  • - {children} -
  • - ), - - // Blockquotes - blockquote: ({ children }) => ( -
    - {children} -
    - ), - - // Code - code: (props) => { - const { children, className } = props; - const inline = !className?.includes("language-"); - - return inline ? ( - - {children} - - ) : ( - - {children} - - ); - }, - pre: ({ children }) =>
    {children}
    , - - // Horizontal rule - hr: () =>
    , - - // Tables - table: ({ children }) => ( -
    - - {children} -
    -
    - ), - thead: ({ children }) => {children}, - tbody: ({ children }) => {children}, - tr: ({ children }) => ( - {children} - ), - th: ({ children }) => ( - - {children} - - ), - td: ({ children }) => ( - {children} - ), - - // Images - Inline with zoom - img: ({ src, alt }) => - src ? ( - - ) : null, - - // Emphasis - strong: ({ children }) => ( - {children} - ), - em: ({ children }) => {children}, - }), - [addWindow], - ); - - return ( -
    - - {content} - -
    - ); -} diff --git a/src/components/NipRenderer.tsx b/src/components/NipRenderer.tsx index 0ac0220..7051b4e 100644 --- a/src/components/NipRenderer.tsx +++ b/src/components/NipRenderer.tsx @@ -1,5 +1,5 @@ import { useNip } from "@/hooks/useNip"; -import { Markdown } from "./Markdown"; +import { MarkdownContent } from "./nostr/MarkdownContent"; import { KindBadge } from "./KindBadge"; import { getKindsForNip } from "@/lib/nip-kinds"; @@ -38,7 +38,7 @@ export function NipRenderer({ nipId, className = "" }: NipRendererProps) { return (
    - + {kinds.length > 0 && (