Code.tsx 767 B

12345678910111213141516171819202122232425
  1. import Example from '@/components/Example';
  2. import CodeBlock from '@/components/CodeBlock';
  3. import { iconsVersion, uiCdnUrl } from '@/config/site';
  4. export function Code({ children, ...props }) {
  5. return <code {...props}>{children}</code>;
  6. }
  7. export function Pre({ children, ...props }) {
  8. const language = (children.props.className || '').replace(/^language-/, ''),
  9. html = ([...children.props.children].join('') || '')
  10. .replace(/\$TABLER_CDN/g, uiCdnUrl)
  11. .replace(/\$ICONS_VERSION/g, iconsVersion);
  12. if (props.example) {
  13. return (
  14. <>
  15. <Example html={html} {...props} />
  16. {props.code && <CodeBlock html={html} language={language} hideLinks />}
  17. </>
  18. );
  19. }
  20. return <CodeBlock html={html} language={language} />;
  21. }