close #42 fallback to html when doctype is invalid

This commit is contained in:
Yanzhen Yu
2026-04-01 12:00:00 +08:00
parent c43189d3fe
commit 79f1ba574a
3 changed files with 19 additions and 1 deletions

View File

@@ -85,7 +85,7 @@ function buildNode(
return doc.implementation.createDocument(null, '', null);
case NodeType.DocumentType:
return doc.implementation.createDocumentType(
n.name,
n.name || 'html',
n.publicId,
n.systemId,
);

View File

@@ -175,6 +175,15 @@ exports[`[html file]: invalid-attribute.html 1`] = `
</body></html>"
`;
exports[`[html file]: invalid-doctype.html 1`] = `
"<!DOCTYPE html><html xmlns=\\"http://www.w3.org/1999/xhtml\\" lang=\\"en\\"><head>
<meta charset=\\"UTF-8\\" />
<meta name=\\"viewport\\" content=\\"width=device-width, initial-scale=1.0\\" />
<title>Invalid Doctype</title>
</head>
<body></body></html>"
`;
exports[`[html file]: invalid-tagname.html 1`] = `
"<!DOCTYPE html><html xmlns=\\"http://www.w3.org/1999/xhtml\\" lang=\\"en\\"><head>
<meta charset=\\"UTF-8\\" />

View File

@@ -0,0 +1,9 @@
<!DOCTYPE >
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Invalid Doctype</title>
</head>
<body></body>
</html>