2022-01-16 18:47:47 +01:00
|
|
|
import CopyToClipboard from 'shared/components/copy-to-clipboard'
|
|
|
|
|
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-01-28 16:57:07 +01:00
|
|
|
const language = props.language
|
|
|
|
? props.language
|
|
|
|
: props.children
|
2022-01-20 09:07:38 +01:00
|
|
|
? props.children.props.className.split('-').pop()
|
|
|
|
: 'txt'
|
2021-12-18 15:41:37 +01:00
|
|
|
|
2022-01-28 16:57:07 +01:00
|
|
|
const preProps = {
|
2022-05-15 18:44:36 +02:00
|
|
|
className: `language-${language} hljs text-base lg:text-lg whitespace-pre-wrap break-all`
|
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
|
|
|
|
|