import { useContextFix } from "@/hooks/useContentFix"; import { Badge, Container, Group, Text, Title, TypographyStylesProvider, } from "@mantine/core"; import dayjs from "dayjs"; import relativeTime from "dayjs/plugin/relativeTime"; import { useLoaderData } from "react-router"; import { Link } from "react-router-dom"; function stripStyles(content: string) { const element = document.createElement("div"); element.innerHTML = content; element.querySelectorAll("*").forEach((el) => { if (!(el instanceof HTMLElement)) return; [ "outline", "color", "font-size", "font-family", "background-color", "border-width", "border-style", "border-color", "counter-reset", "max-width", "caret-color", "letter-spacing", "white-space", "text-size-adjust", "box-sizing", "line-height", "overflow-wrap", ].forEach((key) => el.style.removeProperty(key)); if ( el.tagName === "P" && el.childElementCount === 1 && (el.children[0].tagName === "BR" || (el.children[0].tagName === "SPAN" && el.children[0].childElementCount === 1 && el.children[0].children[0].tagName === "BR")) ) { el.parentElement?.removeChild(el); } }); return element.innerHTML; } dayjs.extend(relativeTime); export default function ParagraphPage() { const paragraph = useLoaderData() as Paragraph; let content = stripStyles(paragraph.content); content = useContextFix(content); return ( {paragraph.title} {" "} {dayjs().to(dayjs(paragraph.time))} {paragraph.author} {paragraph.tags.map((tag, index) => ( <> {tag} ))} {paragraph.source_url && ( Goto Source )}
); }