import { normalizeImagePath } from '@rspress/core/runtime'; import { renderHtmlOrText } from '@rspress/core/theme'; /** * Check if a string is a URL or file path */ function isUrlOrPath(str: string): boolean { return ( str.startsWith('/') || str.startsWith('./') || str.startsWith('../') || str.startsWith('http://') || str.startsWith('https://') || str.startsWith('data:') ); } export type SvgWrapperProps = { icon: string | React.FC>; } & React.SVGProps; /** * A wrapper for custom SVG icon. * When the user uses a custom SVG, the imported icon can be a string or a React component. * - React component: render directly * - SVG string (starts with `` * - Other strings (emoji/text/HTML): render with renderHtmlOrText * @internal */ export function SvgWrapper({ icon: Icon, ...rest }: SvgWrapperProps) { if (!Icon) { return null; } if (typeof Icon === 'string') { const { className } = rest; // SVG inline string if (Icon.trim().startsWith(' ); } // URL or file path if (isUrlOrPath(Icon)) { return ( ); } // Fallback: emoji/text/HTML return ; } return ; }