import { Link, Text, View } from "@react-pdf/renderer";
import React from "react";
import ReactMarkdown from "react-markdown";
import z from "zod";
import { defineComponent } from "../define-component.js";
export const Wrapper = ({
children,
paragraphSpacing,
styles,
style,
}: {
children: any;
paragraphSpacing?: string;
styles: any;
style?: any;
}) => {
return (
{typeof children === "string" ? (
paragraphSpacing ? (
{props.children}
) : (
{props.children}
),
a: (props: any) => {
return (
{props.children}
);
},
strong: (props: any) => (
{props.children}
),
em: (props: any) => {props.children},
code: (props: any) => (
{props.children}
),
del: (props: any) => (
{props.children}
),
ul: (props: any) => {props.children},
ol: (props: any) => {props.children},
li: (props: any) => (
{props.ordered ? `${(props.index ?? 0) + 1}. ` : "• "}
{props.children}
),
}}
>
{children}
) : (
children
)}
);
};
export const markdownComponent = defineComponent({
name: "markdown",
schema: z.object({}),
additionalProps: z.object({
children: z.any(),
style: z.any().nullish(),
paragraphSpacing: z.string().optional(),
}),
// https://www.npmjs.com/package/react-markdown#appendix-b-components
component: ({ children, styles, style, paragraphSpacing }) => {
if (!children) return null;
if (typeof children !== "string" && !Array.isArray(children))
return children;
return Array.isArray(children) ? (
children.map((item, index) => (
))
) : (
);
},
defaultStyles: {
link: { color: "black", textDecoration: "none" },
paragraph: {},
strong: { fontWeight: "bold" },
em: { fontStyle: "italic" },
code: { fontFamily: "Courier" },
del: { textDecoration: "line-through" },
ul: { marginLeft: 10 },
ol: { marginLeft: 10 },
li: { flexDirection: "row" },
liBullet: { width: 10 },
liContent: { flex: 1 },
} as const,
});