feat: resolve NIP-19 identifiers in article content

- Add nostrUriResolver utility to detect and replace nostr: URIs
- Support npub, note, nprofile, nevent, and naddr identifiers
- Convert nostr: URIs to clickable njump.me links
- Process markdown before rendering to handle nostr mentions
- Add CSS styling for nostr-uri-link class
- Implements NIP-19 and NIP-27 (nostr: URI scheme)

Nostr-native articles can now contain references like:
- nostr:npub1... → @npub1abc...
- nostr:note1... → note:note1abc...
- nostr:naddr1... → article:identifier

All identifiers become clickable links to njump.me
This commit is contained in:
Gigi
2025-10-11 01:42:03 +01:00
parent 6783ff23f9
commit 8a69d5bc6b
4 changed files with 167 additions and 4 deletions

View File

@@ -1,18 +1,30 @@
import React, { useState, useEffect, useRef } from 'react'
import { replaceNostrUrisInMarkdown } from '../utils/nostrUriResolver'
/**
* Hook to convert markdown to HTML using a hidden ReactMarkdown component
* Also processes nostr: URIs in the markdown
*/
export const useMarkdownToHTML = (markdown?: string): { renderedHtml: string, previewRef: React.RefObject<HTMLDivElement> } => {
export const useMarkdownToHTML = (markdown?: string): {
renderedHtml: string
previewRef: React.RefObject<HTMLDivElement>
processedMarkdown: string
} => {
const previewRef = useRef<HTMLDivElement>(null)
const [renderedHtml, setRenderedHtml] = useState<string>('')
const [processedMarkdown, setProcessedMarkdown] = useState<string>('')
useEffect(() => {
if (!markdown) {
setRenderedHtml('')
setProcessedMarkdown('')
return
}
// Process nostr: URIs in markdown before rendering
const processed = replaceNostrUrisInMarkdown(markdown)
setProcessedMarkdown(processed)
console.log('📝 Converting markdown to HTML...')
const rafId = requestAnimationFrame(() => {
@@ -28,7 +40,7 @@ export const useMarkdownToHTML = (markdown?: string): { renderedHtml: string, pr
return () => cancelAnimationFrame(rafId)
}, [markdown])
return { renderedHtml, previewRef }
return { renderedHtml, previewRef, processedMarkdown }
}
// Removed separate useMarkdownPreviewRef; use useMarkdownToHTML to obtain previewRef