2022-01-16 18:47:47 +01:00
|
|
|
import CopyToClipboard from 'shared/components/copy-to-clipboard'
|
2022-05-20 14:25:05 +02:00
|
|
|
import Dot from './dot.js'
|
2022-01-16 18:47:47 +01:00
|
|
|
|
2021-12-18 15:41:37 +01:00
|
|
|
const names = {
|
2021-12-27 17:33:31 +01:00
|
|
|
js: 'javascript',
|
|
|
|
bash: 'bash',
|
|
|
|
sh: 'shell',
|
2022-01-28 16:57:07 +01:00
|
|
|
json: 'JSON',
|
|
|
|
yaml: 'YAML',
|
2021-12-18 15:41:37 +01:00
|
|
|
}
|
|
|
|
|
2021-12-27 17:33:31 +01:00
|
|
|
const Highlight = (props) => {
|
2022-01-16 18:47:47 +01:00
|
|
|
|
2022-05-20 14:25:05 +02:00
|
|
|
let language = 'txt'
|
|
|
|
if (props.language) language = props.language
|
|
|
|
if (props.children?.props?.className) {
|
|
|
|
language = props.children.props.className.split('-').pop()
|
|
|
|
}
|
|
|
|
if (language === 'dot') return <Dot>{props.children}</Dot>
|
2021-12-18 15:41:37 +01:00
|
|
|
|
2022-01-28 16:57:07 +01:00
|
|
|
const preProps = {
|
2022-06-17 12:02:09 +02:00
|
|
|
className: `language-${language} hljs text-base lg:text-lg whitespace-pre overflow-scroll pr-4`
|
2022-01-28 16:57:07 +01:00
|
|
|
}
|
|
|
|
if (props.raw) preProps.dangerouslySetInnerHTML = { __html: props.raw }
|
|
|
|
|
2021-12-18 15:41:37 +01:00
|
|
|
return (
|
2021-12-21 20:47:13 +01:00
|
|
|
<div className="hljs my-4">
|
2022-01-16 18:47:47 +01:00
|
|
|
<div className={`
|
|
|
|
flex flex-row justify-between
|
|
|
|
text-xs uppercase font-bold text-neutral-content
|
|
|
|
mt-1 border-b border-neutral-content border-opacity-25
|
|
|
|
py-1 mb-2 lg:text-sm
|
|
|
|
`}>
|
|
|
|
<span> </span>
|
|
|
|
<span>{names[language] ? names[language] : language}</span>
|
2022-01-20 11:04:41 +01:00
|
|
|
<CopyToClipboard content={props.children} />
|
2021-12-18 15:41:37 +01:00
|
|
|
</div>
|
2022-01-28 16:57:07 +01:00
|
|
|
<pre {...preProps}>
|
2022-01-20 11:04:41 +01:00
|
|
|
{props.children}
|
2021-12-28 09:05:27 +01:00
|
|
|
</pre>
|
2021-12-18 15:41:37 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Highlight
|
|
|
|
|