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