aboutsummaryrefslogtreecommitdiff
path: root/apps/web/app/(dash)/chat/markdownRenderHelpers.tsx
blob: 747d4fca18119fa62bb29f9d5863d7f965a901b9 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { DetailedHTMLProps, HTMLAttributes, memo } from "react";
import { ExtraProps } from "react-markdown";
import CodeBlock from "./CodeBlock";

export const code = memo((props: JSX.IntrinsicElements["code"]) => {
  const { className, children } = props;
  const match = /language-(\w+)/.exec(className || "");
  const lang = match && match[1];

  return <CodeBlock lang={lang || "text"} codeChildren={children as any} />;
});

export const p = memo(
  (
    props?: Omit<
      DetailedHTMLProps<
        HTMLAttributes<HTMLParagraphElement>,
        HTMLParagraphElement
      >,
      "ref"
    >,
  ) => {
    return <p className="whitespace-pre-wrap">{props?.children}</p>;
  },
);