@jsenv/ast 5.2.1 → 6.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/html/html_parse.js +30 -5
- package/src/main.js +1 -1
package/package.json
CHANGED
package/src/html/html_parse.js
CHANGED
|
@@ -12,11 +12,36 @@ import {
|
|
|
12
12
|
import { findHtmlChildNode, visitHtmlNodes } from "./html_search.js";
|
|
13
13
|
import { getHtmlNodeText } from "./html_node_text.js";
|
|
14
14
|
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
15
|
+
export const parseHtml = ({
|
|
16
|
+
html,
|
|
17
|
+
url,
|
|
18
|
+
storeOriginalPositions = true,
|
|
19
|
+
} = {}) => {
|
|
20
|
+
const htmlAst = parse(html, {
|
|
21
|
+
sourceCodeLocationInfo: true,
|
|
22
|
+
onParseError: (parse5Error) => {
|
|
23
|
+
if (
|
|
24
|
+
[
|
|
25
|
+
"missing-doctype",
|
|
26
|
+
"abandoned-head-element-child",
|
|
27
|
+
"duplicate-attribute",
|
|
28
|
+
"non-void-html-element-start-tag-with-trailing-solidus",
|
|
29
|
+
].includes(parse5Error.code)
|
|
30
|
+
) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const htmlParseError = new Error(
|
|
34
|
+
`Unable to parse HTML; ${parse5Error.code}`,
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
htmlParseError.reasonCode = parse5Error.code;
|
|
38
|
+
htmlParseError.code = "PARSE_ERROR";
|
|
39
|
+
htmlParseError.url = url;
|
|
40
|
+
htmlParseError.line = parse5Error.startLine;
|
|
41
|
+
htmlParseError.column = parse5Error.startCol;
|
|
42
|
+
throw htmlParseError;
|
|
43
|
+
},
|
|
44
|
+
});
|
|
20
45
|
if (storeOriginalPositions) {
|
|
21
46
|
const htmlNode = findHtmlChildNode(
|
|
22
47
|
htmlAst,
|