Skip to content

Open-source and local-first Slack and Notion alternative that puts you in control of your data

Fix code block renderer (#119)

Hakan Shehu01ffcc3ae285
diff --git a/packages/ui/src/editor/renderers/code-block.tsx b/packages/ui/src/editor/renderers/code-block.tsx
index 2979eeeb..2e47f8f5 100644
--- a/packages/ui/src/editor/renderers/code-block.tsx
+++ b/packages/ui/src/editor/renderers/code-block.tsx
@@ -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(' ')}