open-agreements 0.7.6 → 0.7.7
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 +1 -1
- package/content/templates/openagreements-due-diligence-request-list/template.docx +0 -0
- package/content/templates/openagreements-due-diligence-request-list/template.md +1 -1
- package/dist/core/fill-pipeline.d.ts.map +1 -1
- package/dist/core/fill-pipeline.js +0 -8
- package/dist/core/fill-pipeline.js.map +1 -1
- package/dist/core/unified-pipeline.d.ts.map +1 -1
- package/dist/core/unified-pipeline.js +4 -6
- package/dist/core/unified-pipeline.js.map +1 -1
- package/gemini-extension.json +1 -1
- package/node_modules/@xmldom/xmldom/CHANGELOG.md +939 -0
- package/node_modules/@xmldom/xmldom/LICENSE +8 -0
- package/node_modules/@xmldom/xmldom/SECURITY.md +50 -0
- package/node_modules/@xmldom/xmldom/index.d.ts +1664 -0
- package/node_modules/@xmldom/xmldom/lib/.eslintrc.yml +3 -0
- package/node_modules/@xmldom/xmldom/lib/conventions.js +429 -0
- package/node_modules/@xmldom/xmldom/lib/dom-parser.js +586 -0
- package/node_modules/@xmldom/xmldom/lib/dom.js +3192 -0
- package/node_modules/@xmldom/xmldom/lib/entities.js +2171 -0
- package/node_modules/@xmldom/xmldom/lib/errors.js +202 -0
- package/node_modules/@xmldom/xmldom/lib/grammar.js +533 -0
- package/node_modules/@xmldom/xmldom/lib/index.js +41 -0
- package/node_modules/@xmldom/xmldom/lib/sax.js +929 -0
- package/node_modules/@xmldom/xmldom/package.json +74 -0
- package/node_modules/@xmldom/xmldom/readme.md +364 -0
- package/node_modules/core-util-is/LICENSE +19 -0
- package/node_modules/core-util-is/README.md +3 -0
- package/node_modules/core-util-is/lib/util.js +107 -0
- package/node_modules/core-util-is/package.json +38 -0
- package/node_modules/immediate/LICENSE.txt +20 -0
- package/node_modules/immediate/README.md +93 -0
- package/node_modules/immediate/dist/immediate.js +75 -0
- package/node_modules/immediate/dist/immediate.min.js +1 -0
- package/node_modules/immediate/lib/browser.js +69 -0
- package/node_modules/immediate/lib/index.js +73 -0
- package/node_modules/immediate/package.json +42 -0
- package/node_modules/inherits/LICENSE +16 -0
- package/node_modules/inherits/README.md +42 -0
- package/node_modules/inherits/inherits.js +9 -0
- package/node_modules/inherits/inherits_browser.js +27 -0
- package/node_modules/inherits/package.json +29 -0
- package/node_modules/isarray/.npmignore +1 -0
- package/node_modules/isarray/.travis.yml +4 -0
- package/node_modules/isarray/Makefile +6 -0
- package/node_modules/isarray/README.md +60 -0
- package/node_modules/isarray/component.json +19 -0
- package/node_modules/isarray/index.js +5 -0
- package/node_modules/isarray/package.json +45 -0
- package/node_modules/isarray/test.js +20 -0
- package/node_modules/jszip/.codeclimate.yml +16 -0
- package/node_modules/jszip/.editorconfig +8 -0
- package/node_modules/jszip/.eslintrc.js +43 -0
- package/node_modules/jszip/.github/workflows/pr.yaml +58 -0
- package/node_modules/jszip/.jekyll-metadata +0 -0
- package/node_modules/jszip/.travis.yml +17 -0
- package/node_modules/jszip/CHANGES.md +204 -0
- package/node_modules/jszip/LICENSE.markdown +651 -0
- package/node_modules/jszip/README.markdown +33 -0
- package/node_modules/jszip/deps.js +37 -0
- package/node_modules/jszip/dist/jszip.js +11577 -0
- package/node_modules/jszip/dist/jszip.min.js +13 -0
- package/node_modules/jszip/graph.svg +601 -0
- package/node_modules/jszip/index.d.ts +330 -0
- package/node_modules/jszip/lib/base64.js +106 -0
- package/node_modules/jszip/lib/compressedObject.js +74 -0
- package/node_modules/jszip/lib/compressions.js +14 -0
- package/node_modules/jszip/lib/crc32.js +77 -0
- package/node_modules/jszip/lib/defaults.js +11 -0
- package/node_modules/jszip/lib/external.js +18 -0
- package/node_modules/jszip/lib/flate.js +85 -0
- package/node_modules/jszip/lib/generate/ZipFileWorker.js +539 -0
- package/node_modules/jszip/lib/generate/index.js +57 -0
- package/node_modules/jszip/lib/index.js +55 -0
- package/node_modules/jszip/lib/license_header.js +11 -0
- package/node_modules/jszip/lib/load.js +88 -0
- package/node_modules/jszip/lib/nodejs/NodejsStreamInputAdapter.js +74 -0
- package/node_modules/jszip/lib/nodejs/NodejsStreamOutputAdapter.js +42 -0
- package/node_modules/jszip/lib/nodejsUtils.js +57 -0
- package/node_modules/jszip/lib/object.js +384 -0
- package/node_modules/jszip/lib/readable-stream-browser.js +10 -0
- package/node_modules/jszip/lib/reader/ArrayReader.js +57 -0
- package/node_modules/jszip/lib/reader/DataReader.js +116 -0
- package/node_modules/jszip/lib/reader/NodeBufferReader.js +19 -0
- package/node_modules/jszip/lib/reader/StringReader.js +38 -0
- package/node_modules/jszip/lib/reader/Uint8ArrayReader.js +22 -0
- package/node_modules/jszip/lib/reader/readerFor.js +28 -0
- package/node_modules/jszip/lib/signature.js +7 -0
- package/node_modules/jszip/lib/stream/ConvertWorker.js +26 -0
- package/node_modules/jszip/lib/stream/Crc32Probe.js +24 -0
- package/node_modules/jszip/lib/stream/DataLengthProbe.js +29 -0
- package/node_modules/jszip/lib/stream/DataWorker.js +116 -0
- package/node_modules/jszip/lib/stream/GenericWorker.js +263 -0
- package/node_modules/jszip/lib/stream/StreamHelper.js +214 -0
- package/node_modules/jszip/lib/support.js +38 -0
- package/node_modules/jszip/lib/utf8.js +275 -0
- package/node_modules/jszip/lib/utils.js +501 -0
- package/node_modules/jszip/lib/zipEntries.js +261 -0
- package/node_modules/jszip/lib/zipEntry.js +293 -0
- package/node_modules/jszip/lib/zipObject.js +133 -0
- package/node_modules/jszip/package.json +67 -0
- package/node_modules/jszip/sponsors.md +21 -0
- package/node_modules/jszip/tsconfig.json +101 -0
- package/node_modules/jszip/vendor/FileSaver.js +247 -0
- package/node_modules/lie/README.md +62 -0
- package/node_modules/lie/dist/lie.js +350 -0
- package/node_modules/lie/dist/lie.min.js +1 -0
- package/node_modules/lie/dist/lie.polyfill.js +358 -0
- package/node_modules/lie/dist/lie.polyfill.min.js +1 -0
- package/node_modules/lie/lib/browser.js +273 -0
- package/node_modules/lie/lib/index.js +298 -0
- package/node_modules/lie/license.md +7 -0
- package/node_modules/lie/lie.d.ts +244 -0
- package/node_modules/lie/package.json +69 -0
- package/node_modules/lie/polyfill.js +4 -0
- package/node_modules/pako/LICENSE +21 -0
- package/node_modules/pako/README.md +191 -0
- package/node_modules/pako/dist/pako.js +6818 -0
- package/node_modules/pako/dist/pako.min.js +1 -0
- package/node_modules/pako/dist/pako_deflate.js +3997 -0
- package/node_modules/pako/dist/pako_deflate.min.js +1 -0
- package/node_modules/pako/dist/pako_inflate.js +3300 -0
- package/node_modules/pako/dist/pako_inflate.min.js +1 -0
- package/node_modules/pako/index.js +14 -0
- package/node_modules/pako/lib/deflate.js +400 -0
- package/node_modules/pako/lib/inflate.js +423 -0
- package/node_modules/pako/lib/utils/common.js +105 -0
- package/node_modules/pako/lib/utils/strings.js +187 -0
- package/node_modules/pako/lib/zlib/README +59 -0
- package/node_modules/pako/lib/zlib/adler32.js +51 -0
- package/node_modules/pako/lib/zlib/constants.js +68 -0
- package/node_modules/pako/lib/zlib/crc32.js +59 -0
- package/node_modules/pako/lib/zlib/deflate.js +1874 -0
- package/node_modules/pako/lib/zlib/gzheader.js +58 -0
- package/node_modules/pako/lib/zlib/inffast.js +345 -0
- package/node_modules/pako/lib/zlib/inflate.js +1556 -0
- package/node_modules/pako/lib/zlib/inftrees.js +343 -0
- package/node_modules/pako/lib/zlib/messages.js +32 -0
- package/node_modules/pako/lib/zlib/trees.js +1222 -0
- package/node_modules/pako/lib/zlib/zstream.js +47 -0
- package/node_modules/pako/package.json +44 -0
- package/node_modules/process-nextick-args/index.js +45 -0
- package/node_modules/process-nextick-args/license.md +19 -0
- package/node_modules/process-nextick-args/package.json +25 -0
- package/node_modules/process-nextick-args/readme.md +18 -0
- package/node_modules/readable-stream/.travis.yml +34 -0
- package/node_modules/readable-stream/CONTRIBUTING.md +38 -0
- package/node_modules/readable-stream/GOVERNANCE.md +136 -0
- package/node_modules/readable-stream/LICENSE +47 -0
- package/node_modules/readable-stream/README.md +58 -0
- package/node_modules/readable-stream/doc/wg-meetings/2015-01-30.md +60 -0
- package/node_modules/readable-stream/duplex-browser.js +1 -0
- package/node_modules/readable-stream/duplex.js +1 -0
- package/node_modules/readable-stream/lib/_stream_duplex.js +131 -0
- package/node_modules/readable-stream/lib/_stream_passthrough.js +47 -0
- package/node_modules/readable-stream/lib/_stream_readable.js +1019 -0
- package/node_modules/readable-stream/lib/_stream_transform.js +214 -0
- package/node_modules/readable-stream/lib/_stream_writable.js +685 -0
- package/node_modules/readable-stream/lib/internal/streams/BufferList.js +78 -0
- package/node_modules/readable-stream/lib/internal/streams/destroy.js +84 -0
- package/node_modules/readable-stream/lib/internal/streams/stream-browser.js +1 -0
- package/node_modules/readable-stream/lib/internal/streams/stream.js +1 -0
- package/node_modules/readable-stream/package.json +52 -0
- package/node_modules/readable-stream/passthrough.js +1 -0
- package/node_modules/readable-stream/readable-browser.js +7 -0
- package/node_modules/readable-stream/readable.js +19 -0
- package/node_modules/readable-stream/transform.js +1 -0
- package/node_modules/readable-stream/writable-browser.js +1 -0
- package/node_modules/readable-stream/writable.js +8 -0
- package/node_modules/safe-buffer/LICENSE +21 -0
- package/node_modules/safe-buffer/README.md +584 -0
- package/node_modules/safe-buffer/index.d.ts +187 -0
- package/node_modules/safe-buffer/index.js +62 -0
- package/node_modules/safe-buffer/package.json +37 -0
- package/node_modules/setimmediate/LICENSE.txt +20 -0
- package/node_modules/setimmediate/package.json +30 -0
- package/node_modules/setimmediate/setImmediate.js +186 -0
- package/node_modules/string_decoder/.travis.yml +50 -0
- package/node_modules/string_decoder/LICENSE +48 -0
- package/node_modules/string_decoder/README.md +47 -0
- package/node_modules/string_decoder/lib/string_decoder.js +296 -0
- package/node_modules/string_decoder/package.json +31 -0
- package/node_modules/util-deprecate/History.md +16 -0
- package/node_modules/util-deprecate/LICENSE +24 -0
- package/node_modules/util-deprecate/README.md +53 -0
- package/node_modules/util-deprecate/browser.js +67 -0
- package/node_modules/util-deprecate/node.js +6 -0
- package/node_modules/util-deprecate/package.json +27 -0
- package/package.json +1 -1
- package/skills/client-email/SKILL.md +8 -6
- package/skills/employment-contract/SKILL.md +23 -6
- package/skills/non-compete-contract-explainer/content/alabama.md +251 -0
- package/skills/non-compete-contract-explainer/content/alaska.md +160 -0
- package/skills/non-compete-contract-explainer/content/american-samoa.md +187 -0
- package/skills/non-compete-contract-explainer/content/arizona.md +293 -0
- package/skills/non-compete-contract-explainer/content/arkansas.md +235 -0
- package/skills/non-compete-contract-explainer/content/california.md +270 -0
- package/skills/non-compete-contract-explainer/content/cnmi.md +168 -0
- package/skills/non-compete-contract-explainer/content/colorado.md +277 -0
- package/skills/non-compete-contract-explainer/content/connecticut.md +220 -0
- package/skills/non-compete-contract-explainer/content/delaware.md +222 -0
- package/skills/non-compete-contract-explainer/content/district-of-columbia.md +263 -0
- package/skills/non-compete-contract-explainer/content/florida.md +267 -0
- package/skills/non-compete-contract-explainer/content/georgia.md +323 -0
- package/skills/non-compete-contract-explainer/content/guam.md +180 -0
- package/skills/non-compete-contract-explainer/content/hawaii.md +236 -0
- package/skills/non-compete-contract-explainer/content/idaho.md +258 -0
- package/skills/non-compete-contract-explainer/content/illinois.md +266 -0
- package/skills/non-compete-contract-explainer/content/india.md +269 -0
- package/skills/non-compete-contract-explainer/content/indiana.md +253 -0
- package/skills/non-compete-contract-explainer/content/iowa.md +232 -0
- package/skills/non-compete-contract-explainer/content/kansas.md +227 -0
- package/skills/non-compete-contract-explainer/content/kentucky.md +201 -0
- package/skills/non-compete-contract-explainer/content/louisiana.md +272 -0
- package/skills/non-compete-contract-explainer/content/maine.md +178 -0
- package/skills/non-compete-contract-explainer/content/maryland.md +244 -0
- package/skills/non-compete-contract-explainer/content/massachusetts.md +272 -0
- package/skills/non-compete-contract-explainer/content/michigan.md +222 -0
- package/skills/non-compete-contract-explainer/content/minnesota.md +171 -0
- package/skills/non-compete-contract-explainer/content/mississippi.md +237 -0
- package/skills/non-compete-contract-explainer/content/missouri.md +219 -0
- package/skills/non-compete-contract-explainer/content/montana.md +202 -0
- package/skills/non-compete-contract-explainer/content/nebraska.md +206 -0
- package/skills/non-compete-contract-explainer/content/nevada.md +278 -0
- package/skills/non-compete-contract-explainer/content/new-hampshire.md +233 -0
- package/skills/non-compete-contract-explainer/content/new-jersey.md +277 -0
- package/skills/non-compete-contract-explainer/content/new-mexico.md +244 -0
- package/skills/non-compete-contract-explainer/content/new-york.md +226 -0
- package/skills/non-compete-contract-explainer/content/north-carolina.md +346 -0
- package/skills/non-compete-contract-explainer/content/north-dakota.md +187 -0
- package/skills/non-compete-contract-explainer/content/ohio.md +207 -0
- package/skills/non-compete-contract-explainer/content/oklahoma.md +196 -0
- package/skills/non-compete-contract-explainer/content/oregon.md +359 -0
- package/skills/non-compete-contract-explainer/content/pennsylvania.md +254 -0
- package/skills/non-compete-contract-explainer/content/philippines.md +211 -0
- package/skills/non-compete-contract-explainer/content/puerto-rico.md +163 -0
- package/skills/non-compete-contract-explainer/content/rhode-island.md +171 -0
- package/skills/non-compete-contract-explainer/content/singapore.md +229 -0
- package/skills/non-compete-contract-explainer/content/south-carolina.md +226 -0
- package/skills/non-compete-contract-explainer/content/south-dakota.md +222 -0
- package/skills/non-compete-contract-explainer/content/tennessee.md +251 -0
- package/skills/non-compete-contract-explainer/content/texas.md +297 -0
- package/skills/non-compete-contract-explainer/content/us-virgin-islands.md +193 -0
- package/skills/non-compete-contract-explainer/content/utah.md +250 -0
- package/skills/non-compete-contract-explainer/content/vermont.md +193 -0
- package/skills/non-compete-contract-explainer/content/virginia.md +213 -0
- package/skills/non-compete-contract-explainer/content/washington.md +296 -0
- package/skills/non-compete-contract-explainer/content/west-virginia.md +187 -0
- package/skills/non-compete-contract-explainer/content/wisconsin.md +293 -0
- package/skills/non-compete-contract-explainer/content/wyoming.md +55 -45
- package/skills/non-compete-contract-explainer/manifest.json +523 -1
|
@@ -0,0 +1,929 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var conventions = require('./conventions');
|
|
4
|
+
var g = require('./grammar');
|
|
5
|
+
var errors = require('./errors');
|
|
6
|
+
|
|
7
|
+
var isHTMLEscapableRawTextElement = conventions.isHTMLEscapableRawTextElement;
|
|
8
|
+
var isHTMLMimeType = conventions.isHTMLMimeType;
|
|
9
|
+
var isHTMLRawTextElement = conventions.isHTMLRawTextElement;
|
|
10
|
+
var hasOwn = conventions.hasOwn;
|
|
11
|
+
var NAMESPACE = conventions.NAMESPACE;
|
|
12
|
+
var ParseError = errors.ParseError;
|
|
13
|
+
var DOMException = errors.DOMException;
|
|
14
|
+
|
|
15
|
+
//var handlers = 'resolveEntity,getExternalSubset,characters,endDocument,endElement,endPrefixMapping,ignorableWhitespace,processingInstruction,setDocumentLocator,skippedEntity,startDocument,startElement,startPrefixMapping,notationDecl,unparsedEntityDecl,error,fatalError,warning,attributeDecl,elementDecl,externalEntityDecl,internalEntityDecl,comment,endCDATA,endDTD,endEntity,startCDATA,startDTD,startEntity'.split(',')
|
|
16
|
+
|
|
17
|
+
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
|
18
|
+
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
|
19
|
+
var S_TAG = 0; //tag name offerring
|
|
20
|
+
var S_ATTR = 1; //attr name offerring
|
|
21
|
+
var S_ATTR_SPACE = 2; //attr name end and space offer
|
|
22
|
+
var S_EQ = 3; //=space?
|
|
23
|
+
var S_ATTR_NOQUOT_VALUE = 4; //attr value(no quot value only)
|
|
24
|
+
var S_ATTR_END = 5; //attr value end and no space(quot end)
|
|
25
|
+
var S_TAG_SPACE = 6; //(attr value end || tag end ) && (space offer)
|
|
26
|
+
var S_TAG_CLOSE = 7; //closed el<el />
|
|
27
|
+
|
|
28
|
+
function XMLReader() {}
|
|
29
|
+
|
|
30
|
+
XMLReader.prototype = {
|
|
31
|
+
parse: function (source, defaultNSMap, entityMap) {
|
|
32
|
+
var domBuilder = this.domBuilder;
|
|
33
|
+
domBuilder.startDocument();
|
|
34
|
+
_copy(defaultNSMap, (defaultNSMap = Object.create(null)));
|
|
35
|
+
parse(source, defaultNSMap, entityMap, domBuilder, this.errorHandler);
|
|
36
|
+
domBuilder.endDocument();
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Detecting everything that might be a reference,
|
|
42
|
+
* including those without ending `;`, since those are allowed in HTML.
|
|
43
|
+
* The entityReplacer takes care of verifying and transforming each occurrence,
|
|
44
|
+
* and reports to the errorHandler on those that are not OK,
|
|
45
|
+
* depending on the context.
|
|
46
|
+
*/
|
|
47
|
+
var ENTITY_REG = /&#?\w+;?/g;
|
|
48
|
+
|
|
49
|
+
function parse(source, defaultNSMapCopy, entityMap, domBuilder, errorHandler) {
|
|
50
|
+
var isHTML = isHTMLMimeType(domBuilder.mimeType);
|
|
51
|
+
if (source.indexOf(g.UNICODE_REPLACEMENT_CHARACTER) >= 0) {
|
|
52
|
+
errorHandler.warning('Unicode replacement character detected, source encoding issues?');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function fixedFromCharCode(code) {
|
|
56
|
+
// String.prototype.fromCharCode does not supports
|
|
57
|
+
// > 2 bytes unicode chars directly
|
|
58
|
+
if (code > 0xffff) {
|
|
59
|
+
code -= 0x10000;
|
|
60
|
+
var surrogate1 = 0xd800 + (code >> 10),
|
|
61
|
+
surrogate2 = 0xdc00 + (code & 0x3ff);
|
|
62
|
+
|
|
63
|
+
return String.fromCharCode(surrogate1, surrogate2);
|
|
64
|
+
} else {
|
|
65
|
+
return String.fromCharCode(code);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function entityReplacer(a) {
|
|
70
|
+
var complete = a[a.length - 1] === ';' ? a : a + ';';
|
|
71
|
+
if (!isHTML && complete !== a) {
|
|
72
|
+
errorHandler.error('EntityRef: expecting ;');
|
|
73
|
+
return a;
|
|
74
|
+
}
|
|
75
|
+
var match = g.Reference.exec(complete);
|
|
76
|
+
if (!match || match[0].length !== complete.length) {
|
|
77
|
+
errorHandler.error('entity not matching Reference production: ' + a);
|
|
78
|
+
return a;
|
|
79
|
+
}
|
|
80
|
+
var k = complete.slice(1, -1);
|
|
81
|
+
if (hasOwn(entityMap, k)) {
|
|
82
|
+
return entityMap[k];
|
|
83
|
+
} else if (k.charAt(0) === '#') {
|
|
84
|
+
return fixedFromCharCode(parseInt(k.substring(1).replace('x', '0x')));
|
|
85
|
+
} else {
|
|
86
|
+
errorHandler.error('entity not found:' + a);
|
|
87
|
+
return a;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function appendText(end) {
|
|
92
|
+
//has some bugs
|
|
93
|
+
if (end > start) {
|
|
94
|
+
var xt = source.substring(start, end).replace(ENTITY_REG, entityReplacer);
|
|
95
|
+
locator && position(start);
|
|
96
|
+
domBuilder.characters(xt, 0, end - start);
|
|
97
|
+
start = end;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
var lineStart = 0;
|
|
102
|
+
var lineEnd = 0;
|
|
103
|
+
var linePattern = /\r\n?|\n|$/g;
|
|
104
|
+
var locator = domBuilder.locator;
|
|
105
|
+
|
|
106
|
+
function position(p, m) {
|
|
107
|
+
while (p >= lineEnd && (m = linePattern.exec(source))) {
|
|
108
|
+
lineStart = lineEnd;
|
|
109
|
+
lineEnd = m.index + m[0].length;
|
|
110
|
+
locator.lineNumber++;
|
|
111
|
+
}
|
|
112
|
+
locator.columnNumber = p - lineStart + 1;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
var parseStack = [{ currentNSMap: defaultNSMapCopy }];
|
|
116
|
+
var unclosedTags = [];
|
|
117
|
+
var start = 0;
|
|
118
|
+
while (true) {
|
|
119
|
+
try {
|
|
120
|
+
var tagStart = source.indexOf('<', start);
|
|
121
|
+
if (tagStart < 0) {
|
|
122
|
+
if (!isHTML && unclosedTags.length > 0) {
|
|
123
|
+
return errorHandler.fatalError('unclosed xml tag(s): ' + unclosedTags.join(', '));
|
|
124
|
+
}
|
|
125
|
+
if (!source.substring(start).match(/^\s*$/)) {
|
|
126
|
+
var doc = domBuilder.doc;
|
|
127
|
+
var text = doc.createTextNode(source.substring(start));
|
|
128
|
+
if (doc.documentElement) {
|
|
129
|
+
return errorHandler.error('Extra content at the end of the document');
|
|
130
|
+
}
|
|
131
|
+
doc.appendChild(text);
|
|
132
|
+
domBuilder.currentElement = text;
|
|
133
|
+
}
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (tagStart > start) {
|
|
137
|
+
var fromSource = source.substring(start, tagStart);
|
|
138
|
+
if (!isHTML && unclosedTags.length === 0) {
|
|
139
|
+
fromSource = fromSource.replace(new RegExp(g.S_OPT.source, 'g'), '');
|
|
140
|
+
fromSource && errorHandler.error("Unexpected content outside root element: '" + fromSource + "'");
|
|
141
|
+
}
|
|
142
|
+
appendText(tagStart);
|
|
143
|
+
}
|
|
144
|
+
switch (source.charAt(tagStart + 1)) {
|
|
145
|
+
case '/':
|
|
146
|
+
var end = source.indexOf('>', tagStart + 2);
|
|
147
|
+
var tagNameRaw = source.substring(tagStart + 2, end > 0 ? end : undefined);
|
|
148
|
+
if (!tagNameRaw) {
|
|
149
|
+
return errorHandler.fatalError('end tag name missing');
|
|
150
|
+
}
|
|
151
|
+
var tagNameMatch = end > 0 && g.reg('^', g.QName_group, g.S_OPT, '$').exec(tagNameRaw);
|
|
152
|
+
if (!tagNameMatch) {
|
|
153
|
+
return errorHandler.fatalError('end tag name contains invalid characters: "' + tagNameRaw + '"');
|
|
154
|
+
}
|
|
155
|
+
if (!domBuilder.currentElement && !domBuilder.doc.documentElement) {
|
|
156
|
+
// not enough information to provide a helpful error message,
|
|
157
|
+
// but parsing will throw since there is no root element
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
var currentTagName =
|
|
161
|
+
unclosedTags[unclosedTags.length - 1] ||
|
|
162
|
+
domBuilder.currentElement.tagName ||
|
|
163
|
+
domBuilder.doc.documentElement.tagName ||
|
|
164
|
+
'';
|
|
165
|
+
if (currentTagName !== tagNameMatch[1]) {
|
|
166
|
+
var tagNameLower = tagNameMatch[1].toLowerCase();
|
|
167
|
+
if (!isHTML || currentTagName.toLowerCase() !== tagNameLower) {
|
|
168
|
+
return errorHandler.fatalError('Opening and ending tag mismatch: "' + currentTagName + '" != "' + tagNameRaw + '"');
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
var config = parseStack.pop();
|
|
172
|
+
unclosedTags.pop();
|
|
173
|
+
var localNSMap = config.localNSMap;
|
|
174
|
+
domBuilder.endElement(config.uri, config.localName, currentTagName);
|
|
175
|
+
if (localNSMap) {
|
|
176
|
+
for (var prefix in localNSMap) {
|
|
177
|
+
if (hasOwn(localNSMap, prefix)) {
|
|
178
|
+
domBuilder.endPrefixMapping(prefix);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
end++;
|
|
184
|
+
break;
|
|
185
|
+
// end element
|
|
186
|
+
case '?': // <?...?>
|
|
187
|
+
locator && position(tagStart);
|
|
188
|
+
end = parseProcessingInstruction(source, tagStart, domBuilder, errorHandler);
|
|
189
|
+
break;
|
|
190
|
+
case '!': // <!doctype,<![CDATA,<!--
|
|
191
|
+
locator && position(tagStart);
|
|
192
|
+
end = parseDoctypeCommentOrCData(source, tagStart, domBuilder, errorHandler, isHTML);
|
|
193
|
+
break;
|
|
194
|
+
default:
|
|
195
|
+
locator && position(tagStart);
|
|
196
|
+
var el = new ElementAttributes();
|
|
197
|
+
var currentNSMap = parseStack[parseStack.length - 1].currentNSMap;
|
|
198
|
+
//elStartEnd
|
|
199
|
+
var end = parseElementStartPart(source, tagStart, el, currentNSMap, entityReplacer, errorHandler, isHTML);
|
|
200
|
+
var len = el.length;
|
|
201
|
+
|
|
202
|
+
if (!el.closed) {
|
|
203
|
+
if (isHTML && conventions.isHTMLVoidElement(el.tagName)) {
|
|
204
|
+
el.closed = true;
|
|
205
|
+
} else {
|
|
206
|
+
unclosedTags.push(el.tagName);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (locator && len) {
|
|
210
|
+
var locator2 = copyLocator(locator, {});
|
|
211
|
+
//try{//attribute position fixed
|
|
212
|
+
for (var i = 0; i < len; i++) {
|
|
213
|
+
var a = el[i];
|
|
214
|
+
position(a.offset);
|
|
215
|
+
a.locator = copyLocator(locator, {});
|
|
216
|
+
}
|
|
217
|
+
domBuilder.locator = locator2;
|
|
218
|
+
if (appendElement(el, domBuilder, currentNSMap)) {
|
|
219
|
+
parseStack.push(el);
|
|
220
|
+
}
|
|
221
|
+
domBuilder.locator = locator;
|
|
222
|
+
} else {
|
|
223
|
+
if (appendElement(el, domBuilder, currentNSMap)) {
|
|
224
|
+
parseStack.push(el);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if (isHTML && !el.closed) {
|
|
229
|
+
end = parseHtmlSpecialContent(source, end, el.tagName, entityReplacer, domBuilder);
|
|
230
|
+
} else {
|
|
231
|
+
end++;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
} catch (e) {
|
|
235
|
+
if (e instanceof ParseError) {
|
|
236
|
+
throw e;
|
|
237
|
+
} else if (e instanceof DOMException) {
|
|
238
|
+
throw new ParseError(e.name + ': ' + e.message, domBuilder.locator, e);
|
|
239
|
+
}
|
|
240
|
+
errorHandler.error('element parse error: ' + e);
|
|
241
|
+
end = -1;
|
|
242
|
+
}
|
|
243
|
+
if (end > start) {
|
|
244
|
+
start = end;
|
|
245
|
+
} else {
|
|
246
|
+
//Possible sax fallback here, risk of positional error
|
|
247
|
+
appendText(Math.max(tagStart, start) + 1);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function copyLocator(f, t) {
|
|
253
|
+
t.lineNumber = f.lineNumber;
|
|
254
|
+
t.columnNumber = f.columnNumber;
|
|
255
|
+
return t;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @returns
|
|
260
|
+
* end of the elementStartPart(end of elementEndPart for selfClosed el)
|
|
261
|
+
* @see {@link #appendElement}
|
|
262
|
+
*/
|
|
263
|
+
function parseElementStartPart(source, start, el, currentNSMap, entityReplacer, errorHandler, isHTML) {
|
|
264
|
+
/**
|
|
265
|
+
* @param {string} qname
|
|
266
|
+
* @param {string} value
|
|
267
|
+
* @param {number} startIndex
|
|
268
|
+
*/
|
|
269
|
+
function addAttribute(qname, value, startIndex) {
|
|
270
|
+
if (hasOwn(el.attributeNames, qname)) {
|
|
271
|
+
return errorHandler.fatalError('Attribute ' + qname + ' redefined');
|
|
272
|
+
}
|
|
273
|
+
if (!isHTML && value.indexOf('<') >= 0) {
|
|
274
|
+
return errorHandler.fatalError("Unescaped '<' not allowed in attributes values");
|
|
275
|
+
}
|
|
276
|
+
el.addValue(
|
|
277
|
+
qname,
|
|
278
|
+
// @see https://www.w3.org/TR/xml/#AVNormalize
|
|
279
|
+
// since the xmldom sax parser does not "interpret" DTD the following is not implemented:
|
|
280
|
+
// - recursive replacement of (DTD) entity references
|
|
281
|
+
// - trimming and collapsing multiple spaces into a single one for attributes that are not of type CDATA
|
|
282
|
+
value.replace(/[\t\n\r]/g, ' ').replace(ENTITY_REG, entityReplacer),
|
|
283
|
+
startIndex
|
|
284
|
+
);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
var attrName;
|
|
288
|
+
var value;
|
|
289
|
+
var p = ++start;
|
|
290
|
+
var s = S_TAG; //status
|
|
291
|
+
while (true) {
|
|
292
|
+
var c = source.charAt(p);
|
|
293
|
+
switch (c) {
|
|
294
|
+
case '=':
|
|
295
|
+
if (s === S_ATTR) {
|
|
296
|
+
//attrName
|
|
297
|
+
attrName = source.slice(start, p);
|
|
298
|
+
s = S_EQ;
|
|
299
|
+
} else if (s === S_ATTR_SPACE) {
|
|
300
|
+
s = S_EQ;
|
|
301
|
+
} else {
|
|
302
|
+
//fatalError: equal must after attrName or space after attrName
|
|
303
|
+
throw new Error('attribute equal must after attrName'); // No known test case
|
|
304
|
+
}
|
|
305
|
+
break;
|
|
306
|
+
case "'":
|
|
307
|
+
case '"':
|
|
308
|
+
if (
|
|
309
|
+
s === S_EQ ||
|
|
310
|
+
s === S_ATTR //|| s == S_ATTR_SPACE
|
|
311
|
+
) {
|
|
312
|
+
//equal
|
|
313
|
+
if (s === S_ATTR) {
|
|
314
|
+
errorHandler.warning('attribute value must after "="');
|
|
315
|
+
attrName = source.slice(start, p);
|
|
316
|
+
}
|
|
317
|
+
start = p + 1;
|
|
318
|
+
p = source.indexOf(c, start);
|
|
319
|
+
if (p > 0) {
|
|
320
|
+
value = source.slice(start, p);
|
|
321
|
+
addAttribute(attrName, value, start - 1);
|
|
322
|
+
s = S_ATTR_END;
|
|
323
|
+
} else {
|
|
324
|
+
//fatalError: no end quot match
|
|
325
|
+
throw new Error("attribute value no end '" + c + "' match");
|
|
326
|
+
}
|
|
327
|
+
} else if (s == S_ATTR_NOQUOT_VALUE) {
|
|
328
|
+
value = source.slice(start, p);
|
|
329
|
+
addAttribute(attrName, value, start);
|
|
330
|
+
errorHandler.warning('attribute "' + attrName + '" missed start quot(' + c + ')!!');
|
|
331
|
+
start = p + 1;
|
|
332
|
+
s = S_ATTR_END;
|
|
333
|
+
} else {
|
|
334
|
+
//fatalError: no equal before
|
|
335
|
+
throw new Error('attribute value must after "="'); // No known test case
|
|
336
|
+
}
|
|
337
|
+
break;
|
|
338
|
+
case '/':
|
|
339
|
+
switch (s) {
|
|
340
|
+
case S_TAG:
|
|
341
|
+
el.setTagName(source.slice(start, p));
|
|
342
|
+
case S_ATTR_END:
|
|
343
|
+
case S_TAG_SPACE:
|
|
344
|
+
case S_TAG_CLOSE:
|
|
345
|
+
s = S_TAG_CLOSE;
|
|
346
|
+
el.closed = true;
|
|
347
|
+
case S_ATTR_NOQUOT_VALUE:
|
|
348
|
+
case S_ATTR:
|
|
349
|
+
break;
|
|
350
|
+
case S_ATTR_SPACE:
|
|
351
|
+
el.closed = true;
|
|
352
|
+
break;
|
|
353
|
+
//case S_EQ:
|
|
354
|
+
default:
|
|
355
|
+
throw new Error("attribute invalid close char('/')"); // No known test case
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
case '': //end document
|
|
359
|
+
errorHandler.error('unexpected end of input');
|
|
360
|
+
if (s == S_TAG) {
|
|
361
|
+
el.setTagName(source.slice(start, p));
|
|
362
|
+
}
|
|
363
|
+
return p;
|
|
364
|
+
case '>':
|
|
365
|
+
switch (s) {
|
|
366
|
+
case S_TAG:
|
|
367
|
+
el.setTagName(source.slice(start, p));
|
|
368
|
+
case S_ATTR_END:
|
|
369
|
+
case S_TAG_SPACE:
|
|
370
|
+
case S_TAG_CLOSE:
|
|
371
|
+
break; //normal
|
|
372
|
+
case S_ATTR_NOQUOT_VALUE: //Compatible state
|
|
373
|
+
case S_ATTR:
|
|
374
|
+
value = source.slice(start, p);
|
|
375
|
+
if (value.slice(-1) === '/') {
|
|
376
|
+
el.closed = true;
|
|
377
|
+
value = value.slice(0, -1);
|
|
378
|
+
}
|
|
379
|
+
case S_ATTR_SPACE:
|
|
380
|
+
if (s === S_ATTR_SPACE) {
|
|
381
|
+
value = attrName;
|
|
382
|
+
}
|
|
383
|
+
if (s == S_ATTR_NOQUOT_VALUE) {
|
|
384
|
+
errorHandler.warning('attribute "' + value + '" missed quot(")!');
|
|
385
|
+
addAttribute(attrName, value, start);
|
|
386
|
+
} else {
|
|
387
|
+
if (!isHTML) {
|
|
388
|
+
errorHandler.warning('attribute "' + value + '" missed value!! "' + value + '" instead!!');
|
|
389
|
+
}
|
|
390
|
+
addAttribute(value, value, start);
|
|
391
|
+
}
|
|
392
|
+
break;
|
|
393
|
+
case S_EQ:
|
|
394
|
+
if (!isHTML) {
|
|
395
|
+
return errorHandler.fatalError('AttValue: \' or " expected');
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return p;
|
|
399
|
+
/*xml space '\x20' | #x9 | #xD | #xA; */
|
|
400
|
+
case '\u0080':
|
|
401
|
+
c = ' ';
|
|
402
|
+
default:
|
|
403
|
+
if (c <= ' ') {
|
|
404
|
+
//space
|
|
405
|
+
switch (s) {
|
|
406
|
+
case S_TAG:
|
|
407
|
+
el.setTagName(source.slice(start, p)); //tagName
|
|
408
|
+
s = S_TAG_SPACE;
|
|
409
|
+
break;
|
|
410
|
+
case S_ATTR:
|
|
411
|
+
attrName = source.slice(start, p);
|
|
412
|
+
s = S_ATTR_SPACE;
|
|
413
|
+
break;
|
|
414
|
+
case S_ATTR_NOQUOT_VALUE:
|
|
415
|
+
var value = source.slice(start, p);
|
|
416
|
+
errorHandler.warning('attribute "' + value + '" missed quot(")!!');
|
|
417
|
+
addAttribute(attrName, value, start);
|
|
418
|
+
case S_ATTR_END:
|
|
419
|
+
s = S_TAG_SPACE;
|
|
420
|
+
break;
|
|
421
|
+
//case S_TAG_SPACE:
|
|
422
|
+
//case S_EQ:
|
|
423
|
+
//case S_ATTR_SPACE:
|
|
424
|
+
// void();break;
|
|
425
|
+
//case S_TAG_CLOSE:
|
|
426
|
+
//ignore warning
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
//not space
|
|
430
|
+
//S_TAG, S_ATTR, S_EQ, S_ATTR_NOQUOT_VALUE
|
|
431
|
+
//S_ATTR_SPACE, S_ATTR_END, S_TAG_SPACE, S_TAG_CLOSE
|
|
432
|
+
switch (s) {
|
|
433
|
+
//case S_TAG:void();break;
|
|
434
|
+
//case S_ATTR:void();break;
|
|
435
|
+
//case S_ATTR_NOQUOT_VALUE:void();break;
|
|
436
|
+
case S_ATTR_SPACE:
|
|
437
|
+
if (!isHTML) {
|
|
438
|
+
errorHandler.warning('attribute "' + attrName + '" missed value!! "' + attrName + '" instead2!!');
|
|
439
|
+
}
|
|
440
|
+
addAttribute(attrName, attrName, start);
|
|
441
|
+
start = p;
|
|
442
|
+
s = S_ATTR;
|
|
443
|
+
break;
|
|
444
|
+
case S_ATTR_END:
|
|
445
|
+
errorHandler.warning('attribute space is required"' + attrName + '"!!');
|
|
446
|
+
case S_TAG_SPACE:
|
|
447
|
+
s = S_ATTR;
|
|
448
|
+
start = p;
|
|
449
|
+
break;
|
|
450
|
+
case S_EQ:
|
|
451
|
+
s = S_ATTR_NOQUOT_VALUE;
|
|
452
|
+
start = p;
|
|
453
|
+
break;
|
|
454
|
+
case S_TAG_CLOSE:
|
|
455
|
+
throw new Error("elements closed character '/' and '>' must be connected to");
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
} //end outer switch
|
|
459
|
+
p++;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
/**
|
|
464
|
+
* @returns
|
|
465
|
+
* `true` if a new namespace has been defined.
|
|
466
|
+
*/
|
|
467
|
+
function appendElement(el, domBuilder, currentNSMap) {
|
|
468
|
+
var tagName = el.tagName;
|
|
469
|
+
var localNSMap = null;
|
|
470
|
+
var i = el.length;
|
|
471
|
+
while (i--) {
|
|
472
|
+
var a = el[i];
|
|
473
|
+
var qName = a.qName;
|
|
474
|
+
var value = a.value;
|
|
475
|
+
var nsp = qName.indexOf(':');
|
|
476
|
+
if (nsp > 0) {
|
|
477
|
+
var prefix = (a.prefix = qName.slice(0, nsp));
|
|
478
|
+
var localName = qName.slice(nsp + 1);
|
|
479
|
+
var nsPrefix = prefix === 'xmlns' && localName;
|
|
480
|
+
} else {
|
|
481
|
+
localName = qName;
|
|
482
|
+
prefix = null;
|
|
483
|
+
nsPrefix = qName === 'xmlns' && '';
|
|
484
|
+
}
|
|
485
|
+
//can not set prefix,because prefix !== ''
|
|
486
|
+
a.localName = localName;
|
|
487
|
+
//prefix == null for no ns prefix attribute
|
|
488
|
+
if (nsPrefix !== false) {
|
|
489
|
+
//hack!!
|
|
490
|
+
if (localNSMap == null) {
|
|
491
|
+
localNSMap = Object.create(null);
|
|
492
|
+
_copy(currentNSMap, (currentNSMap = Object.create(null)));
|
|
493
|
+
}
|
|
494
|
+
currentNSMap[nsPrefix] = localNSMap[nsPrefix] = value;
|
|
495
|
+
a.uri = NAMESPACE.XMLNS;
|
|
496
|
+
domBuilder.startPrefixMapping(nsPrefix, value);
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
var i = el.length;
|
|
500
|
+
while (i--) {
|
|
501
|
+
a = el[i];
|
|
502
|
+
if (a.prefix) {
|
|
503
|
+
//no prefix attribute has no namespace
|
|
504
|
+
if (a.prefix === 'xml') {
|
|
505
|
+
a.uri = NAMESPACE.XML;
|
|
506
|
+
}
|
|
507
|
+
if (a.prefix !== 'xmlns') {
|
|
508
|
+
a.uri = currentNSMap[a.prefix];
|
|
509
|
+
}
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
var nsp = tagName.indexOf(':');
|
|
513
|
+
if (nsp > 0) {
|
|
514
|
+
prefix = el.prefix = tagName.slice(0, nsp);
|
|
515
|
+
localName = el.localName = tagName.slice(nsp + 1);
|
|
516
|
+
} else {
|
|
517
|
+
prefix = null; //important!!
|
|
518
|
+
localName = el.localName = tagName;
|
|
519
|
+
}
|
|
520
|
+
//no prefix element has default namespace
|
|
521
|
+
var ns = (el.uri = currentNSMap[prefix || '']);
|
|
522
|
+
domBuilder.startElement(ns, localName, tagName, el);
|
|
523
|
+
//endPrefixMapping and startPrefixMapping have not any help for dom builder
|
|
524
|
+
//localNSMap = null
|
|
525
|
+
if (el.closed) {
|
|
526
|
+
domBuilder.endElement(ns, localName, tagName);
|
|
527
|
+
if (localNSMap) {
|
|
528
|
+
for (prefix in localNSMap) {
|
|
529
|
+
if (hasOwn(localNSMap, prefix)) {
|
|
530
|
+
domBuilder.endPrefixMapping(prefix);
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
} else {
|
|
535
|
+
el.currentNSMap = currentNSMap;
|
|
536
|
+
el.localNSMap = localNSMap;
|
|
537
|
+
//parseStack.push(el);
|
|
538
|
+
return true;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
function parseHtmlSpecialContent(source, elStartEnd, tagName, entityReplacer, domBuilder) {
|
|
543
|
+
// https://html.spec.whatwg.org/#raw-text-elements
|
|
544
|
+
// https://html.spec.whatwg.org/#escapable-raw-text-elements
|
|
545
|
+
// https://html.spec.whatwg.org/#cdata-rcdata-restrictions:raw-text-elements
|
|
546
|
+
// TODO: https://html.spec.whatwg.org/#cdata-rcdata-restrictions
|
|
547
|
+
var isEscapableRaw = isHTMLEscapableRawTextElement(tagName);
|
|
548
|
+
if (isEscapableRaw || isHTMLRawTextElement(tagName)) {
|
|
549
|
+
var elEndStart = source.indexOf('</' + tagName + '>', elStartEnd);
|
|
550
|
+
var text = source.substring(elStartEnd + 1, elEndStart);
|
|
551
|
+
|
|
552
|
+
if (isEscapableRaw) {
|
|
553
|
+
text = text.replace(ENTITY_REG, entityReplacer);
|
|
554
|
+
}
|
|
555
|
+
domBuilder.characters(text, 0, text.length);
|
|
556
|
+
return elEndStart;
|
|
557
|
+
}
|
|
558
|
+
return elStartEnd + 1;
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
function _copy(source, target) {
|
|
562
|
+
for (var n in source) {
|
|
563
|
+
if (hasOwn(source, n)) {
|
|
564
|
+
target[n] = source[n];
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
|
|
569
|
+
/**
|
|
570
|
+
* @typedef ParseUtils
|
|
571
|
+
* @property {function(relativeIndex: number?): string | undefined} char
|
|
572
|
+
* Provides look ahead access to a singe character relative to the current index.
|
|
573
|
+
* @property {function(): number} getIndex
|
|
574
|
+
* Provides read-only access to the current index.
|
|
575
|
+
* @property {function(reg: RegExp): string | null} getMatch
|
|
576
|
+
* Applies the provided regular expression enforcing that it starts at the current index and
|
|
577
|
+
* returns the complete matching string,
|
|
578
|
+
* and moves the current index by the length of the matching string.
|
|
579
|
+
* @property {function(): string} getSource
|
|
580
|
+
* Provides read-only access to the complete source.
|
|
581
|
+
* @property {function(places: number?): void} skip
|
|
582
|
+
* moves the current index by places (defaults to 1)
|
|
583
|
+
* @property {function(): number} skipBlanks
|
|
584
|
+
* Moves the current index by the amount of white space that directly follows the current index
|
|
585
|
+
* and returns the amount of whitespace chars skipped (0..n),
|
|
586
|
+
* or -1 if the end of the source was reached.
|
|
587
|
+
* @property {function(): string} substringFromIndex
|
|
588
|
+
* creates a substring from the current index to the end of `source`
|
|
589
|
+
* @property {function(compareWith: string): boolean} substringStartsWith
|
|
590
|
+
* Checks if `source` contains `compareWith`, starting from the current index.
|
|
591
|
+
* @property {function(compareWith: string): boolean} substringStartsWithCaseInsensitive
|
|
592
|
+
* Checks if `source` contains `compareWith`, starting from the current index,
|
|
593
|
+
* comparing the upper case of both sides.
|
|
594
|
+
* @see {@link parseUtils}
|
|
595
|
+
*/
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* A temporary scope for parsing and look ahead operations in `source`,
|
|
599
|
+
* starting from index `start`.
|
|
600
|
+
*
|
|
601
|
+
* Some operations move the current index by a number of positions,
|
|
602
|
+
* after which `getIndex` returns the new index.
|
|
603
|
+
*
|
|
604
|
+
* @param {string} source
|
|
605
|
+
* @param {number} start
|
|
606
|
+
* @returns {ParseUtils}
|
|
607
|
+
*/
|
|
608
|
+
function parseUtils(source, start) {
|
|
609
|
+
var index = start;
|
|
610
|
+
|
|
611
|
+
function char(n) {
|
|
612
|
+
n = n || 0;
|
|
613
|
+
return source.charAt(index + n);
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
function skip(n) {
|
|
617
|
+
n = n || 1;
|
|
618
|
+
index += n;
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
function skipBlanks() {
|
|
622
|
+
var blanks = 0;
|
|
623
|
+
while (index < source.length) {
|
|
624
|
+
var c = char();
|
|
625
|
+
if (c !== ' ' && c !== '\n' && c !== '\t' && c !== '\r') {
|
|
626
|
+
return blanks;
|
|
627
|
+
}
|
|
628
|
+
blanks++;
|
|
629
|
+
skip();
|
|
630
|
+
}
|
|
631
|
+
return -1;
|
|
632
|
+
}
|
|
633
|
+
function substringFromIndex() {
|
|
634
|
+
return source.substring(index);
|
|
635
|
+
}
|
|
636
|
+
function substringStartsWith(text) {
|
|
637
|
+
return source.substring(index, index + text.length) === text;
|
|
638
|
+
}
|
|
639
|
+
function substringStartsWithCaseInsensitive(text) {
|
|
640
|
+
return source.substring(index, index + text.length).toUpperCase() === text.toUpperCase();
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
function getMatch(args) {
|
|
644
|
+
var expr = g.reg('^', args);
|
|
645
|
+
var match = expr.exec(substringFromIndex());
|
|
646
|
+
if (match) {
|
|
647
|
+
skip(match[0].length);
|
|
648
|
+
return match[0];
|
|
649
|
+
}
|
|
650
|
+
return null;
|
|
651
|
+
}
|
|
652
|
+
return {
|
|
653
|
+
char: char,
|
|
654
|
+
getIndex: function () {
|
|
655
|
+
return index;
|
|
656
|
+
},
|
|
657
|
+
getMatch: getMatch,
|
|
658
|
+
getSource: function () {
|
|
659
|
+
return source;
|
|
660
|
+
},
|
|
661
|
+
skip: skip,
|
|
662
|
+
skipBlanks: skipBlanks,
|
|
663
|
+
substringFromIndex: substringFromIndex,
|
|
664
|
+
substringStartsWith: substringStartsWith,
|
|
665
|
+
substringStartsWithCaseInsensitive: substringStartsWithCaseInsensitive,
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
/**
|
|
670
|
+
* @param {ParseUtils} p
|
|
671
|
+
* @param {DOMHandler} errorHandler
|
|
672
|
+
* @returns {string}
|
|
673
|
+
*/
|
|
674
|
+
function parseDoctypeInternalSubset(p, errorHandler) {
|
|
675
|
+
/**
|
|
676
|
+
* @param {ParseUtils} p
|
|
677
|
+
* @param {DOMHandler} errorHandler
|
|
678
|
+
* @returns {string}
|
|
679
|
+
*/
|
|
680
|
+
function parsePI(p, errorHandler) {
|
|
681
|
+
var match = g.PI.exec(p.substringFromIndex());
|
|
682
|
+
if (!match) {
|
|
683
|
+
return errorHandler.fatalError('processing instruction is not well-formed at position ' + p.getIndex());
|
|
684
|
+
}
|
|
685
|
+
if (match[1].toLowerCase() === 'xml') {
|
|
686
|
+
return errorHandler.fatalError(
|
|
687
|
+
'xml declaration is only allowed at the start of the document, but found at position ' + p.getIndex()
|
|
688
|
+
);
|
|
689
|
+
}
|
|
690
|
+
p.skip(match[0].length);
|
|
691
|
+
return match[0];
|
|
692
|
+
}
|
|
693
|
+
// Parse internal subset
|
|
694
|
+
var source = p.getSource();
|
|
695
|
+
if (p.char() === '[') {
|
|
696
|
+
p.skip(1);
|
|
697
|
+
var intSubsetStart = p.getIndex();
|
|
698
|
+
while (p.getIndex() < source.length) {
|
|
699
|
+
p.skipBlanks();
|
|
700
|
+
if (p.char() === ']') {
|
|
701
|
+
var internalSubset = source.substring(intSubsetStart, p.getIndex());
|
|
702
|
+
p.skip(1);
|
|
703
|
+
return internalSubset;
|
|
704
|
+
}
|
|
705
|
+
var current = null;
|
|
706
|
+
// Only in external subset
|
|
707
|
+
// if (char() === '<' && char(1) === '!' && char(2) === '[') {
|
|
708
|
+
// parseConditionalSections(p, errorHandler);
|
|
709
|
+
// } else
|
|
710
|
+
if (p.char() === '<' && p.char(1) === '!') {
|
|
711
|
+
switch (p.char(2)) {
|
|
712
|
+
case 'E': // ELEMENT | ENTITY
|
|
713
|
+
if (p.char(3) === 'L') {
|
|
714
|
+
current = p.getMatch(g.elementdecl);
|
|
715
|
+
} else if (p.char(3) === 'N') {
|
|
716
|
+
current = p.getMatch(g.EntityDecl);
|
|
717
|
+
}
|
|
718
|
+
break;
|
|
719
|
+
case 'A': // ATTRIBUTE
|
|
720
|
+
current = p.getMatch(g.AttlistDecl);
|
|
721
|
+
break;
|
|
722
|
+
case 'N': // NOTATION
|
|
723
|
+
current = p.getMatch(g.NotationDecl);
|
|
724
|
+
break;
|
|
725
|
+
case '-': // COMMENT
|
|
726
|
+
current = p.getMatch(g.Comment);
|
|
727
|
+
break;
|
|
728
|
+
}
|
|
729
|
+
} else if (p.char() === '<' && p.char(1) === '?') {
|
|
730
|
+
current = parsePI(p, errorHandler);
|
|
731
|
+
} else if (p.char() === '%') {
|
|
732
|
+
current = p.getMatch(g.PEReference);
|
|
733
|
+
} else {
|
|
734
|
+
return errorHandler.fatalError('Error detected in Markup declaration');
|
|
735
|
+
}
|
|
736
|
+
if (!current) {
|
|
737
|
+
return errorHandler.fatalError('Error in internal subset at position ' + p.getIndex());
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return errorHandler.fatalError('doctype internal subset is not well-formed, missing ]');
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
|
|
744
|
+
/**
|
|
745
|
+
* Called when the parser encounters an element starting with '<!'.
|
|
746
|
+
*
|
|
747
|
+
* @param {string} source
|
|
748
|
+
* The xml.
|
|
749
|
+
* @param {number} start
|
|
750
|
+
* the start index of the '<!'
|
|
751
|
+
* @param {DOMHandler} domBuilder
|
|
752
|
+
* @param {DOMHandler} errorHandler
|
|
753
|
+
* @param {boolean} isHTML
|
|
754
|
+
* @returns {number | never}
|
|
755
|
+
* The end index of the element.
|
|
756
|
+
* @throws {ParseError}
|
|
757
|
+
* In case the element is not well-formed.
|
|
758
|
+
*/
|
|
759
|
+
function parseDoctypeCommentOrCData(source, start, domBuilder, errorHandler, isHTML) {
|
|
760
|
+
var p = parseUtils(source, start);
|
|
761
|
+
|
|
762
|
+
switch (isHTML ? p.char(2).toUpperCase() : p.char(2)) {
|
|
763
|
+
case '-':
|
|
764
|
+
// should be a comment
|
|
765
|
+
var comment = p.getMatch(g.Comment);
|
|
766
|
+
if (comment) {
|
|
767
|
+
domBuilder.comment(comment, g.COMMENT_START.length, comment.length - g.COMMENT_START.length - g.COMMENT_END.length);
|
|
768
|
+
return p.getIndex();
|
|
769
|
+
} else {
|
|
770
|
+
return errorHandler.fatalError('comment is not well-formed at position ' + p.getIndex());
|
|
771
|
+
}
|
|
772
|
+
case '[':
|
|
773
|
+
// should be CDATA
|
|
774
|
+
var cdata = p.getMatch(g.CDSect);
|
|
775
|
+
if (cdata) {
|
|
776
|
+
if (!isHTML && !domBuilder.currentElement) {
|
|
777
|
+
return errorHandler.fatalError('CDATA outside of element');
|
|
778
|
+
}
|
|
779
|
+
domBuilder.startCDATA();
|
|
780
|
+
domBuilder.characters(cdata, g.CDATA_START.length, cdata.length - g.CDATA_START.length - g.CDATA_END.length);
|
|
781
|
+
domBuilder.endCDATA();
|
|
782
|
+
return p.getIndex();
|
|
783
|
+
} else {
|
|
784
|
+
return errorHandler.fatalError('Invalid CDATA starting at position ' + start);
|
|
785
|
+
}
|
|
786
|
+
case 'D': {
|
|
787
|
+
// should be DOCTYPE
|
|
788
|
+
if (domBuilder.doc && domBuilder.doc.documentElement) {
|
|
789
|
+
return errorHandler.fatalError('Doctype not allowed inside or after documentElement at position ' + p.getIndex());
|
|
790
|
+
}
|
|
791
|
+
if (isHTML ? !p.substringStartsWithCaseInsensitive(g.DOCTYPE_DECL_START) : !p.substringStartsWith(g.DOCTYPE_DECL_START)) {
|
|
792
|
+
return errorHandler.fatalError('Expected ' + g.DOCTYPE_DECL_START + ' at position ' + p.getIndex());
|
|
793
|
+
}
|
|
794
|
+
p.skip(g.DOCTYPE_DECL_START.length);
|
|
795
|
+
if (p.skipBlanks() < 1) {
|
|
796
|
+
return errorHandler.fatalError('Expected whitespace after ' + g.DOCTYPE_DECL_START + ' at position ' + p.getIndex());
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
var doctype = {
|
|
800
|
+
name: undefined,
|
|
801
|
+
publicId: undefined,
|
|
802
|
+
systemId: undefined,
|
|
803
|
+
internalSubset: undefined,
|
|
804
|
+
};
|
|
805
|
+
// Parse the DOCTYPE name
|
|
806
|
+
doctype.name = p.getMatch(g.Name);
|
|
807
|
+
if (!doctype.name)
|
|
808
|
+
return errorHandler.fatalError('doctype name missing or contains unexpected characters at position ' + p.getIndex());
|
|
809
|
+
|
|
810
|
+
if (isHTML && doctype.name.toLowerCase() !== 'html') {
|
|
811
|
+
errorHandler.warning('Unexpected DOCTYPE in HTML document at position ' + p.getIndex());
|
|
812
|
+
}
|
|
813
|
+
p.skipBlanks();
|
|
814
|
+
|
|
815
|
+
// Check for ExternalID
|
|
816
|
+
if (p.substringStartsWith(g.PUBLIC) || p.substringStartsWith(g.SYSTEM)) {
|
|
817
|
+
var match = g.ExternalID_match.exec(p.substringFromIndex());
|
|
818
|
+
if (!match) {
|
|
819
|
+
return errorHandler.fatalError('doctype external id is not well-formed at position ' + p.getIndex());
|
|
820
|
+
}
|
|
821
|
+
if (match.groups.SystemLiteralOnly !== undefined) {
|
|
822
|
+
doctype.systemId = match.groups.SystemLiteralOnly;
|
|
823
|
+
} else {
|
|
824
|
+
doctype.systemId = match.groups.SystemLiteral;
|
|
825
|
+
doctype.publicId = match.groups.PubidLiteral;
|
|
826
|
+
}
|
|
827
|
+
p.skip(match[0].length);
|
|
828
|
+
} else if (isHTML && p.substringStartsWithCaseInsensitive(g.SYSTEM)) {
|
|
829
|
+
// https://html.spec.whatwg.org/multipage/syntax.html#doctype-legacy-string
|
|
830
|
+
p.skip(g.SYSTEM.length);
|
|
831
|
+
if (p.skipBlanks() < 1) {
|
|
832
|
+
return errorHandler.fatalError('Expected whitespace after ' + g.SYSTEM + ' at position ' + p.getIndex());
|
|
833
|
+
}
|
|
834
|
+
doctype.systemId = p.getMatch(g.ABOUT_LEGACY_COMPAT_SystemLiteral);
|
|
835
|
+
if (!doctype.systemId) {
|
|
836
|
+
return errorHandler.fatalError(
|
|
837
|
+
'Expected ' + g.ABOUT_LEGACY_COMPAT + ' in single or double quotes after ' + g.SYSTEM + ' at position ' + p.getIndex()
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
if (isHTML && doctype.systemId && !g.ABOUT_LEGACY_COMPAT_SystemLiteral.test(doctype.systemId)) {
|
|
842
|
+
errorHandler.warning('Unexpected doctype.systemId in HTML document at position ' + p.getIndex());
|
|
843
|
+
}
|
|
844
|
+
if (!isHTML) {
|
|
845
|
+
p.skipBlanks();
|
|
846
|
+
doctype.internalSubset = parseDoctypeInternalSubset(p, errorHandler);
|
|
847
|
+
}
|
|
848
|
+
p.skipBlanks();
|
|
849
|
+
if (p.char() !== '>') {
|
|
850
|
+
return errorHandler.fatalError('doctype not terminated with > at position ' + p.getIndex());
|
|
851
|
+
}
|
|
852
|
+
p.skip(1);
|
|
853
|
+
domBuilder.startDTD(doctype.name, doctype.publicId, doctype.systemId, doctype.internalSubset);
|
|
854
|
+
domBuilder.endDTD();
|
|
855
|
+
return p.getIndex();
|
|
856
|
+
}
|
|
857
|
+
default:
|
|
858
|
+
return errorHandler.fatalError('Not well-formed XML starting with "<!" at position ' + start);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
function parseProcessingInstruction(source, start, domBuilder, errorHandler) {
|
|
863
|
+
var match = source.substring(start).match(g.PI);
|
|
864
|
+
if (!match) {
|
|
865
|
+
return errorHandler.fatalError('Invalid processing instruction starting at position ' + start);
|
|
866
|
+
}
|
|
867
|
+
if (match[1].toLowerCase() === 'xml') {
|
|
868
|
+
if (start > 0) {
|
|
869
|
+
return errorHandler.fatalError(
|
|
870
|
+
'processing instruction at position ' + start + ' is an xml declaration which is only at the start of the document'
|
|
871
|
+
);
|
|
872
|
+
}
|
|
873
|
+
if (!g.XMLDecl.test(source.substring(start))) {
|
|
874
|
+
return errorHandler.fatalError('xml declaration is not well-formed');
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
domBuilder.processingInstruction(match[1], match[2]);
|
|
878
|
+
return start + match[0].length;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
function ElementAttributes() {
|
|
882
|
+
this.attributeNames = Object.create(null);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
ElementAttributes.prototype = {
|
|
886
|
+
setTagName: function (tagName) {
|
|
887
|
+
if (!g.QName_exact.test(tagName)) {
|
|
888
|
+
throw new Error('invalid tagName:' + tagName);
|
|
889
|
+
}
|
|
890
|
+
this.tagName = tagName;
|
|
891
|
+
},
|
|
892
|
+
addValue: function (qName, value, offset) {
|
|
893
|
+
if (!g.QName_exact.test(qName)) {
|
|
894
|
+
throw new Error('invalid attribute:' + qName);
|
|
895
|
+
}
|
|
896
|
+
this.attributeNames[qName] = this.length;
|
|
897
|
+
this[this.length++] = { qName: qName, value: value, offset: offset };
|
|
898
|
+
},
|
|
899
|
+
length: 0,
|
|
900
|
+
getLocalName: function (i) {
|
|
901
|
+
return this[i].localName;
|
|
902
|
+
},
|
|
903
|
+
getLocator: function (i) {
|
|
904
|
+
return this[i].locator;
|
|
905
|
+
},
|
|
906
|
+
getQName: function (i) {
|
|
907
|
+
return this[i].qName;
|
|
908
|
+
},
|
|
909
|
+
getURI: function (i) {
|
|
910
|
+
return this[i].uri;
|
|
911
|
+
},
|
|
912
|
+
getValue: function (i) {
|
|
913
|
+
return this[i].value;
|
|
914
|
+
},
|
|
915
|
+
// ,getIndex:function(uri, localName)){
|
|
916
|
+
// if(localName){
|
|
917
|
+
//
|
|
918
|
+
// }else{
|
|
919
|
+
// var qName = uri
|
|
920
|
+
// }
|
|
921
|
+
// },
|
|
922
|
+
// getValue:function(){return this.getValue(this.getIndex.apply(this,arguments))},
|
|
923
|
+
// getType:function(uri,localName){}
|
|
924
|
+
// getType:function(i){},
|
|
925
|
+
};
|
|
926
|
+
|
|
927
|
+
exports.XMLReader = XMLReader;
|
|
928
|
+
exports.parseUtils = parseUtils;
|
|
929
|
+
exports.parseDoctypeCommentOrCData = parseDoctypeCommentOrCData;
|