import { MarkdownProps } from "../TextEditor"; import { sanitizeProps } from "../../../../features/apps/text-editor/_utils/sanitizeProps"; import { Attributes, Children, cloneElement, DetailedHTMLProps, isValidElement, ReactNode } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faExclamationCircle, faExclamationTriangle, faInfoCircle, faLightbulb } from "@fortawesome/free-solid-svg-icons"; import styles from "../TextEditor.module.css"; type Props = Partial & Attributes & { children: ReactNode, className?: string }; export function MarkdownBlockquote({ children, ...props }: MarkdownProps) { sanitizeProps(props); const formatContent = (children: ReactNode): [ReactNode, string | null] => { if (!children) return [null, null]; let alertType: string | null = null; children = Children.map(children, (child) => { if (isValidElement(child)) { const { children, ...props } = child.props as Props; const [newChildren, childAlertType] = formatContent(children); if (childAlertType != null) props.className = `${styles.AlertContainer} ${styles[childAlertType + "Alert"]}`; return cloneElement(child, { ...props, children: newChildren, } as Props); } else if (typeof child !== "string") { return child; } switch (child) { case "[!IMPORTANT]": child = Important ; alertType = "Important"; break; case "[!NOTE]": child = Note ; alertType = "Note"; break; case "[!TIP]": child = Tip ; alertType = "Tip"; break; case "[!WARNING]": child = Warning ; alertType = "Warning"; break; case "[!CAUTION]": child = Caution ; alertType = "Caution"; break; } return child; }); return [children, alertType]; }; return
, HTMLQuoteElement>)} className={styles.MarkdownBlockquote} > {formatContent(children)[0]}
; }