import { cn } from "@/commons"; import { nanoid } from "nanoid"; import { type ReactNode, useMemo } from "react"; import reactStringReplace from "react-string-replace"; import { Hashtag } from "./mentions/hashtag"; import { MentionNote } from "./mentions/note"; import { MentionUser } from "./mentions/user"; import { ImagePreview } from "./preview/image"; import { useNoteContext } from "./provider"; export function NoteContentLarge({ className, }: { className?: string; }) { const event = useNoteContext(); const content = useMemo(() => { try { // Get parsed meta const { images, hashtags, events, mentions } = event.meta; // Define rich content let richContent: ReactNode[] | string = event.content; for (const hashtag of hashtags) { const regex = new RegExp(`(|^)${hashtag}\\b`, "g"); richContent = reactStringReplace(richContent, regex, () => ( )); } for (const event of events) { richContent = reactStringReplace(richContent, event, (match, i) => ( )); } for (const mention of mentions) { richContent = reactStringReplace(richContent, mention, (match, i) => ( )); } for (const image of images) { richContent = reactStringReplace(richContent, image, (match, i) => ( )); } richContent = reactStringReplace( richContent, /(https?:\/\/\S+)/gi, (match, i) => ( {match} ), ); richContent = reactStringReplace(richContent, /(\r\n|\r|\n)+/g, () => (
)); return richContent; } catch { return event.content; } }, [event.content]); return (
{content}
); }