diff options
author | Nate Sesti <sestinj@gmail.com> | 2023-06-26 17:41:12 -0700 |
---|---|---|
committer | Nate Sesti <sestinj@gmail.com> | 2023-06-26 17:41:12 -0700 |
commit | ce846df27aa9646d79da4160c833031766d2c13b (patch) | |
tree | 5993b2d211fcaa0a14bd742249d66d5ae52c5a85 /extension/react-app/src/components | |
parent | f4beca92731a81c32aec9c692ec32b78024f5974 (diff) | |
download | sncontinue-ce846df27aa9646d79da4160c833031766d2c13b.tar.gz sncontinue-ce846df27aa9646d79da4160c833031766d2c13b.tar.bz2 sncontinue-ce846df27aa9646d79da4160c833031766d2c13b.zip |
syntax highlighting lang auto detection
Diffstat (limited to 'extension/react-app/src/components')
-rw-r--r-- | extension/react-app/src/components/CodeBlock.tsx | 54 | ||||
-rw-r--r-- | extension/react-app/src/components/StyledCode.tsx | 2 |
2 files changed, 52 insertions, 4 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> ); } diff --git a/extension/react-app/src/components/StyledCode.tsx b/extension/react-app/src/components/StyledCode.tsx index 485c70b6..c5ed0101 100644 --- a/extension/react-app/src/components/StyledCode.tsx +++ b/extension/react-app/src/components/StyledCode.tsx @@ -12,7 +12,7 @@ const StyledCode = (props: StyledCodeProps) => ( style={highlightStyle} language={props.language || "python"} > - {(props.children as any).props.children} + {props.children} </SyntaxHighlighter> ); |