parse5 3.0.1 → 3.0.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 -19
- package/lib/common/unicode.js +47 -47
- package/lib/index.d.ts +1077 -1077
- package/lib/location_info/parser_mixin.js +57 -47
- package/lib/parser/index.js +7 -3
- package/lib/parser/parser_stream.js +1 -1
- package/lib/sax/dev_null_stream.js +14 -14
- package/package.json +63 -63
|
@@ -8,49 +8,6 @@ var OpenElementStack = require('../parser/open_element_stack'),
|
|
|
8
8
|
//Aliases
|
|
9
9
|
var $ = HTML.TAG_NAMES;
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
function setEndLocation(element, closingToken, treeAdapter) {
|
|
13
|
-
var loc = element.__location;
|
|
14
|
-
|
|
15
|
-
if (!loc)
|
|
16
|
-
return;
|
|
17
|
-
|
|
18
|
-
if (!loc.startTag) {
|
|
19
|
-
loc.startTag = {
|
|
20
|
-
line: loc.line,
|
|
21
|
-
col: loc.col,
|
|
22
|
-
startOffset: loc.startOffset,
|
|
23
|
-
endOffset: loc.endOffset
|
|
24
|
-
};
|
|
25
|
-
if (loc.attrs)
|
|
26
|
-
loc.startTag.attrs = loc.attrs;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (closingToken.location) {
|
|
30
|
-
var ctLocation = closingToken.location,
|
|
31
|
-
tn = treeAdapter.getTagName(element),
|
|
32
|
-
// NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing tag and
|
|
33
|
-
// for cases like <td> <p> </td> - 'p' closes without a closing tag
|
|
34
|
-
isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN &&
|
|
35
|
-
tn === closingToken.tagName;
|
|
36
|
-
|
|
37
|
-
if (isClosingEndTag) {
|
|
38
|
-
loc.endTag = {
|
|
39
|
-
line: ctLocation.line,
|
|
40
|
-
col: ctLocation.col,
|
|
41
|
-
startOffset: ctLocation.startOffset,
|
|
42
|
-
endOffset: ctLocation.endOffset
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (isClosingEndTag)
|
|
47
|
-
loc.endOffset = ctLocation.endOffset;
|
|
48
|
-
else
|
|
49
|
-
loc.endOffset = ctLocation.startOffset;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
|
|
54
11
|
exports.assign = function (parser) {
|
|
55
12
|
//NOTE: obtain Parser proto this way to avoid module circular references
|
|
56
13
|
var parserProto = Object.getPrototypeOf(parser),
|
|
@@ -59,6 +16,50 @@ exports.assign = function (parser) {
|
|
|
59
16
|
lastFosterParentingLocation = null,
|
|
60
17
|
currentToken = null;
|
|
61
18
|
|
|
19
|
+
function setEndLocation(element, closingToken) {
|
|
20
|
+
var loc = element.__location;
|
|
21
|
+
|
|
22
|
+
if (!loc)
|
|
23
|
+
return;
|
|
24
|
+
|
|
25
|
+
if (!loc.startTag) {
|
|
26
|
+
loc.startTag = {
|
|
27
|
+
line: loc.line,
|
|
28
|
+
col: loc.col,
|
|
29
|
+
startOffset: loc.startOffset,
|
|
30
|
+
endOffset: loc.endOffset
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (loc.attrs)
|
|
34
|
+
loc.startTag.attrs = loc.attrs;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (closingToken.location) {
|
|
38
|
+
var ctLocation = closingToken.location,
|
|
39
|
+
tn = treeAdapter.getTagName(element),
|
|
40
|
+
// NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing tag and
|
|
41
|
+
// for cases like <td> <p> </td> - 'p' closes without a closing tag
|
|
42
|
+
isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN &&
|
|
43
|
+
tn === closingToken.tagName;
|
|
44
|
+
|
|
45
|
+
if (isClosingEndTag) {
|
|
46
|
+
loc.endTag = {
|
|
47
|
+
line: ctLocation.line,
|
|
48
|
+
col: ctLocation.col,
|
|
49
|
+
startOffset: ctLocation.startOffset,
|
|
50
|
+
endOffset: ctLocation.endOffset
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (isClosingEndTag)
|
|
55
|
+
loc.endOffset = ctLocation.endOffset;
|
|
56
|
+
else
|
|
57
|
+
loc.endOffset = ctLocation.startOffset;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
else if (closingToken.type === Tokenizer.EOF_TOKEN)
|
|
61
|
+
loc.endOffset = parser.tokenizer.preprocessor.sourcePos;
|
|
62
|
+
}
|
|
62
63
|
|
|
63
64
|
//NOTE: patch _bootstrap method
|
|
64
65
|
parser._bootstrap = function (document, fragmentContext) {
|
|
@@ -70,23 +71,32 @@ exports.assign = function (parser) {
|
|
|
70
71
|
|
|
71
72
|
//OpenElementStack
|
|
72
73
|
parser.openElements.pop = function () {
|
|
73
|
-
setEndLocation(this.current, currentToken
|
|
74
|
+
setEndLocation(this.current, currentToken);
|
|
74
75
|
OpenElementStack.prototype.pop.call(this);
|
|
75
76
|
};
|
|
76
77
|
|
|
77
78
|
parser.openElements.popAllUpToHtmlElement = function () {
|
|
78
79
|
for (var i = this.stackTop; i > 0; i--)
|
|
79
|
-
setEndLocation(this.items[i], currentToken
|
|
80
|
+
setEndLocation(this.items[i], currentToken);
|
|
80
81
|
|
|
81
82
|
OpenElementStack.prototype.popAllUpToHtmlElement.call(this);
|
|
82
83
|
};
|
|
83
84
|
|
|
84
85
|
parser.openElements.remove = function (element) {
|
|
85
|
-
setEndLocation(element, currentToken
|
|
86
|
+
setEndLocation(element, currentToken);
|
|
86
87
|
OpenElementStack.prototype.remove.call(this, element);
|
|
87
88
|
};
|
|
88
89
|
};
|
|
89
90
|
|
|
91
|
+
parser._runParsingLoop = function (scriptHandler) {
|
|
92
|
+
parserProto._runParsingLoop.call(this, scriptHandler);
|
|
93
|
+
|
|
94
|
+
// NOTE: generate location info for elements
|
|
95
|
+
// that remains on open element stack
|
|
96
|
+
for (var i = parser.openElements.stackTop; i >= 0; i--)
|
|
97
|
+
setEndLocation(parser.openElements.items[i], currentToken);
|
|
98
|
+
};
|
|
99
|
+
|
|
90
100
|
|
|
91
101
|
//Token processing
|
|
92
102
|
parser._processTokenInForeignContent = function (token) {
|
|
@@ -107,7 +117,7 @@ exports.assign = function (parser) {
|
|
|
107
117
|
var element = this.openElements.items[i];
|
|
108
118
|
|
|
109
119
|
if (this.treeAdapter.getTagName(element) === token.tagName) {
|
|
110
|
-
setEndLocation(element, token
|
|
120
|
+
setEndLocation(element, token);
|
|
111
121
|
break;
|
|
112
122
|
}
|
|
113
123
|
}
|
package/lib/parser/index.js
CHANGED
|
@@ -319,7 +319,7 @@ Parser.prototype.parse = function (html) {
|
|
|
319
319
|
|
|
320
320
|
this._bootstrap(document, null);
|
|
321
321
|
this.tokenizer.write(html, true);
|
|
322
|
-
this._runParsingLoop(null
|
|
322
|
+
this._runParsingLoop(null);
|
|
323
323
|
|
|
324
324
|
return document;
|
|
325
325
|
};
|
|
@@ -345,7 +345,7 @@ Parser.prototype.parseFragment = function (html, fragmentContext) {
|
|
|
345
345
|
this._resetInsertionMode();
|
|
346
346
|
this._findFormInFragmentContext();
|
|
347
347
|
this.tokenizer.write(html, true);
|
|
348
|
-
this._runParsingLoop(null
|
|
348
|
+
this._runParsingLoop(null);
|
|
349
349
|
|
|
350
350
|
var rootElement = this.treeAdapter.getFirstChild(documentMock),
|
|
351
351
|
fragment = this.treeAdapter.createDocumentFragment();
|
|
@@ -386,7 +386,7 @@ Parser.prototype._bootstrap = function (document, fragmentContext) {
|
|
|
386
386
|
};
|
|
387
387
|
|
|
388
388
|
//Parsing loop
|
|
389
|
-
Parser.prototype._runParsingLoop
|
|
389
|
+
Parser.prototype._runParsingLoop = function (scriptHandler) {
|
|
390
390
|
while (!this.stopped) {
|
|
391
391
|
this._setupTokenizerCDATAMode();
|
|
392
392
|
|
|
@@ -411,6 +411,10 @@ Parser.prototype._runParsingLoop = function (writeCallback, scriptHandler) {
|
|
|
411
411
|
if (scriptHandler && this.pendingScript)
|
|
412
412
|
break;
|
|
413
413
|
}
|
|
414
|
+
};
|
|
415
|
+
|
|
416
|
+
Parser.prototype.runParsingLoopForCurrentChunk = function (writeCallback, scriptHandler) {
|
|
417
|
+
this._runParsingLoop(scriptHandler);
|
|
414
418
|
|
|
415
419
|
if (scriptHandler && this.pendingScript) {
|
|
416
420
|
var script = this.pendingScript;
|
|
@@ -40,7 +40,7 @@ ParserStream.prototype.end = function (chunk, encoding, callback) {
|
|
|
40
40
|
|
|
41
41
|
//Scriptable parser implementation
|
|
42
42
|
ParserStream.prototype._runParsingLoop = function () {
|
|
43
|
-
this.parser.
|
|
43
|
+
this.parser.runParsingLoopForCurrentChunk(this.writeCallback, this._scriptHandler);
|
|
44
44
|
};
|
|
45
45
|
|
|
46
46
|
ParserStream.prototype._resume = function () {
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var WritableStream = require('stream').Writable,
|
|
4
|
-
util = require('util');
|
|
5
|
-
|
|
6
|
-
var DevNullStream = module.exports = function () {
|
|
7
|
-
WritableStream.call(this);
|
|
8
|
-
};
|
|
9
|
-
|
|
10
|
-
util.inherits(DevNullStream, WritableStream);
|
|
11
|
-
|
|
12
|
-
DevNullStream.prototype._write = function (chunk, encoding, cb) {
|
|
13
|
-
cb();
|
|
14
|
-
};
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var WritableStream = require('stream').Writable,
|
|
4
|
+
util = require('util');
|
|
5
|
+
|
|
6
|
+
var DevNullStream = module.exports = function () {
|
|
7
|
+
WritableStream.call(this);
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
util.inherits(DevNullStream, WritableStream);
|
|
11
|
+
|
|
12
|
+
DevNullStream.prototype._write = function (chunk, encoding, cb) {
|
|
13
|
+
cb();
|
|
14
|
+
};
|
package/package.json
CHANGED
|
@@ -1,63 +1,63 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "parse5",
|
|
3
|
-
"description": "HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.",
|
|
4
|
-
"version": "3.0.
|
|
5
|
-
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
|
|
6
|
-
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
|
7
|
-
"homepage": "https://github.com/inikulin/parse5",
|
|
8
|
-
"devDependencies": {
|
|
9
|
-
"del": "^2.0.2",
|
|
10
|
-
"gulp": "^3.9.0",
|
|
11
|
-
"gulp-benchmark": "^1.1.1",
|
|
12
|
-
"gulp-download": "0.0.1",
|
|
13
|
-
"gulp-eslint": "^3.0.1",
|
|
14
|
-
"gulp-install": "^0.6.0",
|
|
15
|
-
"gulp-mocha": "^2.1.3",
|
|
16
|
-
"gulp-rename": "^1.2.2",
|
|
17
|
-
"gulp-typedoc": "^2.0.0",
|
|
18
|
-
"gulp-typescript": "^3.1.2",
|
|
19
|
-
"publish-please": "^2.2.0",
|
|
20
|
-
"through2": "^2.0.0",
|
|
21
|
-
"typedoc": "^0.5.1",
|
|
22
|
-
"typescript": "^2.0.6"
|
|
23
|
-
},
|
|
24
|
-
"keywords": [
|
|
25
|
-
"html",
|
|
26
|
-
"parser",
|
|
27
|
-
"html5",
|
|
28
|
-
"WHATWG",
|
|
29
|
-
"specification",
|
|
30
|
-
"fast",
|
|
31
|
-
"html parser",
|
|
32
|
-
"html5 parser",
|
|
33
|
-
"htmlparser",
|
|
34
|
-
"parse5",
|
|
35
|
-
"serializer",
|
|
36
|
-
"html serializer",
|
|
37
|
-
"htmlserializer",
|
|
38
|
-
"sax",
|
|
39
|
-
"simple api",
|
|
40
|
-
"parse",
|
|
41
|
-
"tokenize",
|
|
42
|
-
"serialize",
|
|
43
|
-
"tokenizer"
|
|
44
|
-
],
|
|
45
|
-
"license": "MIT",
|
|
46
|
-
"main": "./lib/index.js",
|
|
47
|
-
"types": "./lib/index.d.ts",
|
|
48
|
-
"repository": {
|
|
49
|
-
"type": "git",
|
|
50
|
-
"url": "git://github.com/inikulin/parse5.git"
|
|
51
|
-
},
|
|
52
|
-
"scripts": {
|
|
53
|
-
"test": "gulp test",
|
|
54
|
-
"publish-please": "publish-please",
|
|
55
|
-
"prepublish": "publish-please guard"
|
|
56
|
-
},
|
|
57
|
-
"files": [
|
|
58
|
-
"lib"
|
|
59
|
-
],
|
|
60
|
-
"dependencies": {
|
|
61
|
-
"@types/node": "^6.0.46"
|
|
62
|
-
}
|
|
63
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "parse5",
|
|
3
|
+
"description": "HTML parsing/serialization toolset for Node.js. WHATWG HTML Living Standard (aka HTML5)-compliant.",
|
|
4
|
+
"version": "3.0.2",
|
|
5
|
+
"author": "Ivan Nikulin <ifaaan@gmail.com> (https://github.com/inikulin)",
|
|
6
|
+
"contributors": "https://github.com/inikulin/parse5/graphs/contributors",
|
|
7
|
+
"homepage": "https://github.com/inikulin/parse5",
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"del": "^2.0.2",
|
|
10
|
+
"gulp": "^3.9.0",
|
|
11
|
+
"gulp-benchmark": "^1.1.1",
|
|
12
|
+
"gulp-download": "0.0.1",
|
|
13
|
+
"gulp-eslint": "^3.0.1",
|
|
14
|
+
"gulp-install": "^0.6.0",
|
|
15
|
+
"gulp-mocha": "^2.1.3",
|
|
16
|
+
"gulp-rename": "^1.2.2",
|
|
17
|
+
"gulp-typedoc": "^2.0.0",
|
|
18
|
+
"gulp-typescript": "^3.1.2",
|
|
19
|
+
"publish-please": "^2.2.0",
|
|
20
|
+
"through2": "^2.0.0",
|
|
21
|
+
"typedoc": "^0.5.1",
|
|
22
|
+
"typescript": "^2.0.6"
|
|
23
|
+
},
|
|
24
|
+
"keywords": [
|
|
25
|
+
"html",
|
|
26
|
+
"parser",
|
|
27
|
+
"html5",
|
|
28
|
+
"WHATWG",
|
|
29
|
+
"specification",
|
|
30
|
+
"fast",
|
|
31
|
+
"html parser",
|
|
32
|
+
"html5 parser",
|
|
33
|
+
"htmlparser",
|
|
34
|
+
"parse5",
|
|
35
|
+
"serializer",
|
|
36
|
+
"html serializer",
|
|
37
|
+
"htmlserializer",
|
|
38
|
+
"sax",
|
|
39
|
+
"simple api",
|
|
40
|
+
"parse",
|
|
41
|
+
"tokenize",
|
|
42
|
+
"serialize",
|
|
43
|
+
"tokenizer"
|
|
44
|
+
],
|
|
45
|
+
"license": "MIT",
|
|
46
|
+
"main": "./lib/index.js",
|
|
47
|
+
"types": "./lib/index.d.ts",
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git://github.com/inikulin/parse5.git"
|
|
51
|
+
},
|
|
52
|
+
"scripts": {
|
|
53
|
+
"test": "gulp test",
|
|
54
|
+
"publish-please": "publish-please",
|
|
55
|
+
"prepublish": "publish-please guard"
|
|
56
|
+
},
|
|
57
|
+
"files": [
|
|
58
|
+
"lib"
|
|
59
|
+
],
|
|
60
|
+
"dependencies": {
|
|
61
|
+
"@types/node": "^6.0.46"
|
|
62
|
+
}
|
|
63
|
+
}
|