forked from tanner/qotnews
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 localForage from 'localforage';
|
||||||
import { sourceLink, infoLine, ToggleDot } from './utils.js';
|
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 }) {
|
function Article({ cache }) {
|
||||||
const { id } = useParams();
|
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 (
|
return (
|
||||||
<Tag key={key}>
|
<Tag {...props}>
|
||||||
{renderNodes(v.childNodes, `${key}-`)}
|
{renderNodes(v.childNodes, `${key}-`)}
|
||||||
</Tag>
|
</Tag>
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user