Fix code block renderer (#119)

This commit is contained in:
Hakan Shehu
2025-07-07 07:34:16 +02:00
committed by GitHub
parent 6fe6f324e8
commit 01ffcc3ae2

View File

@@ -14,11 +14,11 @@ export const CodeBlockRenderer = ({
node, node,
keyPrefix, keyPrefix,
}: CodeBlockRendererProps) => { }: CodeBlockRendererProps) => {
const language = node.attributes.language; const language = node.attrs?.language;
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const code = node.attributes.content?.[0].text ?? ''; const code = node.content?.[0]?.text ?? '';
if (!code) { if (!code) {
return null; return null;
} }
@@ -43,11 +43,13 @@ export const CodeBlockRenderer = ({
<p>{copied ? 'Copied' : 'Copy code'}</p> <p>{copied ? 'Copied' : 'Copy code'}</p>
</div> </div>
</div> </div>
{highlight ? ( {highlight && highlight.language && highlight.nodes?.length > 0 ? (
<code <code
className={highlight.language ? `language-${highlight.language}` : ''} className={
highlight?.language ? `language-${highlight?.language}` : ''
}
> >
{highlight.nodes.map((node, index) => ( {highlight?.nodes.map((node, index) => (
<span <span
key={`${keyPrefix}-${index}`} key={`${keyPrefix}-${index}`}
className={node.classes.join(' ')} className={node.classes.join(' ')}