parse5 6.0.1 → 7.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/README.md +2 -2
- package/dist/cjs/common/doctype.d.ts +5 -0
- package/dist/cjs/common/doctype.js +120 -0
- package/dist/cjs/common/error-codes.d.ts +68 -0
- package/dist/cjs/common/error-codes.js +67 -0
- package/dist/cjs/common/foreign-content.d.ts +10 -0
- package/dist/cjs/common/foreign-content.js +239 -0
- package/dist/cjs/common/html.d.ts +288 -0
- package/dist/cjs/common/html.js +529 -0
- package/dist/cjs/common/token.d.ts +85 -0
- package/dist/cjs/common/token.js +25 -0
- package/dist/cjs/common/unicode.d.ts +49 -0
- package/dist/cjs/common/unicode.js +77 -0
- package/dist/cjs/index.d.ts +60 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/parser/formatting-element-list.d.ts +32 -0
- package/dist/cjs/parser/formatting-element-list.js +110 -0
- package/dist/cjs/parser/index.d.ts +157 -0
- package/dist/cjs/parser/index.js +3049 -0
- package/dist/cjs/parser/open-element-stack.d.ts +53 -0
- package/dist/cjs/parser/open-element-stack.js +316 -0
- package/dist/cjs/serializer/index.d.ts +61 -0
- package/dist/cjs/serializer/index.js +173 -0
- package/dist/cjs/tokenizer/index.d.ts +250 -0
- package/dist/cjs/tokenizer/index.js +2921 -0
- package/dist/cjs/tokenizer/preprocessor.d.ts +37 -0
- package/dist/cjs/tokenizer/preprocessor.js +198 -0
- package/dist/cjs/tree-adapters/default.d.ts +92 -0
- package/dist/cjs/tree-adapters/default.js +185 -0
- package/dist/cjs/tree-adapters/interface.d.ts +250 -0
- package/dist/cjs/tree-adapters/interface.js +3 -0
- package/dist/common/doctype.d.ts +5 -0
- package/{lib → dist}/common/doctype.js +25 -72
- package/dist/common/error-codes.d.ts +68 -0
- package/dist/common/error-codes.js +64 -0
- package/dist/common/foreign-content.d.ts +10 -0
- package/dist/common/foreign-content.js +230 -0
- package/dist/common/html.d.ts +288 -0
- package/dist/common/html.js +523 -0
- package/dist/common/token.d.ts +85 -0
- package/dist/common/token.js +21 -0
- package/dist/common/unicode.d.ts +49 -0
- package/dist/common/unicode.js +69 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.js +44 -0
- package/dist/parser/formatting-element-list.d.ts +32 -0
- package/dist/parser/formatting-element-list.js +106 -0
- package/dist/parser/index.d.ts +157 -0
- package/dist/parser/index.js +3054 -0
- package/dist/parser/open-element-stack.d.ts +53 -0
- package/dist/parser/open-element-stack.js +312 -0
- package/dist/serializer/index.d.ts +61 -0
- package/dist/serializer/index.js +168 -0
- package/dist/tokenizer/index.d.ts +250 -0
- package/dist/tokenizer/index.js +2917 -0
- package/dist/tokenizer/preprocessor.d.ts +37 -0
- package/dist/tokenizer/preprocessor.js +194 -0
- package/dist/tree-adapters/default.d.ts +92 -0
- package/dist/tree-adapters/default.js +182 -0
- package/dist/tree-adapters/interface.d.ts +250 -0
- package/dist/tree-adapters/interface.js +2 -0
- package/package.json +19 -5
- package/lib/common/error-codes.js +0 -65
- package/lib/common/foreign-content.js +0 -265
- package/lib/common/html.js +0 -272
- package/lib/common/unicode.js +0 -109
- package/lib/extensions/error-reporting/mixin-base.js +0 -43
- package/lib/extensions/error-reporting/parser-mixin.js +0 -52
- package/lib/extensions/error-reporting/preprocessor-mixin.js +0 -24
- package/lib/extensions/error-reporting/tokenizer-mixin.js +0 -17
- package/lib/extensions/location-info/open-element-stack-mixin.js +0 -35
- package/lib/extensions/location-info/parser-mixin.js +0 -223
- package/lib/extensions/location-info/tokenizer-mixin.js +0 -146
- package/lib/extensions/position-tracking/preprocessor-mixin.js +0 -64
- package/lib/index.js +0 -29
- package/lib/parser/formatting-element-list.js +0 -181
- package/lib/parser/index.js +0 -2956
- package/lib/parser/open-element-stack.js +0 -482
- package/lib/serializer/index.js +0 -176
- package/lib/tokenizer/index.js +0 -2196
- package/lib/tokenizer/named-entity-data.js +0 -5
- package/lib/tokenizer/preprocessor.js +0 -159
- package/lib/tree-adapters/default.js +0 -221
- package/lib/utils/merge-options.js +0 -13
- package/lib/utils/mixin.js +0 -39
package/README.md
CHANGED
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
<br>
|
|
17
17
|
|
|
18
18
|
<p align="center">
|
|
19
|
-
📖 <a href="https://
|
|
19
|
+
📖 <a href="https://parse5.js.org/modules/parse5.html"><b>Documentation</b></a> 📖
|
|
20
20
|
</p>
|
|
21
21
|
|
|
22
22
|
---
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
</p>
|
|
35
35
|
|
|
36
36
|
<p align="center">
|
|
37
|
-
<a href="https://github.com/inikulin/parse5/
|
|
37
|
+
<a href="https://github.com/inikulin/parse5/releases">Changelog</a>
|
|
38
38
|
</p>
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { DOCUMENT_MODE } from './html.js';
|
|
2
|
+
import type { DoctypeToken } from './token.js';
|
|
3
|
+
export declare function isConforming(token: DoctypeToken): boolean;
|
|
4
|
+
export declare function getDocumentMode(token: DoctypeToken): DOCUMENT_MODE;
|
|
5
|
+
//# sourceMappingURL=doctype.d.ts.map
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDocumentMode = exports.isConforming = void 0;
|
|
4
|
+
const html_js_1 = require("./html.js");
|
|
5
|
+
//Const
|
|
6
|
+
const VALID_DOCTYPE_NAME = 'html';
|
|
7
|
+
const VALID_SYSTEM_ID = 'about:legacy-compat';
|
|
8
|
+
const QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd';
|
|
9
|
+
const QUIRKS_MODE_PUBLIC_ID_PREFIXES = [
|
|
10
|
+
'+//silmaril//dtd html pro v0r11 19970101//',
|
|
11
|
+
'-//as//dtd html 3.0 aswedit + extensions//',
|
|
12
|
+
'-//advasoft ltd//dtd html 3.0 aswedit + extensions//',
|
|
13
|
+
'-//ietf//dtd html 2.0 level 1//',
|
|
14
|
+
'-//ietf//dtd html 2.0 level 2//',
|
|
15
|
+
'-//ietf//dtd html 2.0 strict level 1//',
|
|
16
|
+
'-//ietf//dtd html 2.0 strict level 2//',
|
|
17
|
+
'-//ietf//dtd html 2.0 strict//',
|
|
18
|
+
'-//ietf//dtd html 2.0//',
|
|
19
|
+
'-//ietf//dtd html 2.1e//',
|
|
20
|
+
'-//ietf//dtd html 3.0//',
|
|
21
|
+
'-//ietf//dtd html 3.2 final//',
|
|
22
|
+
'-//ietf//dtd html 3.2//',
|
|
23
|
+
'-//ietf//dtd html 3//',
|
|
24
|
+
'-//ietf//dtd html level 0//',
|
|
25
|
+
'-//ietf//dtd html level 1//',
|
|
26
|
+
'-//ietf//dtd html level 2//',
|
|
27
|
+
'-//ietf//dtd html level 3//',
|
|
28
|
+
'-//ietf//dtd html strict level 0//',
|
|
29
|
+
'-//ietf//dtd html strict level 1//',
|
|
30
|
+
'-//ietf//dtd html strict level 2//',
|
|
31
|
+
'-//ietf//dtd html strict level 3//',
|
|
32
|
+
'-//ietf//dtd html strict//',
|
|
33
|
+
'-//ietf//dtd html//',
|
|
34
|
+
'-//metrius//dtd metrius presentational//',
|
|
35
|
+
'-//microsoft//dtd internet explorer 2.0 html strict//',
|
|
36
|
+
'-//microsoft//dtd internet explorer 2.0 html//',
|
|
37
|
+
'-//microsoft//dtd internet explorer 2.0 tables//',
|
|
38
|
+
'-//microsoft//dtd internet explorer 3.0 html strict//',
|
|
39
|
+
'-//microsoft//dtd internet explorer 3.0 html//',
|
|
40
|
+
'-//microsoft//dtd internet explorer 3.0 tables//',
|
|
41
|
+
'-//netscape comm. corp.//dtd html//',
|
|
42
|
+
'-//netscape comm. corp.//dtd strict html//',
|
|
43
|
+
"-//o'reilly and associates//dtd html 2.0//",
|
|
44
|
+
"-//o'reilly and associates//dtd html extended 1.0//",
|
|
45
|
+
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
|
|
46
|
+
'-//sq//dtd html 2.0 hotmetal + extensions//',
|
|
47
|
+
'-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//',
|
|
48
|
+
'-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//',
|
|
49
|
+
'-//spyglass//dtd html 2.0 extended//',
|
|
50
|
+
'-//sun microsystems corp.//dtd hotjava html//',
|
|
51
|
+
'-//sun microsystems corp.//dtd hotjava strict html//',
|
|
52
|
+
'-//w3c//dtd html 3 1995-03-24//',
|
|
53
|
+
'-//w3c//dtd html 3.2 draft//',
|
|
54
|
+
'-//w3c//dtd html 3.2 final//',
|
|
55
|
+
'-//w3c//dtd html 3.2//',
|
|
56
|
+
'-//w3c//dtd html 3.2s draft//',
|
|
57
|
+
'-//w3c//dtd html 4.0 frameset//',
|
|
58
|
+
'-//w3c//dtd html 4.0 transitional//',
|
|
59
|
+
'-//w3c//dtd html experimental 19960712//',
|
|
60
|
+
'-//w3c//dtd html experimental 970421//',
|
|
61
|
+
'-//w3c//dtd w3 html//',
|
|
62
|
+
'-//w3o//dtd w3 html 3.0//',
|
|
63
|
+
'-//webtechs//dtd mozilla html 2.0//',
|
|
64
|
+
'-//webtechs//dtd mozilla html//',
|
|
65
|
+
];
|
|
66
|
+
const QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
|
|
67
|
+
...QUIRKS_MODE_PUBLIC_ID_PREFIXES,
|
|
68
|
+
'-//w3c//dtd html 4.01 frameset//',
|
|
69
|
+
'-//w3c//dtd html 4.01 transitional//',
|
|
70
|
+
];
|
|
71
|
+
const QUIRKS_MODE_PUBLIC_IDS = new Set([
|
|
72
|
+
'-//w3o//dtd w3 html strict 3.0//en//',
|
|
73
|
+
'-/w3c/dtd html 4.0 transitional/en',
|
|
74
|
+
'html',
|
|
75
|
+
]);
|
|
76
|
+
const LIMITED_QUIRKS_PUBLIC_ID_PREFIXES = ['-//w3c//dtd xhtml 1.0 frameset//', '-//w3c//dtd xhtml 1.0 transitional//'];
|
|
77
|
+
const LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
|
|
78
|
+
...LIMITED_QUIRKS_PUBLIC_ID_PREFIXES,
|
|
79
|
+
'-//w3c//dtd html 4.01 frameset//',
|
|
80
|
+
'-//w3c//dtd html 4.01 transitional//',
|
|
81
|
+
];
|
|
82
|
+
//Utils
|
|
83
|
+
function hasPrefix(publicId, prefixes) {
|
|
84
|
+
return prefixes.some((prefix) => publicId.startsWith(prefix));
|
|
85
|
+
}
|
|
86
|
+
//API
|
|
87
|
+
function isConforming(token) {
|
|
88
|
+
return (token.name === VALID_DOCTYPE_NAME &&
|
|
89
|
+
token.publicId === null &&
|
|
90
|
+
(token.systemId === null || token.systemId === VALID_SYSTEM_ID));
|
|
91
|
+
}
|
|
92
|
+
exports.isConforming = isConforming;
|
|
93
|
+
function getDocumentMode(token) {
|
|
94
|
+
if (token.name !== VALID_DOCTYPE_NAME) {
|
|
95
|
+
return html_js_1.DOCUMENT_MODE.QUIRKS;
|
|
96
|
+
}
|
|
97
|
+
const { systemId } = token;
|
|
98
|
+
if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) {
|
|
99
|
+
return html_js_1.DOCUMENT_MODE.QUIRKS;
|
|
100
|
+
}
|
|
101
|
+
let { publicId } = token;
|
|
102
|
+
if (publicId !== null) {
|
|
103
|
+
publicId = publicId.toLowerCase();
|
|
104
|
+
if (QUIRKS_MODE_PUBLIC_IDS.has(publicId)) {
|
|
105
|
+
return html_js_1.DOCUMENT_MODE.QUIRKS;
|
|
106
|
+
}
|
|
107
|
+
let prefixes = systemId === null ? QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES : QUIRKS_MODE_PUBLIC_ID_PREFIXES;
|
|
108
|
+
if (hasPrefix(publicId, prefixes)) {
|
|
109
|
+
return html_js_1.DOCUMENT_MODE.QUIRKS;
|
|
110
|
+
}
|
|
111
|
+
prefixes =
|
|
112
|
+
systemId === null ? LIMITED_QUIRKS_PUBLIC_ID_PREFIXES : LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES;
|
|
113
|
+
if (hasPrefix(publicId, prefixes)) {
|
|
114
|
+
return html_js_1.DOCUMENT_MODE.LIMITED_QUIRKS;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return html_js_1.DOCUMENT_MODE.NO_QUIRKS;
|
|
118
|
+
}
|
|
119
|
+
exports.getDocumentMode = getDocumentMode;
|
|
120
|
+
//# sourceMappingURL=doctype.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import type { Location } from './token.js';
|
|
2
|
+
export interface ParserError extends Location {
|
|
3
|
+
code: ERR;
|
|
4
|
+
}
|
|
5
|
+
export declare type ParserErrorHandler = (error: ParserError) => void;
|
|
6
|
+
export declare enum ERR {
|
|
7
|
+
controlCharacterInInputStream = "control-character-in-input-stream",
|
|
8
|
+
noncharacterInInputStream = "noncharacter-in-input-stream",
|
|
9
|
+
surrogateInInputStream = "surrogate-in-input-stream",
|
|
10
|
+
nonVoidHtmlElementStartTagWithTrailingSolidus = "non-void-html-element-start-tag-with-trailing-solidus",
|
|
11
|
+
endTagWithAttributes = "end-tag-with-attributes",
|
|
12
|
+
endTagWithTrailingSolidus = "end-tag-with-trailing-solidus",
|
|
13
|
+
unexpectedSolidusInTag = "unexpected-solidus-in-tag",
|
|
14
|
+
unexpectedNullCharacter = "unexpected-null-character",
|
|
15
|
+
unexpectedQuestionMarkInsteadOfTagName = "unexpected-question-mark-instead-of-tag-name",
|
|
16
|
+
invalidFirstCharacterOfTagName = "invalid-first-character-of-tag-name",
|
|
17
|
+
unexpectedEqualsSignBeforeAttributeName = "unexpected-equals-sign-before-attribute-name",
|
|
18
|
+
missingEndTagName = "missing-end-tag-name",
|
|
19
|
+
unexpectedCharacterInAttributeName = "unexpected-character-in-attribute-name",
|
|
20
|
+
unknownNamedCharacterReference = "unknown-named-character-reference",
|
|
21
|
+
missingSemicolonAfterCharacterReference = "missing-semicolon-after-character-reference",
|
|
22
|
+
unexpectedCharacterAfterDoctypeSystemIdentifier = "unexpected-character-after-doctype-system-identifier",
|
|
23
|
+
unexpectedCharacterInUnquotedAttributeValue = "unexpected-character-in-unquoted-attribute-value",
|
|
24
|
+
eofBeforeTagName = "eof-before-tag-name",
|
|
25
|
+
eofInTag = "eof-in-tag",
|
|
26
|
+
missingAttributeValue = "missing-attribute-value",
|
|
27
|
+
missingWhitespaceBetweenAttributes = "missing-whitespace-between-attributes",
|
|
28
|
+
missingWhitespaceAfterDoctypePublicKeyword = "missing-whitespace-after-doctype-public-keyword",
|
|
29
|
+
missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers = "missing-whitespace-between-doctype-public-and-system-identifiers",
|
|
30
|
+
missingWhitespaceAfterDoctypeSystemKeyword = "missing-whitespace-after-doctype-system-keyword",
|
|
31
|
+
missingQuoteBeforeDoctypePublicIdentifier = "missing-quote-before-doctype-public-identifier",
|
|
32
|
+
missingQuoteBeforeDoctypeSystemIdentifier = "missing-quote-before-doctype-system-identifier",
|
|
33
|
+
missingDoctypePublicIdentifier = "missing-doctype-public-identifier",
|
|
34
|
+
missingDoctypeSystemIdentifier = "missing-doctype-system-identifier",
|
|
35
|
+
abruptDoctypePublicIdentifier = "abrupt-doctype-public-identifier",
|
|
36
|
+
abruptDoctypeSystemIdentifier = "abrupt-doctype-system-identifier",
|
|
37
|
+
cdataInHtmlContent = "cdata-in-html-content",
|
|
38
|
+
incorrectlyOpenedComment = "incorrectly-opened-comment",
|
|
39
|
+
eofInScriptHtmlCommentLikeText = "eof-in-script-html-comment-like-text",
|
|
40
|
+
eofInDoctype = "eof-in-doctype",
|
|
41
|
+
nestedComment = "nested-comment",
|
|
42
|
+
abruptClosingOfEmptyComment = "abrupt-closing-of-empty-comment",
|
|
43
|
+
eofInComment = "eof-in-comment",
|
|
44
|
+
incorrectlyClosedComment = "incorrectly-closed-comment",
|
|
45
|
+
eofInCdata = "eof-in-cdata",
|
|
46
|
+
absenceOfDigitsInNumericCharacterReference = "absence-of-digits-in-numeric-character-reference",
|
|
47
|
+
nullCharacterReference = "null-character-reference",
|
|
48
|
+
surrogateCharacterReference = "surrogate-character-reference",
|
|
49
|
+
characterReferenceOutsideUnicodeRange = "character-reference-outside-unicode-range",
|
|
50
|
+
controlCharacterReference = "control-character-reference",
|
|
51
|
+
noncharacterCharacterReference = "noncharacter-character-reference",
|
|
52
|
+
missingWhitespaceBeforeDoctypeName = "missing-whitespace-before-doctype-name",
|
|
53
|
+
missingDoctypeName = "missing-doctype-name",
|
|
54
|
+
invalidCharacterSequenceAfterDoctypeName = "invalid-character-sequence-after-doctype-name",
|
|
55
|
+
duplicateAttribute = "duplicate-attribute",
|
|
56
|
+
nonConformingDoctype = "non-conforming-doctype",
|
|
57
|
+
missingDoctype = "missing-doctype",
|
|
58
|
+
misplacedDoctype = "misplaced-doctype",
|
|
59
|
+
endTagWithoutMatchingOpenElement = "end-tag-without-matching-open-element",
|
|
60
|
+
closingOfElementWithOpenChildElements = "closing-of-element-with-open-child-elements",
|
|
61
|
+
disallowedContentInNoscriptInHead = "disallowed-content-in-noscript-in-head",
|
|
62
|
+
openElementsLeftAfterEof = "open-elements-left-after-eof",
|
|
63
|
+
abandonedHeadElementChild = "abandoned-head-element-child",
|
|
64
|
+
misplacedStartTagForHeadElement = "misplaced-start-tag-for-head-element",
|
|
65
|
+
nestedNoscriptInHead = "nested-noscript-in-head",
|
|
66
|
+
eofInElementThatCanContainOnlyText = "eof-in-element-that-can-contain-only-text"
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=error-codes.d.ts.map
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERR = void 0;
|
|
4
|
+
var ERR;
|
|
5
|
+
(function (ERR) {
|
|
6
|
+
ERR["controlCharacterInInputStream"] = "control-character-in-input-stream";
|
|
7
|
+
ERR["noncharacterInInputStream"] = "noncharacter-in-input-stream";
|
|
8
|
+
ERR["surrogateInInputStream"] = "surrogate-in-input-stream";
|
|
9
|
+
ERR["nonVoidHtmlElementStartTagWithTrailingSolidus"] = "non-void-html-element-start-tag-with-trailing-solidus";
|
|
10
|
+
ERR["endTagWithAttributes"] = "end-tag-with-attributes";
|
|
11
|
+
ERR["endTagWithTrailingSolidus"] = "end-tag-with-trailing-solidus";
|
|
12
|
+
ERR["unexpectedSolidusInTag"] = "unexpected-solidus-in-tag";
|
|
13
|
+
ERR["unexpectedNullCharacter"] = "unexpected-null-character";
|
|
14
|
+
ERR["unexpectedQuestionMarkInsteadOfTagName"] = "unexpected-question-mark-instead-of-tag-name";
|
|
15
|
+
ERR["invalidFirstCharacterOfTagName"] = "invalid-first-character-of-tag-name";
|
|
16
|
+
ERR["unexpectedEqualsSignBeforeAttributeName"] = "unexpected-equals-sign-before-attribute-name";
|
|
17
|
+
ERR["missingEndTagName"] = "missing-end-tag-name";
|
|
18
|
+
ERR["unexpectedCharacterInAttributeName"] = "unexpected-character-in-attribute-name";
|
|
19
|
+
ERR["unknownNamedCharacterReference"] = "unknown-named-character-reference";
|
|
20
|
+
ERR["missingSemicolonAfterCharacterReference"] = "missing-semicolon-after-character-reference";
|
|
21
|
+
ERR["unexpectedCharacterAfterDoctypeSystemIdentifier"] = "unexpected-character-after-doctype-system-identifier";
|
|
22
|
+
ERR["unexpectedCharacterInUnquotedAttributeValue"] = "unexpected-character-in-unquoted-attribute-value";
|
|
23
|
+
ERR["eofBeforeTagName"] = "eof-before-tag-name";
|
|
24
|
+
ERR["eofInTag"] = "eof-in-tag";
|
|
25
|
+
ERR["missingAttributeValue"] = "missing-attribute-value";
|
|
26
|
+
ERR["missingWhitespaceBetweenAttributes"] = "missing-whitespace-between-attributes";
|
|
27
|
+
ERR["missingWhitespaceAfterDoctypePublicKeyword"] = "missing-whitespace-after-doctype-public-keyword";
|
|
28
|
+
ERR["missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers"] = "missing-whitespace-between-doctype-public-and-system-identifiers";
|
|
29
|
+
ERR["missingWhitespaceAfterDoctypeSystemKeyword"] = "missing-whitespace-after-doctype-system-keyword";
|
|
30
|
+
ERR["missingQuoteBeforeDoctypePublicIdentifier"] = "missing-quote-before-doctype-public-identifier";
|
|
31
|
+
ERR["missingQuoteBeforeDoctypeSystemIdentifier"] = "missing-quote-before-doctype-system-identifier";
|
|
32
|
+
ERR["missingDoctypePublicIdentifier"] = "missing-doctype-public-identifier";
|
|
33
|
+
ERR["missingDoctypeSystemIdentifier"] = "missing-doctype-system-identifier";
|
|
34
|
+
ERR["abruptDoctypePublicIdentifier"] = "abrupt-doctype-public-identifier";
|
|
35
|
+
ERR["abruptDoctypeSystemIdentifier"] = "abrupt-doctype-system-identifier";
|
|
36
|
+
ERR["cdataInHtmlContent"] = "cdata-in-html-content";
|
|
37
|
+
ERR["incorrectlyOpenedComment"] = "incorrectly-opened-comment";
|
|
38
|
+
ERR["eofInScriptHtmlCommentLikeText"] = "eof-in-script-html-comment-like-text";
|
|
39
|
+
ERR["eofInDoctype"] = "eof-in-doctype";
|
|
40
|
+
ERR["nestedComment"] = "nested-comment";
|
|
41
|
+
ERR["abruptClosingOfEmptyComment"] = "abrupt-closing-of-empty-comment";
|
|
42
|
+
ERR["eofInComment"] = "eof-in-comment";
|
|
43
|
+
ERR["incorrectlyClosedComment"] = "incorrectly-closed-comment";
|
|
44
|
+
ERR["eofInCdata"] = "eof-in-cdata";
|
|
45
|
+
ERR["absenceOfDigitsInNumericCharacterReference"] = "absence-of-digits-in-numeric-character-reference";
|
|
46
|
+
ERR["nullCharacterReference"] = "null-character-reference";
|
|
47
|
+
ERR["surrogateCharacterReference"] = "surrogate-character-reference";
|
|
48
|
+
ERR["characterReferenceOutsideUnicodeRange"] = "character-reference-outside-unicode-range";
|
|
49
|
+
ERR["controlCharacterReference"] = "control-character-reference";
|
|
50
|
+
ERR["noncharacterCharacterReference"] = "noncharacter-character-reference";
|
|
51
|
+
ERR["missingWhitespaceBeforeDoctypeName"] = "missing-whitespace-before-doctype-name";
|
|
52
|
+
ERR["missingDoctypeName"] = "missing-doctype-name";
|
|
53
|
+
ERR["invalidCharacterSequenceAfterDoctypeName"] = "invalid-character-sequence-after-doctype-name";
|
|
54
|
+
ERR["duplicateAttribute"] = "duplicate-attribute";
|
|
55
|
+
ERR["nonConformingDoctype"] = "non-conforming-doctype";
|
|
56
|
+
ERR["missingDoctype"] = "missing-doctype";
|
|
57
|
+
ERR["misplacedDoctype"] = "misplaced-doctype";
|
|
58
|
+
ERR["endTagWithoutMatchingOpenElement"] = "end-tag-without-matching-open-element";
|
|
59
|
+
ERR["closingOfElementWithOpenChildElements"] = "closing-of-element-with-open-child-elements";
|
|
60
|
+
ERR["disallowedContentInNoscriptInHead"] = "disallowed-content-in-noscript-in-head";
|
|
61
|
+
ERR["openElementsLeftAfterEof"] = "open-elements-left-after-eof";
|
|
62
|
+
ERR["abandonedHeadElementChild"] = "abandoned-head-element-child";
|
|
63
|
+
ERR["misplacedStartTagForHeadElement"] = "misplaced-start-tag-for-head-element";
|
|
64
|
+
ERR["nestedNoscriptInHead"] = "nested-noscript-in-head";
|
|
65
|
+
ERR["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text";
|
|
66
|
+
})(ERR = exports.ERR || (exports.ERR = {}));
|
|
67
|
+
//# sourceMappingURL=error-codes.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { TAG_ID as $, NS } from './html.js';
|
|
2
|
+
import type { TagToken, Attribute } from './token.js';
|
|
3
|
+
export declare const SVG_TAG_NAMES_ADJUSTMENT_MAP: Map<string, string>;
|
|
4
|
+
export declare function causesExit(startTagToken: TagToken): boolean;
|
|
5
|
+
export declare function adjustTokenMathMLAttrs(token: TagToken): void;
|
|
6
|
+
export declare function adjustTokenSVGAttrs(token: TagToken): void;
|
|
7
|
+
export declare function adjustTokenXMLAttrs(token: TagToken): void;
|
|
8
|
+
export declare function adjustTokenSVGTagName(token: TagToken): void;
|
|
9
|
+
export declare function isIntegrationPoint(tn: $, ns: NS, attrs: Attribute[], foreignNS?: NS): boolean;
|
|
10
|
+
//# sourceMappingURL=foreign-content.d.ts.map
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isIntegrationPoint = exports.adjustTokenSVGTagName = exports.adjustTokenXMLAttrs = exports.adjustTokenSVGAttrs = exports.adjustTokenMathMLAttrs = exports.causesExit = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = void 0;
|
|
4
|
+
const html_js_1 = require("./html.js");
|
|
5
|
+
//MIME types
|
|
6
|
+
const MIME_TYPES = {
|
|
7
|
+
TEXT_HTML: 'text/html',
|
|
8
|
+
APPLICATION_XML: 'application/xhtml+xml',
|
|
9
|
+
};
|
|
10
|
+
//Attributes
|
|
11
|
+
const DEFINITION_URL_ATTR = 'definitionurl';
|
|
12
|
+
const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL';
|
|
13
|
+
const SVG_ATTRS_ADJUSTMENT_MAP = new Map([
|
|
14
|
+
'attributeName',
|
|
15
|
+
'attributeType',
|
|
16
|
+
'baseFrequency',
|
|
17
|
+
'baseProfile',
|
|
18
|
+
'calcMode',
|
|
19
|
+
'clipPathUnits',
|
|
20
|
+
'diffuseConstant',
|
|
21
|
+
'edgeMode',
|
|
22
|
+
'filterUnits',
|
|
23
|
+
'glyphRef',
|
|
24
|
+
'gradientTransform',
|
|
25
|
+
'gradientUnits',
|
|
26
|
+
'kernelMatrix',
|
|
27
|
+
'kernelUnitLength',
|
|
28
|
+
'keyPoints',
|
|
29
|
+
'keySplines',
|
|
30
|
+
'keyTimes',
|
|
31
|
+
'lengthAdjust',
|
|
32
|
+
'limitingConeAngle',
|
|
33
|
+
'markerHeight',
|
|
34
|
+
'markerUnits',
|
|
35
|
+
'markerWidth',
|
|
36
|
+
'maskContentUnits',
|
|
37
|
+
'maskUnits',
|
|
38
|
+
'numOctaves',
|
|
39
|
+
'pathLength',
|
|
40
|
+
'patternContentUnits',
|
|
41
|
+
'patternTransform',
|
|
42
|
+
'patternUnits',
|
|
43
|
+
'pointsAtX',
|
|
44
|
+
'pointsAtY',
|
|
45
|
+
'pointsAtZ',
|
|
46
|
+
'preserveAlpha',
|
|
47
|
+
'preserveAspectRatio',
|
|
48
|
+
'primitiveUnits',
|
|
49
|
+
'refX',
|
|
50
|
+
'refY',
|
|
51
|
+
'repeatCount',
|
|
52
|
+
'repeatDur',
|
|
53
|
+
'requiredExtensions',
|
|
54
|
+
'requiredFeatures',
|
|
55
|
+
'specularConstant',
|
|
56
|
+
'specularExponent',
|
|
57
|
+
'spreadMethod',
|
|
58
|
+
'startOffset',
|
|
59
|
+
'stdDeviation',
|
|
60
|
+
'stitchTiles',
|
|
61
|
+
'surfaceScale',
|
|
62
|
+
'systemLanguage',
|
|
63
|
+
'tableValues',
|
|
64
|
+
'targetX',
|
|
65
|
+
'targetY',
|
|
66
|
+
'textLength',
|
|
67
|
+
'viewBox',
|
|
68
|
+
'viewTarget',
|
|
69
|
+
'xChannelSelector',
|
|
70
|
+
'yChannelSelector',
|
|
71
|
+
'zoomAndPan',
|
|
72
|
+
].map((attr) => [attr.toLowerCase(), attr]));
|
|
73
|
+
const XML_ATTRS_ADJUSTMENT_MAP = new Map([
|
|
74
|
+
['xlink:actuate', { prefix: 'xlink', name: 'actuate', namespace: html_js_1.NS.XLINK }],
|
|
75
|
+
['xlink:arcrole', { prefix: 'xlink', name: 'arcrole', namespace: html_js_1.NS.XLINK }],
|
|
76
|
+
['xlink:href', { prefix: 'xlink', name: 'href', namespace: html_js_1.NS.XLINK }],
|
|
77
|
+
['xlink:role', { prefix: 'xlink', name: 'role', namespace: html_js_1.NS.XLINK }],
|
|
78
|
+
['xlink:show', { prefix: 'xlink', name: 'show', namespace: html_js_1.NS.XLINK }],
|
|
79
|
+
['xlink:title', { prefix: 'xlink', name: 'title', namespace: html_js_1.NS.XLINK }],
|
|
80
|
+
['xlink:type', { prefix: 'xlink', name: 'type', namespace: html_js_1.NS.XLINK }],
|
|
81
|
+
['xml:base', { prefix: 'xml', name: 'base', namespace: html_js_1.NS.XML }],
|
|
82
|
+
['xml:lang', { prefix: 'xml', name: 'lang', namespace: html_js_1.NS.XML }],
|
|
83
|
+
['xml:space', { prefix: 'xml', name: 'space', namespace: html_js_1.NS.XML }],
|
|
84
|
+
['xmlns', { prefix: '', name: 'xmlns', namespace: html_js_1.NS.XMLNS }],
|
|
85
|
+
['xmlns:xlink', { prefix: 'xmlns', name: 'xlink', namespace: html_js_1.NS.XMLNS }],
|
|
86
|
+
]);
|
|
87
|
+
//SVG tag names adjustment map
|
|
88
|
+
exports.SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map([
|
|
89
|
+
'altGlyph',
|
|
90
|
+
'altGlyphDef',
|
|
91
|
+
'altGlyphItem',
|
|
92
|
+
'animateColor',
|
|
93
|
+
'animateMotion',
|
|
94
|
+
'animateTransform',
|
|
95
|
+
'clipPath',
|
|
96
|
+
'feBlend',
|
|
97
|
+
'feColorMatrix',
|
|
98
|
+
'feComponentTransfer',
|
|
99
|
+
'feComposite',
|
|
100
|
+
'feConvolveMatrix',
|
|
101
|
+
'feDiffuseLighting',
|
|
102
|
+
'feDisplacementMap',
|
|
103
|
+
'feDistantLight',
|
|
104
|
+
'feFlood',
|
|
105
|
+
'feFuncA',
|
|
106
|
+
'feFuncB',
|
|
107
|
+
'feFuncG',
|
|
108
|
+
'feFuncR',
|
|
109
|
+
'feGaussianBlur',
|
|
110
|
+
'feImage',
|
|
111
|
+
'feMerge',
|
|
112
|
+
'feMergeNode',
|
|
113
|
+
'feMorphology',
|
|
114
|
+
'feOffset',
|
|
115
|
+
'fePointLight',
|
|
116
|
+
'feSpecularLighting',
|
|
117
|
+
'feSpotLight',
|
|
118
|
+
'feTile',
|
|
119
|
+
'feTurbulence',
|
|
120
|
+
'foreignObject',
|
|
121
|
+
'glyphRef',
|
|
122
|
+
'linearGradient',
|
|
123
|
+
'radialGradient',
|
|
124
|
+
'textPath',
|
|
125
|
+
].map((tn) => [tn.toLowerCase(), tn]));
|
|
126
|
+
//Tags that causes exit from foreign content
|
|
127
|
+
const EXITS_FOREIGN_CONTENT = new Set([
|
|
128
|
+
html_js_1.TAG_ID.B,
|
|
129
|
+
html_js_1.TAG_ID.BIG,
|
|
130
|
+
html_js_1.TAG_ID.BLOCKQUOTE,
|
|
131
|
+
html_js_1.TAG_ID.BODY,
|
|
132
|
+
html_js_1.TAG_ID.BR,
|
|
133
|
+
html_js_1.TAG_ID.CENTER,
|
|
134
|
+
html_js_1.TAG_ID.CODE,
|
|
135
|
+
html_js_1.TAG_ID.DD,
|
|
136
|
+
html_js_1.TAG_ID.DIV,
|
|
137
|
+
html_js_1.TAG_ID.DL,
|
|
138
|
+
html_js_1.TAG_ID.DT,
|
|
139
|
+
html_js_1.TAG_ID.EM,
|
|
140
|
+
html_js_1.TAG_ID.EMBED,
|
|
141
|
+
html_js_1.TAG_ID.H1,
|
|
142
|
+
html_js_1.TAG_ID.H2,
|
|
143
|
+
html_js_1.TAG_ID.H3,
|
|
144
|
+
html_js_1.TAG_ID.H4,
|
|
145
|
+
html_js_1.TAG_ID.H5,
|
|
146
|
+
html_js_1.TAG_ID.H6,
|
|
147
|
+
html_js_1.TAG_ID.HEAD,
|
|
148
|
+
html_js_1.TAG_ID.HR,
|
|
149
|
+
html_js_1.TAG_ID.I,
|
|
150
|
+
html_js_1.TAG_ID.IMG,
|
|
151
|
+
html_js_1.TAG_ID.LI,
|
|
152
|
+
html_js_1.TAG_ID.LISTING,
|
|
153
|
+
html_js_1.TAG_ID.MENU,
|
|
154
|
+
html_js_1.TAG_ID.META,
|
|
155
|
+
html_js_1.TAG_ID.NOBR,
|
|
156
|
+
html_js_1.TAG_ID.OL,
|
|
157
|
+
html_js_1.TAG_ID.P,
|
|
158
|
+
html_js_1.TAG_ID.PRE,
|
|
159
|
+
html_js_1.TAG_ID.RUBY,
|
|
160
|
+
html_js_1.TAG_ID.S,
|
|
161
|
+
html_js_1.TAG_ID.SMALL,
|
|
162
|
+
html_js_1.TAG_ID.SPAN,
|
|
163
|
+
html_js_1.TAG_ID.STRONG,
|
|
164
|
+
html_js_1.TAG_ID.STRIKE,
|
|
165
|
+
html_js_1.TAG_ID.SUB,
|
|
166
|
+
html_js_1.TAG_ID.SUP,
|
|
167
|
+
html_js_1.TAG_ID.TABLE,
|
|
168
|
+
html_js_1.TAG_ID.TT,
|
|
169
|
+
html_js_1.TAG_ID.U,
|
|
170
|
+
html_js_1.TAG_ID.UL,
|
|
171
|
+
html_js_1.TAG_ID.VAR,
|
|
172
|
+
]);
|
|
173
|
+
//Check exit from foreign content
|
|
174
|
+
function causesExit(startTagToken) {
|
|
175
|
+
const tn = startTagToken.tagID;
|
|
176
|
+
const isFontWithAttrs = tn === html_js_1.TAG_ID.FONT &&
|
|
177
|
+
startTagToken.attrs.some(({ name }) => name === html_js_1.ATTRS.COLOR || name === html_js_1.ATTRS.SIZE || name === html_js_1.ATTRS.FACE);
|
|
178
|
+
return isFontWithAttrs || EXITS_FOREIGN_CONTENT.has(tn);
|
|
179
|
+
}
|
|
180
|
+
exports.causesExit = causesExit;
|
|
181
|
+
//Token adjustments
|
|
182
|
+
function adjustTokenMathMLAttrs(token) {
|
|
183
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
184
|
+
if (token.attrs[i].name === DEFINITION_URL_ATTR) {
|
|
185
|
+
token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
|
|
186
|
+
break;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
exports.adjustTokenMathMLAttrs = adjustTokenMathMLAttrs;
|
|
191
|
+
function adjustTokenSVGAttrs(token) {
|
|
192
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
193
|
+
const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
|
|
194
|
+
if (adjustedAttrName != null) {
|
|
195
|
+
token.attrs[i].name = adjustedAttrName;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
exports.adjustTokenSVGAttrs = adjustTokenSVGAttrs;
|
|
200
|
+
function adjustTokenXMLAttrs(token) {
|
|
201
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
202
|
+
const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
|
|
203
|
+
if (adjustedAttrEntry) {
|
|
204
|
+
token.attrs[i].prefix = adjustedAttrEntry.prefix;
|
|
205
|
+
token.attrs[i].name = adjustedAttrEntry.name;
|
|
206
|
+
token.attrs[i].namespace = adjustedAttrEntry.namespace;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
exports.adjustTokenXMLAttrs = adjustTokenXMLAttrs;
|
|
211
|
+
function adjustTokenSVGTagName(token) {
|
|
212
|
+
const adjustedTagName = exports.SVG_TAG_NAMES_ADJUSTMENT_MAP.get(token.tagName);
|
|
213
|
+
if (adjustedTagName != null) {
|
|
214
|
+
token.tagName = adjustedTagName;
|
|
215
|
+
token.tagID = (0, html_js_1.getTagID)(token.tagName);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
exports.adjustTokenSVGTagName = adjustTokenSVGTagName;
|
|
219
|
+
//Integration points
|
|
220
|
+
function isMathMLTextIntegrationPoint(tn, ns) {
|
|
221
|
+
return ns === html_js_1.NS.MATHML && (tn === html_js_1.TAG_ID.MI || tn === html_js_1.TAG_ID.MO || tn === html_js_1.TAG_ID.MN || tn === html_js_1.TAG_ID.MS || tn === html_js_1.TAG_ID.MTEXT);
|
|
222
|
+
}
|
|
223
|
+
function isHtmlIntegrationPoint(tn, ns, attrs) {
|
|
224
|
+
if (ns === html_js_1.NS.MATHML && tn === html_js_1.TAG_ID.ANNOTATION_XML) {
|
|
225
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
226
|
+
if (attrs[i].name === html_js_1.ATTRS.ENCODING) {
|
|
227
|
+
const value = attrs[i].value.toLowerCase();
|
|
228
|
+
return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
return ns === html_js_1.NS.SVG && (tn === html_js_1.TAG_ID.FOREIGN_OBJECT || tn === html_js_1.TAG_ID.DESC || tn === html_js_1.TAG_ID.TITLE);
|
|
233
|
+
}
|
|
234
|
+
function isIntegrationPoint(tn, ns, attrs, foreignNS) {
|
|
235
|
+
return (((!foreignNS || foreignNS === html_js_1.NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) ||
|
|
236
|
+
((!foreignNS || foreignNS === html_js_1.NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns)));
|
|
237
|
+
}
|
|
238
|
+
exports.isIntegrationPoint = isIntegrationPoint;
|
|
239
|
+
//# sourceMappingURL=foreign-content.js.map
|