Openstatus
www.openstatus.dev
1import type { AnchorHTMLAttributes, HTMLAttributes } from "react";
2import { Fragment, createElement } from "react";
3import { jsx, jsxs } from "react/jsx-runtime";
4import rehypeReact from "rehype-react";
5import remarkParse from "remark-parse";
6import remarkRehype from "remark-rehype";
7import { unified } from "unified";
8
9export function ProcessMessage({ value }: { value: string }) {
10 const result = unified()
11 .use(remarkParse)
12 .use(remarkRehype)
13 .use(rehypeReact, {
14 createElement,
15 Fragment,
16 jsx,
17 jsxs,
18 components: {
19 ul: (props: HTMLAttributes<HTMLUListElement>) => {
20 return (
21 <ul
22 className="list-inside list-disc marker:text-muted-foreground/50"
23 {...props}
24 />
25 );
26 },
27 ol: (_props: HTMLAttributes<HTMLOListElement>) => {
28 return (
29 <ol className="list-inside list-decimal marker:text-muted-foreground/50" />
30 );
31 },
32 a: (props: AnchorHTMLAttributes<HTMLAnchorElement>) => {
33 return (
34 <a
35 target="_blank"
36 rel="noreferrer"
37 className="rounded-sm underline outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50"
38 {...props}
39 />
40 );
41 },
42 } as { [key: string]: React.ComponentType<unknown> },
43 })
44 .processSync(value).result;
45
46 return result;
47}