| 1 | import { useContext } from "react"; |
| 2 | import styled from "styled-components"; |
| 3 | import { defaultBorderRadius, vscForeground } from ".."; |
| 4 | import { VscThemeContext } from "../../context/VscTheme"; |
| 5 | |
| 6 | const generateThemeStyles = (theme: any) => { |
| 7 | return Object.keys(theme) |
| 8 | .map((key) => { |
| 9 | return ` |
| 10 | & ${key} { |
| 11 | color: ${theme[key]}; |
| 12 | } |
| 13 | `; |
| 14 | }) |
| 15 | .join(""); |
| 16 | }; |
| 17 | |
| 18 | const StyledPre = styled.pre<{ theme: any }>` |
| 19 | & .hljs { |
| 20 | color: ${vscForeground}; |
| 21 | } |
| 22 | |
| 23 | margin-top: 0; |
| 24 | margin-bottom: 0; |
| 25 | border-radius: 0 0 ${defaultBorderRadius} ${defaultBorderRadius} !important; |
| 26 | |
| 27 | ${(props) => generateThemeStyles(props.theme)} |
| 28 | `; |
| 29 | |
| 30 | export const SyntaxHighlightedPre = (props: any) => { |
| 31 | const currentTheme = useContext(VscThemeContext); |
| 32 | return <StyledPre {...props} theme={currentTheme.theme} />; |
| 33 | }; |