import style from "./content-markdown.module.css" import { createResource, createSignal } from "solid-js" import { createOverflow } from "./common" import { transformerNotationDiff } from "@shikijs/transformers" import { marked } from "marked" import markedShiki from "marked-shiki" import { codeToHtml } from "shiki" const markedWithShiki = marked.use( markedShiki({ highlight(code, lang) { return codeToHtml(code, { lang: lang || "text", themes: { light: "github-light", dark: "github-dark", }, transformers: [transformerNotationDiff()], }) }, }), ) interface Props { text: string expand?: boolean highlight?: boolean } export function ContentMarkdown(props: Props) { const [html] = createResource( () => strip(props.text), async (markdown) => { return markedWithShiki.parse(markdown) }, ) const [expanded, setExpanded] = createSignal(false) const overflow = createOverflow() return (
{!props.expand && overflow.status && ( )}
) } function strip(text: string): string { const wrappedRe = /^\s*<([A-Za-z]\w*)>\s*([\s\S]*?)\s*<\/\1>\s*$/ const match = text.match(wrappedRe) return match ? match[2] : text }