MCPcopy Create free account
hub / github.com/Linen-dev/linen.dev / Code

Function Code

apps/web/ui/Code/index.tsx:15–65  ·  view source on GitHub ↗
({
  className,
  content,
  language,
  highlight,
  inline,
  block,
}: Props)

Source from the content-addressed store, hash-verified

13}
14
15function Code({
16 className,
17 content,
18 language,
19 highlight,
20 inline,
21 block,
22}: Props): JSX.Element {
23 const [highlighted, setHighlighted] = useState<any>();
24
25 useEffect(() => {
26 let mounted = true;
27 if (highlight && !highlighted) {
28 highlightCode(content, language).then((output) => {
29 if (mounted) {
30 setHighlighted(output);
31 }
32 });
33 }
34 return () => {
35 mounted = false;
36 };
37 }, [highlight, highlighted, language]);
38
39 if (highlighted) {
40 return (
41 <pre
42 className={classNames('hljs', styles.pre, className, {
43 [styles.block]: block,
44 [styles.inline]: inline,
45 })}
46 >
47 <code
48 className={styles.code}
49 dangerouslySetInnerHTML={{ __html: highlighted }}
50 />
51 </pre>
52 );
53 }
54
55 return (
56 <pre
57 className={classNames(styles.pre, className, {
58 [styles.block]: block,
59 [styles.inline]: inline,
60 })}
61 >
62 <code className={styles.code}>{content}</code>
63 </pre>
64 );
65}
66
67export default Code;

Callers

nothing calls this directly

Calls 1

highlightCodeFunction · 0.90

Tested by

no test coverage detected