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',
|
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
|
|
|
|
|
|
|
const { children=[], className='language-js' } = props
|
2021-12-27 17:33:31 +01:00
|
|
|
const language = props.children.props.className.split('-').pop()
|
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>
|
|
|
|
<CopyToClipboard content={children} />
|
2021-12-18 15:41:37 +01:00
|
|
|
</div>
|
2021-12-31 10:15:51 +01:00
|
|
|
<pre className={`language-${language} hljs text-base lg:text-lg whitespace-pre-wrap break-words`}>
|
2021-12-28 09:05:27 +01:00
|
|
|
{children}
|
|
|
|
</pre>
|
2021-12-18 15:41:37 +01:00
|
|
|
</div>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Highlight
|
|
|
|
|