diff options
Diffstat (limited to 'extension/react-app/src/components/CodeBlock.tsx')
-rw-r--r-- | extension/react-app/src/components/CodeBlock.tsx | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/extension/react-app/src/components/CodeBlock.tsx b/extension/react-app/src/components/CodeBlock.tsx index 98760fbd..b0de13ac 100644 --- a/extension/react-app/src/components/CodeBlock.tsx +++ b/extension/react-app/src/components/CodeBlock.tsx @@ -61,9 +61,55 @@ function CopyButton(props: { textToCopy: string; visible: boolean }) { ); } -function CodeBlock(props: { language?: string; children: string }) { +function CodeBlock(props: { children: string }) { + const [result, setResult] = useState<AutoHighlightResult | undefined>( + undefined + ); useEffect(() => { - hljs.highlightAll(); + const result = hljs.highlightAuto( + (props.children as any).props.children[0], + [ + "python", + "javascript", + "typescript", + "bash", + "html", + "css", + "json", + "yaml", + "markdown", + "sql", + "java", + "c", + "cpp", + "csharp", + "go", + "kotlin", + "php", + "ruby", + "rust", + "scala", + "swift", + "dart", + "haskell", + "perl", + "r", + "matlab", + "powershell", + "lua", + "elixir", + "clojure", + "groovy", + "julia", + "vbnet", + "objectivec", + "fsharp", + "erlang", + "ocaml", + ] + ); + console.log(result); + setResult(result); }, [props.children]); const [hovered, setHovered] = useState<boolean>(false); @@ -82,7 +128,9 @@ function CodeBlock(props: { language?: string; children: string }) { textToCopy={(props.children as any).props.children[0]} /> </CopyButtonDiv> - <StyledCode language={props.language}>{props.children}</StyledCode> + <StyledCode language={result?.language}> + {(props.children as any).props.children[0]} + </StyledCode> </StyledPre> ); } |