import type { PluginTheme } from "@getpaseo/plugin"; import { openExternalUrl } from "@getpaseo/plugin/client"; import React, { useMemo } from "react"; import { StyleSheet, Text, View } from "react-native"; import { parseInline, parseMarkdown, type Block, type Inline } from "../shared/diagram/markdown"; export function MarkdownText({ text, theme, compact = false, color, }: { text: string; theme: PluginTheme; compact?: boolean; color?: string; }) { const blocks = useMemo(() => parseMarkdown(text), [text]); return ( {blocks.map((block, index) => ( ))} ); } /** One line of inline Markdown (links, emphasis, code), nested inside a caller's styled Text. */ export function InlineMarkdown({ text, theme }: { text: string; theme: PluginTheme }) { const content = useMemo(() => parseInline(text), [text]); return ; } function BlockView({ block, theme, color, }: { block: Block; theme: PluginTheme; color?: string; }) { const body = { color: color ?? theme.colors.foreground, fontSize: 13.5, lineHeight: 20, }; if (block.kind === "rule") { return ( ); } if (block.kind === "code") { return ( {block.text} ); } if (block.kind === "heading") { return ( ); } if (block.kind === "quote") { return ( ); } if (block.kind === "bullet" || block.kind === "ordered") { return ( {block.items.map((item, index) => ( {block.kind === "bullet" ? "•" : `${block.start + index}.`} ))} ); } return ( ); } function Spans({ content, theme }: { content: Inline[]; theme: PluginTheme }) { return ( <> {content.map((span, index) => { if (span.kind === "bold") { return ( {span.text} ); } if (span.kind === "italic") { return ( {span.text} ); } if (span.kind === "code") { return ( {span.text} ); } if (span.kind === "link") { return ( void openExternalUrl(span.url)} style={{ color: theme.colors.accent, textDecorationLine: "underline" }} > {span.text} ); } return {span.text}; })} ); }