Highlighter

The Highlighter component is used to display syntax-highlighted code blocks. It takes in the code content as a string and the language of the code as a string. The component allows users to copy the code content and can also display the language tag. The code block can have a background and the theme can be set to either 'dark' or 'light'.

import { Highlighter } from '@lobehub/ui';

Default

tsx
export default ({ children, className }: MarkdownProps) => {
  const { styles } = useStyles();
  return (
    <ReactMarkdown
      className={cx(styles.container, className)}
      components={{ pre: CodeBlock, code: Code }}
    >
      {children}
    </ReactMarkdown>
  );
}
tsx
export default ({ children, className }: MarkdownProps) => {
  const { styles } = useStyles();
  return (
    <ReactMarkdown
      className={cx(styles.container, className)}
      components={{ pre: CodeBlock, code: Code }}
    >
      {children}
    </ReactMarkdown>
  );
}

Actions Render

tsx
export default ({ children, className }: MarkdownProps) => {
  const { styles } = useStyles();
  return (
    <ReactMarkdown
      className={cx(styles.container, className)}
      components={{ pre: CodeBlock, code: Code }}
    >
      {children}
    </ReactMarkdown>
  );
}

APIs

NameDescriptionTypeDefault
actionsRender--(props:{ actionIconSize: any; content: string; language: string; originalNode: React.ReactNode; })=>ReactNode--
allowChangeLanguage--boolean--
bodyRender--(props:{ content: string; language: string; originalNode: React.ReactNode; })=>ReactNode--
childrenThe code content to be highlightedstring(required)
copyButtonSize--any--
copyableWhether to show the copy buttonbooleantrue
defalutExpandWhether to expand code blocks by defaultbooleantrue
fileName--string--
fullFeatured--boolean--
icon--ReactNode--
languageThe language of the code contentstring(required)
showLanguageWhether to show language tagbooleantrue
spotlightWhether add spotlight backgroundbooleanfalse
typeThe type of the code block"ghost"|"block"|"pure""block"
wrap--boolean--