1 | import { DOCUMENT_MODE } from './html.js';
|
2 |
|
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 |
|
80 | function hasPrefix(publicId, prefixes) {
|
81 | return prefixes.some((prefix) => publicId.startsWith(prefix));
|
82 | }
|
83 |
|
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 | }
|
115 |
|
\ | No newline at end of file |