import { chakra } from '@chakra-ui/react' import BaseHighlight, { Language, PrismTheme, defaultProps, } from 'prism-react-renderer' import React from 'react' import { liveEditorStyle } from './styles' const RE = /{([\d,-]+)}/ const calculateLinesToHighlight = (meta: string) => { if (!RE.test(meta)) { return () => false } const lineNumbers = RE.exec(meta)[1] .split(`,`) .map((v) => v.split(`-`).map((x) => parseInt(x, 10))) return (index: number) => { const lineNumber = index + 1 const inRange = lineNumbers.some(([start, end]) => end ? lineNumber >= start && lineNumber <= end : lineNumber === start, ) return inRange } } interface HighlightProps { codeString: string language: Language theme: PrismTheme metastring?: string showLines?: boolean } function Highlight({ codeString, language, metastring, showLines, ...props }: HighlightProps) { const shouldHighlightLine = calculateLinesToHighlight(metastring) return ( {({ className, style, tokens, getLineProps, getTokenProps }) => (
            {tokens.map((line, i) => {
              const lineProps = getLineProps({ line, key: i })
              return (
                
                  {showLines && (
                    
                      {i + 1}
                    
                  )}
                  {line.map((token, key) => (
                    
                  ))}
                
              )
            })}
          
)}
) } export default Highlight