From 88e34441b81f34a1980d94a218c4862c4d9b3b8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20G=C3=B3mez?= Date: Wed, 10 Dec 2025 16:29:48 +0100 Subject: [PATCH] feat: markdown tables --- src/components/Markdown.tsx | 18 ++++++++++++------ src/components/nostr/RichText/Text.tsx | 15 +++++++++------ src/main.tsx | 9 +++------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/components/Markdown.tsx b/src/components/Markdown.tsx index cf5635d..25cc903 100644 --- a/src/components/Markdown.tsx +++ b/src/components/Markdown.tsx @@ -3,6 +3,7 @@ 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; @@ -79,15 +80,18 @@ export function Markdown({ content, className = "" }: MarkdownProps) { console.log("[Markdown Link]", { href, children }); // Check if it's a relative NIP link (e.g., "./01.md" or "01.md" or "30.md") - if (href && (href.endsWith(".md") || href.includes(".md#"))) { - console.log("[Markdown] Detected .md link:", href); + // 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 (1-3 digits) - const nipMatch = href.match(/(\d{1,3})\.md/); + // 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]; + const nipNumber = nipMatch[1].toUpperCase(); console.log("[Markdown] Creating NIP link for NIP-" + nipNumber); return ( @@ -221,7 +225,9 @@ export function Markdown({ content, className = "" }: MarkdownProps) { return (
- {content} + + {content} +
); } diff --git a/src/components/nostr/RichText/Text.tsx b/src/components/nostr/RichText/Text.tsx index 52d23bc..4ff4e91 100644 --- a/src/components/nostr/RichText/Text.tsx +++ b/src/components/nostr/RichText/Text.tsx @@ -12,23 +12,26 @@ function hasRTLCharacters(text: string): boolean { export function Text({ node }: TextNodeProps) { const text = node.value; - + // If no newlines, render as inline span if (!text.includes("\n")) { const isRTL = hasRTLCharacters(text); return {text || "\u00A0"}; } - - // If has newlines, use divs for proper RTL per line + + // If has newlines, use regular inline spans with
tags const lines = text.split("\n"); return ( <> {lines.map((line, idx) => { const isRTL = hasRTLCharacters(line); return ( -
- {line || "\u00A0"} -
+ <> + {idx > 0 &&
} + + {line || "\u00A0"} + + ); })} diff --git a/src/main.tsx b/src/main.tsx index 4549054..79076e3 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,4 +1,3 @@ -import { StrictMode } from "react"; import { createRoot } from "react-dom/client"; import { EventStoreProvider } from "applesauce-react/providers"; import Root from "./root"; @@ -10,9 +9,7 @@ import "react-mosaic-component/react-mosaic-component.css"; document.documentElement.classList.add("dark"); createRoot(document.getElementById("root")!).render( - - - - - , + + + , );