Skip to content

Commit

Permalink
Fix issue with code block
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanoverna committed Mar 8, 2021
1 parent 71b3964 commit d0f2c24
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 22 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
},
"dependencies": {
"@znck/prop-types": "^0.6.3",
"datocms-structured-text-generic-html-renderer": "^1.0.10",
"datocms-structured-text-generic-html-renderer": "^1.0.13",
"hyphenate-style-name": "^1.0.4"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ exports[`StructuredText simple dast with no links/blocks with custom rules rende

exports[`StructuredText simple dast with no links/blocks with default rules renders the document 1`] = `
<div>
<h1>This<br>is a<br>title!</h1>
<h1>This<br>is a<br>title!</h1><pre data-language="javascript"><code>function greetings() {
console.log('Hi!');
}</code></pre>
</div>
`;
Expand Down
6 changes: 6 additions & 0 deletions src/StructuredText/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe("StructuredText", () => {
},
],
},
{
type: "code",
language: "javascript",
highlight: [1],
code: "function greetings() {\n console.log('Hi!');\n}",
},
],
},
},
Expand Down
23 changes: 16 additions & 7 deletions src/StructuredText/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,22 @@ export const StructuredText = {
return null;
}

const hAdapter = (tagName, { key, ...attrs }, children) => {
const data = {
key,
attrs,
};

return h(tagName, data, children);
const hAdapter = (tagName, attrsWithKey, childOrChildren) => {
let data = undefined;

if (attrsWithKey) {
const { key, ...attrs } = attrsWithKey;
data = {
key,
attrs,
};
}

return h(
tagName,
data,
Array.isArray(childOrChildren) ? childOrChildren : [childOrChildren],
);
};

const adapter = {
Expand Down

1 comment on commit d0f2c24

@vercel
Copy link

@vercel vercel bot commented on d0f2c24 Mar 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.