(
props: ComponentPropsWithoutRef<"pre"> & { children?: ReactNode; node?: unknown },
)
| 27 | } |
| 28 | |
| 29 | function PreBlock( |
| 30 | props: ComponentPropsWithoutRef<"pre"> & { children?: ReactNode; node?: unknown }, |
| 31 | ) { |
| 32 | const child = Children.toArray(props.children)[0]; |
| 33 | if ( |
| 34 | isValidElement(child) && |
| 35 | (child.type === "code" || (child.props as Record<string, unknown>)?.className) |
| 36 | ) { |
| 37 | const childProps = child.props as { className?: string; children?: ReactNode }; |
| 38 | const lang = childProps.className?.replace("language-", "") ?? undefined; |
| 39 | const code = extractText(childProps.children).replace(/\n$/, ""); |
| 40 | return <CodeBlock code={code} lang={lang} className="my-2" />; |
| 41 | } |
| 42 | return <pre>{props.children}</pre>; |
| 43 | } |
| 44 | |
| 45 | function Link(props: ComponentPropsWithoutRef<"a"> & { children?: ReactNode; node?: unknown }) { |
| 46 | const { children, href, node: _node, ...rest } = props; |
nothing calls this directly
no test coverage detected