-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make innerHTML and outerHTML parsing spec compliant
This pull request fixes the issue discussed here: #2398 (comment). Before this change, innerHTML and outerHTML would directly manipulate their thisArg, using appendChild() and removeChild(), instead of instead of creating a fragment and inserting it in the DOM at the end of the parsing. Moving to the per-spec architecture fixes various correctness issues. Other changes: - Create a generic parser module exposing two methods: parseFragment and parseDocument. This abstracts over the HTML vs. XML distinction. - Migrate all the internal usages of the "htmltodom" module to use the new parser module. - Adjust the implementation of Element's innerHTML, outerHTML, and insertAdjacentHTML(), as well as ShadowRoot's innerHTML, to closer match to the spec. - Update saxes and w3c-xmlserializer to improve XML parsing/serialization.
- Loading branch information
Showing
15 changed files
with
367 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
"use strict"; | ||
|
||
const xmlParser = require("./xml"); | ||
const htmlParser = require("./html"); | ||
|
||
// https://w3c.github.io/DOM-Parsing/#dfn-fragment-parsing-algorithm | ||
function parseFragment(markup, contextElement) { | ||
const { _parsingMode } = contextElement._ownerDocument; | ||
|
||
let parseAlgorithm; | ||
if (_parsingMode === "html") { | ||
parseAlgorithm = htmlParser.parseFragment; | ||
} else if (_parsingMode === "xml") { | ||
parseAlgorithm = xmlParser.parseFragment; | ||
} | ||
|
||
// Note: HTML and XML fragment parsing algorithm already return a document fragments; no need to do steps 3 and 4 | ||
return parseAlgorithm(markup, contextElement); | ||
} | ||
|
||
function parseIntoDocument(markup, ownerDocument) { | ||
const { _parsingMode } = ownerDocument; | ||
|
||
let parseAlgorithm; | ||
if (_parsingMode === "html") { | ||
parseAlgorithm = htmlParser.parseIntoDocument; | ||
} else if (_parsingMode === "xml") { | ||
parseAlgorithm = xmlParser.parseIntoDocument; | ||
} | ||
|
||
return parseAlgorithm(markup, ownerDocument); | ||
} | ||
|
||
module.exports = { | ||
parseFragment, | ||
parseIntoDocument | ||
}; |
Oops, something went wrong.