fix: Render void elements correctly and copy all attributes
Co-authored-by: aider (gemini/gemini-2.5-pro) <aider@aider.chat>
This commit is contained in:
@@ -4,6 +4,8 @@ import { Helmet } from 'react-helmet';
|
||||
import localForage from 'localforage';
|
||||
import { sourceLink, infoLine, ToggleDot } from './utils.js';
|
||||
|
||||
const VOID_ELEMENTS = ['area', 'base', 'br', 'col', 'embed', 'hr', 'img', 'input', 'link', 'meta', 'param', 'source', 'track', 'wbr'];
|
||||
|
||||
function Article({ cache }) {
|
||||
const { id } = useParams();
|
||||
|
||||
@@ -96,8 +98,20 @@ function Article({ cache }) {
|
||||
);
|
||||
}
|
||||
|
||||
const props = { key: key };
|
||||
if (v.hasAttributes()) {
|
||||
for (const attr of v.attributes) {
|
||||
const name = attr.name === 'class' ? 'className' : attr.name;
|
||||
props[name] = attr.value;
|
||||
}
|
||||
}
|
||||
|
||||
if (VOID_ELEMENTS.includes(Tag)) {
|
||||
return <Tag {...props} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<Tag key={key}>
|
||||
<Tag {...props}>
|
||||
{renderNodes(v.childNodes, `${key}-`)}
|
||||
</Tag>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user