Treat XHTML without xmlns as HTML

The XHTML 1.1 spec says

    The start tag of the root element of the document MUST explicitly
    contain an xmlns declaration for the XHTML namespace

There doesn't seem to be such a requirement in the WHATWG spec. But at
any rate browsers won't render it properly without the XHTML namespace.
This commit is contained in:
John Factotum
2024-07-27 09:46:04 +08:00
parent 835b70a840
commit 9ff893f3e7
2 changed files with 4 additions and 3 deletions
+3 -2
View File
@@ -673,8 +673,9 @@ class Loader {
if ([MIME.XHTML, MIME.HTML, MIME.SVG].includes(mediaType)) {
let doc = new DOMParser().parseFromString(str, mediaType)
// change to HTML if it's not valid XHTML
if (mediaType === MIME.XHTML && doc.querySelector('parsererror')) {
console.warn(doc.querySelector('parsererror').innerText)
if (mediaType === MIME.XHTML && (doc.querySelector('parsererror')
|| !doc.documentElement?.namespaceURI)) {
console.warn(doc.querySelector('parsererror')?.innerText ?? 'Invalid XHTML')
item.mediaType = MIME.HTML
doc = new DOMParser().parseFromString(str, item.mediaType)
}
+1 -1
View File
@@ -1154,7 +1154,7 @@ class KF8 {
// by default, type is XHTML; change to HTML if it's not valid XHTML
let doc = this.parser.parseFromString(replaced, this.#type)
if (doc.querySelector('parsererror')) {
if (doc.querySelector('parsererror') || !doc.documentElement?.namespaceURI) {
this.#type = MIME.HTML
doc = this.parser.parseFromString(replaced, this.#type)
}