File size: 663 Bytes
1e92f2d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import Prism from 'prismjs';
import { useEffect, useRef } from 'react';
import 'prismjs/themes/prism.css';
import 'prismjs/components/prism-yaml';
import './style.scss';
interface CodeHighlighterProps {
content: string;
}
export const CodeHighlighter = ( { content }: CodeHighlighterProps ) => {
const yamlCodeRef = useRef< HTMLElement | null >( null );
useEffect( () => {
if ( yamlCodeRef.current ) {
Prism.highlightElement( yamlCodeRef.current );
}
}, [ content ] );
return (
<>
<pre className="github-workflow-code-highlighter">
<code ref={ yamlCodeRef } className="language-yaml">
{ content }
</code>
</pre>
</>
);
};
|