@cjser/parse5 0.0.0-stage → 8.0.1-cjser.2
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/LICENSE +19 -0
- package/README.md +42 -2
- package/dist/common/doctype.d.ts +4 -0
- package/dist/common/doctype.js +114 -0
- package/dist/common/error-codes.d.ts +67 -0
- package/dist/common/error-codes.js +63 -0
- package/dist/common/foreign-content.d.ts +9 -0
- package/dist/common/foreign-content.js +228 -0
- package/dist/common/html.d.ts +289 -0
- package/dist/common/html.js +523 -0
- package/dist/common/token.d.ts +84 -0
- package/dist/common/token.js +20 -0
- package/dist/common/unicode.d.ts +42 -0
- package/dist/common/unicode.js +62 -0
- package/dist/index.d.ts +71 -0
- package/dist/index.js +42 -0
- package/dist/parser/formatting-element-list.d.ts +36 -0
- package/dist/parser/formatting-element-list.js +110 -0
- package/dist/parser/index.d.ts +221 -0
- package/dist/parser/index.js +3245 -0
- package/dist/parser/open-element-stack.d.ts +53 -0
- package/dist/parser/open-element-stack.js +324 -0
- package/dist/serializer/index.d.ts +60 -0
- package/dist/serializer/index.js +168 -0
- package/dist/tokenizer/index.d.ts +247 -0
- package/dist/tokenizer/index.js +2712 -0
- package/dist/tokenizer/preprocessor.d.ts +36 -0
- package/dist/tokenizer/preprocessor.js +196 -0
- package/dist/tree-adapters/default.d.ts +84 -0
- package/dist/tree-adapters/default.js +173 -0
- package/dist/tree-adapters/interface.d.ts +255 -0
- package/dist/tree-adapters/interface.js +1 -0
- package/dist-cjser/index.cjs +7633 -0
- package/package.json +78 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
Copyright (c) 2013-2019 Ivan Nikulin (ifaaan@gmail.com, https://github.com/inikulin)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
in the Software without restriction, including without limitation the rights
|
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
furnished to do so, subject to the following conditions:
|
|
9
|
+
|
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
|
11
|
+
all copies or substantial portions of the Software.
|
|
12
|
+
|
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
+
THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,43 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<a href="https://github.com/inikulin/parse5">
|
|
3
|
+
<img src="https://raw.github.com/inikulin/parse5/master/media/logo.png" alt="parse5" />
|
|
4
|
+
</a>
|
|
5
|
+
</p>
|
|
2
6
|
|
|
3
|
-
|
|
7
|
+
<div align="center">
|
|
8
|
+
<h1>parse5</h1>
|
|
9
|
+
<i><b>HTML parser and serializer.</b></i>
|
|
10
|
+
</div>
|
|
11
|
+
<br>
|
|
12
|
+
|
|
13
|
+
<div align="center">
|
|
14
|
+
<code>npm install --save parse5</code>
|
|
15
|
+
</div>
|
|
16
|
+
<br>
|
|
17
|
+
|
|
18
|
+
<p align="center">
|
|
19
|
+
📖 <a href="https://parse5.js.org/modules/parse5.html"><b>Documentation</b></a> 📖
|
|
20
|
+
</p>
|
|
21
|
+
|
|
22
|
+
---
|
|
23
|
+
|
|
24
|
+
<p align="center">
|
|
25
|
+
<a href="https://github.com/inikulin/parse5/tree/master/docs/list-of-packages.md">List of parse5 toolset packages</a>
|
|
26
|
+
</p>
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<a href="https://github.com/inikulin/parse5">GitHub</a>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<p align="center">
|
|
33
|
+
<a href="http://astexplorer.net/#/1CHlCXc4n4">Online playground</a>
|
|
34
|
+
</p>
|
|
35
|
+
|
|
36
|
+
<p align="center">
|
|
37
|
+
<a href="https://github.com/inikulin/parse5/releases">Changelog</a>
|
|
38
|
+
</p>
|
|
39
|
+
|
|
40
|
+
## cjser
|
|
41
|
+
|
|
42
|
+
This package is a CommonJS-compatible build generated by cjser for projects that still need `require()` support. The source version matches the original npm package version, with a cjser prerelease suffix for this generated build.
|
|
43
|
+
Original repository: git://github.com/inikulin/parse5.git
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { DOCUMENT_MODE } from './html.js';
|
|
2
|
+
//Const
|
|
3
|
+
const VALID_DOCTYPE_NAME = 'html';
|
|
4
|
+
const VALID_SYSTEM_ID = 'about:legacy-compat';
|
|
5
|
+
const QUIRKS_MODE_SYSTEM_ID = 'http://www.ibm.com/data/dtd/v11/ibmxhtml1-transitional.dtd';
|
|
6
|
+
const QUIRKS_MODE_PUBLIC_ID_PREFIXES = [
|
|
7
|
+
'+//silmaril//dtd html pro v0r11 19970101//',
|
|
8
|
+
'-//as//dtd html 3.0 aswedit + extensions//',
|
|
9
|
+
'-//advasoft ltd//dtd html 3.0 aswedit + extensions//',
|
|
10
|
+
'-//ietf//dtd html 2.0 level 1//',
|
|
11
|
+
'-//ietf//dtd html 2.0 level 2//',
|
|
12
|
+
'-//ietf//dtd html 2.0 strict level 1//',
|
|
13
|
+
'-//ietf//dtd html 2.0 strict level 2//',
|
|
14
|
+
'-//ietf//dtd html 2.0 strict//',
|
|
15
|
+
'-//ietf//dtd html 2.0//',
|
|
16
|
+
'-//ietf//dtd html 2.1e//',
|
|
17
|
+
'-//ietf//dtd html 3.0//',
|
|
18
|
+
'-//ietf//dtd html 3.2 final//',
|
|
19
|
+
'-//ietf//dtd html 3.2//',
|
|
20
|
+
'-//ietf//dtd html 3//',
|
|
21
|
+
'-//ietf//dtd html level 0//',
|
|
22
|
+
'-//ietf//dtd html level 1//',
|
|
23
|
+
'-//ietf//dtd html level 2//',
|
|
24
|
+
'-//ietf//dtd html level 3//',
|
|
25
|
+
'-//ietf//dtd html strict level 0//',
|
|
26
|
+
'-//ietf//dtd html strict level 1//',
|
|
27
|
+
'-//ietf//dtd html strict level 2//',
|
|
28
|
+
'-//ietf//dtd html strict level 3//',
|
|
29
|
+
'-//ietf//dtd html strict//',
|
|
30
|
+
'-//ietf//dtd html//',
|
|
31
|
+
'-//metrius//dtd metrius presentational//',
|
|
32
|
+
'-//microsoft//dtd internet explorer 2.0 html strict//',
|
|
33
|
+
'-//microsoft//dtd internet explorer 2.0 html//',
|
|
34
|
+
'-//microsoft//dtd internet explorer 2.0 tables//',
|
|
35
|
+
'-//microsoft//dtd internet explorer 3.0 html strict//',
|
|
36
|
+
'-//microsoft//dtd internet explorer 3.0 html//',
|
|
37
|
+
'-//microsoft//dtd internet explorer 3.0 tables//',
|
|
38
|
+
'-//netscape comm. corp.//dtd html//',
|
|
39
|
+
'-//netscape comm. corp.//dtd strict html//',
|
|
40
|
+
"-//o'reilly and associates//dtd html 2.0//",
|
|
41
|
+
"-//o'reilly and associates//dtd html extended 1.0//",
|
|
42
|
+
"-//o'reilly and associates//dtd html extended relaxed 1.0//",
|
|
43
|
+
'-//sq//dtd html 2.0 hotmetal + extensions//',
|
|
44
|
+
'-//softquad software//dtd hotmetal pro 6.0::19990601::extensions to html 4.0//',
|
|
45
|
+
'-//softquad//dtd hotmetal pro 4.0::19971010::extensions to html 4.0//',
|
|
46
|
+
'-//spyglass//dtd html 2.0 extended//',
|
|
47
|
+
'-//sun microsystems corp.//dtd hotjava html//',
|
|
48
|
+
'-//sun microsystems corp.//dtd hotjava strict html//',
|
|
49
|
+
'-//w3c//dtd html 3 1995-03-24//',
|
|
50
|
+
'-//w3c//dtd html 3.2 draft//',
|
|
51
|
+
'-//w3c//dtd html 3.2 final//',
|
|
52
|
+
'-//w3c//dtd html 3.2//',
|
|
53
|
+
'-//w3c//dtd html 3.2s draft//',
|
|
54
|
+
'-//w3c//dtd html 4.0 frameset//',
|
|
55
|
+
'-//w3c//dtd html 4.0 transitional//',
|
|
56
|
+
'-//w3c//dtd html experimental 19960712//',
|
|
57
|
+
'-//w3c//dtd html experimental 970421//',
|
|
58
|
+
'-//w3c//dtd w3 html//',
|
|
59
|
+
'-//w3o//dtd w3 html 3.0//',
|
|
60
|
+
'-//webtechs//dtd mozilla html 2.0//',
|
|
61
|
+
'-//webtechs//dtd mozilla html//',
|
|
62
|
+
];
|
|
63
|
+
const QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
|
|
64
|
+
...QUIRKS_MODE_PUBLIC_ID_PREFIXES,
|
|
65
|
+
'-//w3c//dtd html 4.01 frameset//',
|
|
66
|
+
'-//w3c//dtd html 4.01 transitional//',
|
|
67
|
+
];
|
|
68
|
+
const QUIRKS_MODE_PUBLIC_IDS = new Set([
|
|
69
|
+
'-//w3o//dtd w3 html strict 3.0//en//',
|
|
70
|
+
'-/w3c/dtd html 4.0 transitional/en',
|
|
71
|
+
'html',
|
|
72
|
+
]);
|
|
73
|
+
const LIMITED_QUIRKS_PUBLIC_ID_PREFIXES = ['-//w3c//dtd xhtml 1.0 frameset//', '-//w3c//dtd xhtml 1.0 transitional//'];
|
|
74
|
+
const LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES = [
|
|
75
|
+
...LIMITED_QUIRKS_PUBLIC_ID_PREFIXES,
|
|
76
|
+
'-//w3c//dtd html 4.01 frameset//',
|
|
77
|
+
'-//w3c//dtd html 4.01 transitional//',
|
|
78
|
+
];
|
|
79
|
+
//Utils
|
|
80
|
+
function hasPrefix(publicId, prefixes) {
|
|
81
|
+
return prefixes.some((prefix) => publicId.startsWith(prefix));
|
|
82
|
+
}
|
|
83
|
+
//API
|
|
84
|
+
export function isConforming(token) {
|
|
85
|
+
return (token.name === VALID_DOCTYPE_NAME &&
|
|
86
|
+
token.publicId === null &&
|
|
87
|
+
(token.systemId === null || token.systemId === VALID_SYSTEM_ID));
|
|
88
|
+
}
|
|
89
|
+
export function getDocumentMode(token) {
|
|
90
|
+
if (token.name !== VALID_DOCTYPE_NAME) {
|
|
91
|
+
return DOCUMENT_MODE.QUIRKS;
|
|
92
|
+
}
|
|
93
|
+
const { systemId } = token;
|
|
94
|
+
if (systemId && systemId.toLowerCase() === QUIRKS_MODE_SYSTEM_ID) {
|
|
95
|
+
return DOCUMENT_MODE.QUIRKS;
|
|
96
|
+
}
|
|
97
|
+
let { publicId } = token;
|
|
98
|
+
if (publicId !== null) {
|
|
99
|
+
publicId = publicId.toLowerCase();
|
|
100
|
+
if (QUIRKS_MODE_PUBLIC_IDS.has(publicId)) {
|
|
101
|
+
return DOCUMENT_MODE.QUIRKS;
|
|
102
|
+
}
|
|
103
|
+
let prefixes = systemId === null ? QUIRKS_MODE_NO_SYSTEM_ID_PUBLIC_ID_PREFIXES : QUIRKS_MODE_PUBLIC_ID_PREFIXES;
|
|
104
|
+
if (hasPrefix(publicId, prefixes)) {
|
|
105
|
+
return DOCUMENT_MODE.QUIRKS;
|
|
106
|
+
}
|
|
107
|
+
prefixes =
|
|
108
|
+
systemId === null ? LIMITED_QUIRKS_PUBLIC_ID_PREFIXES : LIMITED_QUIRKS_WITH_SYSTEM_ID_PUBLIC_ID_PREFIXES;
|
|
109
|
+
if (hasPrefix(publicId, prefixes)) {
|
|
110
|
+
return DOCUMENT_MODE.LIMITED_QUIRKS;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return DOCUMENT_MODE.NO_QUIRKS;
|
|
114
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Location } from './token.js';
|
|
2
|
+
export interface ParserError extends Location {
|
|
3
|
+
code: ERR;
|
|
4
|
+
}
|
|
5
|
+
export 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
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
export var ERR;
|
|
2
|
+
(function (ERR) {
|
|
3
|
+
ERR["controlCharacterInInputStream"] = "control-character-in-input-stream";
|
|
4
|
+
ERR["noncharacterInInputStream"] = "noncharacter-in-input-stream";
|
|
5
|
+
ERR["surrogateInInputStream"] = "surrogate-in-input-stream";
|
|
6
|
+
ERR["nonVoidHtmlElementStartTagWithTrailingSolidus"] = "non-void-html-element-start-tag-with-trailing-solidus";
|
|
7
|
+
ERR["endTagWithAttributes"] = "end-tag-with-attributes";
|
|
8
|
+
ERR["endTagWithTrailingSolidus"] = "end-tag-with-trailing-solidus";
|
|
9
|
+
ERR["unexpectedSolidusInTag"] = "unexpected-solidus-in-tag";
|
|
10
|
+
ERR["unexpectedNullCharacter"] = "unexpected-null-character";
|
|
11
|
+
ERR["unexpectedQuestionMarkInsteadOfTagName"] = "unexpected-question-mark-instead-of-tag-name";
|
|
12
|
+
ERR["invalidFirstCharacterOfTagName"] = "invalid-first-character-of-tag-name";
|
|
13
|
+
ERR["unexpectedEqualsSignBeforeAttributeName"] = "unexpected-equals-sign-before-attribute-name";
|
|
14
|
+
ERR["missingEndTagName"] = "missing-end-tag-name";
|
|
15
|
+
ERR["unexpectedCharacterInAttributeName"] = "unexpected-character-in-attribute-name";
|
|
16
|
+
ERR["unknownNamedCharacterReference"] = "unknown-named-character-reference";
|
|
17
|
+
ERR["missingSemicolonAfterCharacterReference"] = "missing-semicolon-after-character-reference";
|
|
18
|
+
ERR["unexpectedCharacterAfterDoctypeSystemIdentifier"] = "unexpected-character-after-doctype-system-identifier";
|
|
19
|
+
ERR["unexpectedCharacterInUnquotedAttributeValue"] = "unexpected-character-in-unquoted-attribute-value";
|
|
20
|
+
ERR["eofBeforeTagName"] = "eof-before-tag-name";
|
|
21
|
+
ERR["eofInTag"] = "eof-in-tag";
|
|
22
|
+
ERR["missingAttributeValue"] = "missing-attribute-value";
|
|
23
|
+
ERR["missingWhitespaceBetweenAttributes"] = "missing-whitespace-between-attributes";
|
|
24
|
+
ERR["missingWhitespaceAfterDoctypePublicKeyword"] = "missing-whitespace-after-doctype-public-keyword";
|
|
25
|
+
ERR["missingWhitespaceBetweenDoctypePublicAndSystemIdentifiers"] = "missing-whitespace-between-doctype-public-and-system-identifiers";
|
|
26
|
+
ERR["missingWhitespaceAfterDoctypeSystemKeyword"] = "missing-whitespace-after-doctype-system-keyword";
|
|
27
|
+
ERR["missingQuoteBeforeDoctypePublicIdentifier"] = "missing-quote-before-doctype-public-identifier";
|
|
28
|
+
ERR["missingQuoteBeforeDoctypeSystemIdentifier"] = "missing-quote-before-doctype-system-identifier";
|
|
29
|
+
ERR["missingDoctypePublicIdentifier"] = "missing-doctype-public-identifier";
|
|
30
|
+
ERR["missingDoctypeSystemIdentifier"] = "missing-doctype-system-identifier";
|
|
31
|
+
ERR["abruptDoctypePublicIdentifier"] = "abrupt-doctype-public-identifier";
|
|
32
|
+
ERR["abruptDoctypeSystemIdentifier"] = "abrupt-doctype-system-identifier";
|
|
33
|
+
ERR["cdataInHtmlContent"] = "cdata-in-html-content";
|
|
34
|
+
ERR["incorrectlyOpenedComment"] = "incorrectly-opened-comment";
|
|
35
|
+
ERR["eofInScriptHtmlCommentLikeText"] = "eof-in-script-html-comment-like-text";
|
|
36
|
+
ERR["eofInDoctype"] = "eof-in-doctype";
|
|
37
|
+
ERR["nestedComment"] = "nested-comment";
|
|
38
|
+
ERR["abruptClosingOfEmptyComment"] = "abrupt-closing-of-empty-comment";
|
|
39
|
+
ERR["eofInComment"] = "eof-in-comment";
|
|
40
|
+
ERR["incorrectlyClosedComment"] = "incorrectly-closed-comment";
|
|
41
|
+
ERR["eofInCdata"] = "eof-in-cdata";
|
|
42
|
+
ERR["absenceOfDigitsInNumericCharacterReference"] = "absence-of-digits-in-numeric-character-reference";
|
|
43
|
+
ERR["nullCharacterReference"] = "null-character-reference";
|
|
44
|
+
ERR["surrogateCharacterReference"] = "surrogate-character-reference";
|
|
45
|
+
ERR["characterReferenceOutsideUnicodeRange"] = "character-reference-outside-unicode-range";
|
|
46
|
+
ERR["controlCharacterReference"] = "control-character-reference";
|
|
47
|
+
ERR["noncharacterCharacterReference"] = "noncharacter-character-reference";
|
|
48
|
+
ERR["missingWhitespaceBeforeDoctypeName"] = "missing-whitespace-before-doctype-name";
|
|
49
|
+
ERR["missingDoctypeName"] = "missing-doctype-name";
|
|
50
|
+
ERR["invalidCharacterSequenceAfterDoctypeName"] = "invalid-character-sequence-after-doctype-name";
|
|
51
|
+
ERR["duplicateAttribute"] = "duplicate-attribute";
|
|
52
|
+
ERR["nonConformingDoctype"] = "non-conforming-doctype";
|
|
53
|
+
ERR["missingDoctype"] = "missing-doctype";
|
|
54
|
+
ERR["misplacedDoctype"] = "misplaced-doctype";
|
|
55
|
+
ERR["endTagWithoutMatchingOpenElement"] = "end-tag-without-matching-open-element";
|
|
56
|
+
ERR["closingOfElementWithOpenChildElements"] = "closing-of-element-with-open-child-elements";
|
|
57
|
+
ERR["disallowedContentInNoscriptInHead"] = "disallowed-content-in-noscript-in-head";
|
|
58
|
+
ERR["openElementsLeftAfterEof"] = "open-elements-left-after-eof";
|
|
59
|
+
ERR["abandonedHeadElementChild"] = "abandoned-head-element-child";
|
|
60
|
+
ERR["misplacedStartTagForHeadElement"] = "misplaced-start-tag-for-head-element";
|
|
61
|
+
ERR["nestedNoscriptInHead"] = "nested-noscript-in-head";
|
|
62
|
+
ERR["eofInElementThatCanContainOnlyText"] = "eof-in-element-that-can-contain-only-text";
|
|
63
|
+
})(ERR || (ERR = {}));
|
|
@@ -0,0 +1,9 @@
|
|
|
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;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { TAG_ID as $, NS, ATTRS, getTagID } from './html.js';
|
|
2
|
+
//MIME types
|
|
3
|
+
const MIME_TYPES = {
|
|
4
|
+
TEXT_HTML: 'text/html',
|
|
5
|
+
APPLICATION_XML: 'application/xhtml+xml',
|
|
6
|
+
};
|
|
7
|
+
//Attributes
|
|
8
|
+
const DEFINITION_URL_ATTR = 'definitionurl';
|
|
9
|
+
const ADJUSTED_DEFINITION_URL_ATTR = 'definitionURL';
|
|
10
|
+
const SVG_ATTRS_ADJUSTMENT_MAP = new Map([
|
|
11
|
+
'attributeName',
|
|
12
|
+
'attributeType',
|
|
13
|
+
'baseFrequency',
|
|
14
|
+
'baseProfile',
|
|
15
|
+
'calcMode',
|
|
16
|
+
'clipPathUnits',
|
|
17
|
+
'diffuseConstant',
|
|
18
|
+
'edgeMode',
|
|
19
|
+
'filterUnits',
|
|
20
|
+
'glyphRef',
|
|
21
|
+
'gradientTransform',
|
|
22
|
+
'gradientUnits',
|
|
23
|
+
'kernelMatrix',
|
|
24
|
+
'kernelUnitLength',
|
|
25
|
+
'keyPoints',
|
|
26
|
+
'keySplines',
|
|
27
|
+
'keyTimes',
|
|
28
|
+
'lengthAdjust',
|
|
29
|
+
'limitingConeAngle',
|
|
30
|
+
'markerHeight',
|
|
31
|
+
'markerUnits',
|
|
32
|
+
'markerWidth',
|
|
33
|
+
'maskContentUnits',
|
|
34
|
+
'maskUnits',
|
|
35
|
+
'numOctaves',
|
|
36
|
+
'pathLength',
|
|
37
|
+
'patternContentUnits',
|
|
38
|
+
'patternTransform',
|
|
39
|
+
'patternUnits',
|
|
40
|
+
'pointsAtX',
|
|
41
|
+
'pointsAtY',
|
|
42
|
+
'pointsAtZ',
|
|
43
|
+
'preserveAlpha',
|
|
44
|
+
'preserveAspectRatio',
|
|
45
|
+
'primitiveUnits',
|
|
46
|
+
'refX',
|
|
47
|
+
'refY',
|
|
48
|
+
'repeatCount',
|
|
49
|
+
'repeatDur',
|
|
50
|
+
'requiredExtensions',
|
|
51
|
+
'requiredFeatures',
|
|
52
|
+
'specularConstant',
|
|
53
|
+
'specularExponent',
|
|
54
|
+
'spreadMethod',
|
|
55
|
+
'startOffset',
|
|
56
|
+
'stdDeviation',
|
|
57
|
+
'stitchTiles',
|
|
58
|
+
'surfaceScale',
|
|
59
|
+
'systemLanguage',
|
|
60
|
+
'tableValues',
|
|
61
|
+
'targetX',
|
|
62
|
+
'targetY',
|
|
63
|
+
'textLength',
|
|
64
|
+
'viewBox',
|
|
65
|
+
'viewTarget',
|
|
66
|
+
'xChannelSelector',
|
|
67
|
+
'yChannelSelector',
|
|
68
|
+
'zoomAndPan',
|
|
69
|
+
].map((attr) => [attr.toLowerCase(), attr]));
|
|
70
|
+
const XML_ATTRS_ADJUSTMENT_MAP = new Map([
|
|
71
|
+
['xlink:actuate', { prefix: 'xlink', name: 'actuate', namespace: NS.XLINK }],
|
|
72
|
+
['xlink:arcrole', { prefix: 'xlink', name: 'arcrole', namespace: NS.XLINK }],
|
|
73
|
+
['xlink:href', { prefix: 'xlink', name: 'href', namespace: NS.XLINK }],
|
|
74
|
+
['xlink:role', { prefix: 'xlink', name: 'role', namespace: NS.XLINK }],
|
|
75
|
+
['xlink:show', { prefix: 'xlink', name: 'show', namespace: NS.XLINK }],
|
|
76
|
+
['xlink:title', { prefix: 'xlink', name: 'title', namespace: NS.XLINK }],
|
|
77
|
+
['xlink:type', { prefix: 'xlink', name: 'type', namespace: NS.XLINK }],
|
|
78
|
+
['xml:lang', { prefix: 'xml', name: 'lang', namespace: NS.XML }],
|
|
79
|
+
['xml:space', { prefix: 'xml', name: 'space', namespace: NS.XML }],
|
|
80
|
+
['xmlns', { prefix: '', name: 'xmlns', namespace: NS.XMLNS }],
|
|
81
|
+
['xmlns:xlink', { prefix: 'xmlns', name: 'xlink', namespace: NS.XMLNS }],
|
|
82
|
+
]);
|
|
83
|
+
//SVG tag names adjustment map
|
|
84
|
+
export const SVG_TAG_NAMES_ADJUSTMENT_MAP = new Map([
|
|
85
|
+
'altGlyph',
|
|
86
|
+
'altGlyphDef',
|
|
87
|
+
'altGlyphItem',
|
|
88
|
+
'animateColor',
|
|
89
|
+
'animateMotion',
|
|
90
|
+
'animateTransform',
|
|
91
|
+
'clipPath',
|
|
92
|
+
'feBlend',
|
|
93
|
+
'feColorMatrix',
|
|
94
|
+
'feComponentTransfer',
|
|
95
|
+
'feComposite',
|
|
96
|
+
'feConvolveMatrix',
|
|
97
|
+
'feDiffuseLighting',
|
|
98
|
+
'feDisplacementMap',
|
|
99
|
+
'feDistantLight',
|
|
100
|
+
'feFlood',
|
|
101
|
+
'feFuncA',
|
|
102
|
+
'feFuncB',
|
|
103
|
+
'feFuncG',
|
|
104
|
+
'feFuncR',
|
|
105
|
+
'feGaussianBlur',
|
|
106
|
+
'feImage',
|
|
107
|
+
'feMerge',
|
|
108
|
+
'feMergeNode',
|
|
109
|
+
'feMorphology',
|
|
110
|
+
'feOffset',
|
|
111
|
+
'fePointLight',
|
|
112
|
+
'feSpecularLighting',
|
|
113
|
+
'feSpotLight',
|
|
114
|
+
'feTile',
|
|
115
|
+
'feTurbulence',
|
|
116
|
+
'foreignObject',
|
|
117
|
+
'glyphRef',
|
|
118
|
+
'linearGradient',
|
|
119
|
+
'radialGradient',
|
|
120
|
+
'textPath',
|
|
121
|
+
].map((tn) => [tn.toLowerCase(), tn]));
|
|
122
|
+
//Tags that causes exit from foreign content
|
|
123
|
+
const EXITS_FOREIGN_CONTENT = new Set([
|
|
124
|
+
$.B,
|
|
125
|
+
$.BIG,
|
|
126
|
+
$.BLOCKQUOTE,
|
|
127
|
+
$.BODY,
|
|
128
|
+
$.BR,
|
|
129
|
+
$.CENTER,
|
|
130
|
+
$.CODE,
|
|
131
|
+
$.DD,
|
|
132
|
+
$.DIV,
|
|
133
|
+
$.DL,
|
|
134
|
+
$.DT,
|
|
135
|
+
$.EM,
|
|
136
|
+
$.EMBED,
|
|
137
|
+
$.H1,
|
|
138
|
+
$.H2,
|
|
139
|
+
$.H3,
|
|
140
|
+
$.H4,
|
|
141
|
+
$.H5,
|
|
142
|
+
$.H6,
|
|
143
|
+
$.HEAD,
|
|
144
|
+
$.HR,
|
|
145
|
+
$.I,
|
|
146
|
+
$.IMG,
|
|
147
|
+
$.LI,
|
|
148
|
+
$.LISTING,
|
|
149
|
+
$.MENU,
|
|
150
|
+
$.META,
|
|
151
|
+
$.NOBR,
|
|
152
|
+
$.OL,
|
|
153
|
+
$.P,
|
|
154
|
+
$.PRE,
|
|
155
|
+
$.RUBY,
|
|
156
|
+
$.S,
|
|
157
|
+
$.SMALL,
|
|
158
|
+
$.SPAN,
|
|
159
|
+
$.STRONG,
|
|
160
|
+
$.STRIKE,
|
|
161
|
+
$.SUB,
|
|
162
|
+
$.SUP,
|
|
163
|
+
$.TABLE,
|
|
164
|
+
$.TT,
|
|
165
|
+
$.U,
|
|
166
|
+
$.UL,
|
|
167
|
+
$.VAR,
|
|
168
|
+
]);
|
|
169
|
+
//Check exit from foreign content
|
|
170
|
+
export function causesExit(startTagToken) {
|
|
171
|
+
const tn = startTagToken.tagID;
|
|
172
|
+
const isFontWithAttrs = tn === $.FONT &&
|
|
173
|
+
startTagToken.attrs.some(({ name }) => name === ATTRS.COLOR || name === ATTRS.SIZE || name === ATTRS.FACE);
|
|
174
|
+
return isFontWithAttrs || EXITS_FOREIGN_CONTENT.has(tn);
|
|
175
|
+
}
|
|
176
|
+
//Token adjustments
|
|
177
|
+
export function adjustTokenMathMLAttrs(token) {
|
|
178
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
179
|
+
if (token.attrs[i].name === DEFINITION_URL_ATTR) {
|
|
180
|
+
token.attrs[i].name = ADJUSTED_DEFINITION_URL_ATTR;
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
export function adjustTokenSVGAttrs(token) {
|
|
186
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
187
|
+
const adjustedAttrName = SVG_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
|
|
188
|
+
if (adjustedAttrName != null) {
|
|
189
|
+
token.attrs[i].name = adjustedAttrName;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
export function adjustTokenXMLAttrs(token) {
|
|
194
|
+
for (let i = 0; i < token.attrs.length; i++) {
|
|
195
|
+
const adjustedAttrEntry = XML_ATTRS_ADJUSTMENT_MAP.get(token.attrs[i].name);
|
|
196
|
+
if (adjustedAttrEntry) {
|
|
197
|
+
token.attrs[i].prefix = adjustedAttrEntry.prefix;
|
|
198
|
+
token.attrs[i].name = adjustedAttrEntry.name;
|
|
199
|
+
token.attrs[i].namespace = adjustedAttrEntry.namespace;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
export function adjustTokenSVGTagName(token) {
|
|
204
|
+
const adjustedTagName = SVG_TAG_NAMES_ADJUSTMENT_MAP.get(token.tagName);
|
|
205
|
+
if (adjustedTagName != null) {
|
|
206
|
+
token.tagName = adjustedTagName;
|
|
207
|
+
token.tagID = getTagID(token.tagName);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//Integration points
|
|
211
|
+
function isMathMLTextIntegrationPoint(tn, ns) {
|
|
212
|
+
return ns === NS.MATHML && (tn === $.MI || tn === $.MO || tn === $.MN || tn === $.MS || tn === $.MTEXT);
|
|
213
|
+
}
|
|
214
|
+
function isHtmlIntegrationPoint(tn, ns, attrs) {
|
|
215
|
+
if (ns === NS.MATHML && tn === $.ANNOTATION_XML) {
|
|
216
|
+
for (let i = 0; i < attrs.length; i++) {
|
|
217
|
+
if (attrs[i].name === ATTRS.ENCODING) {
|
|
218
|
+
const value = attrs[i].value.toLowerCase();
|
|
219
|
+
return value === MIME_TYPES.TEXT_HTML || value === MIME_TYPES.APPLICATION_XML;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return ns === NS.SVG && (tn === $.FOREIGN_OBJECT || tn === $.DESC || tn === $.TITLE);
|
|
224
|
+
}
|
|
225
|
+
export function isIntegrationPoint(tn, ns, attrs, foreignNS) {
|
|
226
|
+
return (((!foreignNS || foreignNS === NS.HTML) && isHtmlIntegrationPoint(tn, ns, attrs)) ||
|
|
227
|
+
((!foreignNS || foreignNS === NS.MATHML) && isMathMLTextIntegrationPoint(tn, ns)));
|
|
228
|
+
}
|