parse5 3.0.3 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +14 -16
  2. package/lib/common/doctype.js +125 -108
  3. package/lib/common/error-codes.js +65 -0
  4. package/lib/common/foreign-content.js +265 -0
  5. package/lib/common/html.js +102 -102
  6. package/lib/common/unicode.js +81 -19
  7. package/lib/extensions/error-reporting/mixin-base.js +43 -0
  8. package/lib/extensions/error-reporting/parser-mixin.js +52 -0
  9. package/lib/extensions/error-reporting/preprocessor-mixin.js +24 -0
  10. package/lib/extensions/error-reporting/tokenizer-mixin.js +17 -0
  11. package/lib/extensions/location-info/open-element-stack-mixin.js +35 -0
  12. package/lib/extensions/location-info/parser-mixin.js +222 -0
  13. package/lib/extensions/location-info/tokenizer-mixin.js +146 -0
  14. package/lib/extensions/position-tracking/preprocessor-mixin.js +64 -0
  15. package/lib/index.js +6 -21
  16. package/lib/parser/formatting-element-list.js +181 -0
  17. package/lib/parser/index.js +1469 -1332
  18. package/lib/parser/open-element-stack.js +482 -0
  19. package/lib/serializer/index.js +136 -122
  20. package/lib/tokenizer/index.js +1856 -1804
  21. package/lib/tokenizer/{named_entity_data.js → named-entity-data.js} +1 -1
  22. package/lib/tokenizer/preprocessor.js +115 -103
  23. package/lib/tree-adapters/default.js +217 -0
  24. package/lib/utils/{merge_options.js → merge-options.js} +2 -2
  25. package/lib/utils/mixin.js +33 -12
  26. package/package.json +32 -61
  27. package/LICENSE +0 -19
  28. package/lib/common/foreign_content.js +0 -260
  29. package/lib/extensions/location_info/open_element_stack_mixin.js +0 -34
  30. package/lib/extensions/location_info/parser_mixin.js +0 -213
  31. package/lib/extensions/location_info/tokenizer_mixin.js +0 -117
  32. package/lib/extensions/position_tracking/preprocessor_mixin.js +0 -72
  33. package/lib/index.d.ts +0 -1077
  34. package/lib/parser/formatting_element_list.js +0 -167
  35. package/lib/parser/open_element_stack.js +0 -395
  36. package/lib/parser/parser_stream.js +0 -76
  37. package/lib/parser/plain_text_conversion_stream.js +0 -20
  38. package/lib/sax/dev_null_stream.js +0 -14
  39. package/lib/sax/index.js +0 -118
  40. package/lib/sax/parser_feedback_simulator.js +0 -153
  41. package/lib/serializer/serializer_stream.js +0 -28
  42. package/lib/tree_adapters/default.js +0 -209
  43. package/lib/tree_adapters/htmlparser2.js +0 -338
@@ -0,0 +1,52 @@
1
+ 'use strict';
2
+
3
+ const ErrorReportingMixinBase = require('./mixin-base');
4
+ const ErrorReportingTokenizerMixin = require('./tokenizer-mixin');
5
+ const LocationInfoTokenizerMixin = require('../location-info/tokenizer-mixin');
6
+ const Mixin = require('../../utils/mixin');
7
+
8
+ class ErrorReportingParserMixin extends ErrorReportingMixinBase {
9
+ constructor(parser, opts) {
10
+ super(parser, opts);
11
+
12
+ this.opts = opts;
13
+ this.ctLoc = null;
14
+ this.locBeforeToken = false;
15
+ }
16
+
17
+ _setErrorLocation(err) {
18
+ if (this.ctLoc) {
19
+ err.startLine = this.ctLoc.startLine;
20
+ err.startCol = this.ctLoc.startCol;
21
+ err.startOffset = this.ctLoc.startOffset;
22
+
23
+ err.endLine = this.locBeforeToken ? this.ctLoc.startLine : this.ctLoc.endLine;
24
+ err.endCol = this.locBeforeToken ? this.ctLoc.startCol : this.ctLoc.endCol;
25
+ err.endOffset = this.locBeforeToken ? this.ctLoc.startOffset : this.ctLoc.endOffset;
26
+ }
27
+ }
28
+
29
+ _getOverriddenMethods(mxn, orig) {
30
+ return {
31
+ _bootstrap(document, fragmentContext) {
32
+ orig._bootstrap.call(this, document, fragmentContext);
33
+
34
+ Mixin.install(this.tokenizer, ErrorReportingTokenizerMixin, mxn.opts);
35
+ Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
36
+ },
37
+
38
+ _processInputToken(token) {
39
+ mxn.ctLoc = token.location;
40
+
41
+ orig._processInputToken.call(this, token);
42
+ },
43
+
44
+ _err(code, options) {
45
+ mxn.locBeforeToken = options && options.beforeToken;
46
+ mxn._reportError(code);
47
+ }
48
+ };
49
+ }
50
+ }
51
+
52
+ module.exports = ErrorReportingParserMixin;
@@ -0,0 +1,24 @@
1
+ 'use strict';
2
+
3
+ const ErrorReportingMixinBase = require('./mixin-base');
4
+ const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin');
5
+ const Mixin = require('../../utils/mixin');
6
+
7
+ class ErrorReportingPreprocessorMixin extends ErrorReportingMixinBase {
8
+ constructor(preprocessor, opts) {
9
+ super(preprocessor, opts);
10
+
11
+ this.posTracker = Mixin.install(preprocessor, PositionTrackingPreprocessorMixin);
12
+ this.lastErrOffset = -1;
13
+ }
14
+
15
+ _reportError(code) {
16
+ //NOTE: avoid reporting error twice on advance/retreat
17
+ if (this.lastErrOffset !== this.posTracker.offset) {
18
+ this.lastErrOffset = this.posTracker.offset;
19
+ super._reportError(code);
20
+ }
21
+ }
22
+ }
23
+
24
+ module.exports = ErrorReportingPreprocessorMixin;
@@ -0,0 +1,17 @@
1
+ 'use strict';
2
+
3
+ const ErrorReportingMixinBase = require('./mixin-base');
4
+ const ErrorReportingPreprocessorMixin = require('./preprocessor-mixin');
5
+ const Mixin = require('../../utils/mixin');
6
+
7
+ class ErrorReportingTokenizerMixin extends ErrorReportingMixinBase {
8
+ constructor(tokenizer, opts) {
9
+ super(tokenizer, opts);
10
+
11
+ const preprocessorMixin = Mixin.install(tokenizer.preprocessor, ErrorReportingPreprocessorMixin, opts);
12
+
13
+ this.posTracker = preprocessorMixin.posTracker;
14
+ }
15
+ }
16
+
17
+ module.exports = ErrorReportingTokenizerMixin;
@@ -0,0 +1,35 @@
1
+ 'use strict';
2
+
3
+ const Mixin = require('../../utils/mixin');
4
+
5
+ class LocationInfoOpenElementStackMixin extends Mixin {
6
+ constructor(stack, opts) {
7
+ super(stack);
8
+
9
+ this.onItemPop = opts.onItemPop;
10
+ }
11
+
12
+ _getOverriddenMethods(mxn, orig) {
13
+ return {
14
+ pop() {
15
+ mxn.onItemPop(this.current);
16
+ orig.pop.call(this);
17
+ },
18
+
19
+ popAllUpToHtmlElement() {
20
+ for (let i = this.stackTop; i > 0; i--) {
21
+ mxn.onItemPop(this.items[i]);
22
+ }
23
+
24
+ orig.popAllUpToHtmlElement.call(this);
25
+ },
26
+
27
+ remove(element) {
28
+ mxn.onItemPop(this.current);
29
+ orig.remove.call(this, element);
30
+ }
31
+ };
32
+ }
33
+ }
34
+
35
+ module.exports = LocationInfoOpenElementStackMixin;
@@ -0,0 +1,222 @@
1
+ 'use strict';
2
+
3
+ const Mixin = require('../../utils/mixin');
4
+ const Tokenizer = require('../../tokenizer');
5
+ const LocationInfoTokenizerMixin = require('./tokenizer-mixin');
6
+ const LocationInfoOpenElementStackMixin = require('./open-element-stack-mixin');
7
+ const HTML = require('../../common/html');
8
+
9
+ //Aliases
10
+ const $ = HTML.TAG_NAMES;
11
+
12
+ class LocationInfoParserMixin extends Mixin {
13
+ constructor(parser) {
14
+ super(parser);
15
+
16
+ this.parser = parser;
17
+ this.treeAdapter = this.parser.treeAdapter;
18
+ this.posTracker = null;
19
+ this.lastStartTagToken = null;
20
+ this.lastFosterParentingLocation = null;
21
+ this.currentToken = null;
22
+ }
23
+
24
+ _setStartLocation(element) {
25
+ let loc = null;
26
+
27
+ if (this.lastStartTagToken) {
28
+ loc = Object.assign({}, this.lastStartTagToken.location);
29
+ loc.startTag = this.lastStartTagToken.location;
30
+ }
31
+
32
+ this.treeAdapter.setNodeSourceCodeLocation(element, loc);
33
+ }
34
+
35
+ _setEndLocation(element, closingToken) {
36
+ const loc = this.treeAdapter.getNodeSourceCodeLocation(element);
37
+
38
+ if (loc) {
39
+ if (closingToken.location) {
40
+ const ctLoc = closingToken.location;
41
+ const tn = this.treeAdapter.getTagName(element);
42
+
43
+ // NOTE: For cases like <p> <p> </p> - First 'p' closes without a closing
44
+ // tag and for cases like <td> <p> </td> - 'p' closes without a closing tag.
45
+ const isClosingEndTag = closingToken.type === Tokenizer.END_TAG_TOKEN && tn === closingToken.tagName;
46
+
47
+ if (isClosingEndTag) {
48
+ loc.endTag = Object.assign({}, ctLoc);
49
+ loc.endLine = ctLoc.endLine;
50
+ loc.endCol = ctLoc.endCol;
51
+ loc.endOffset = ctLoc.endOffset;
52
+ } else {
53
+ loc.endLine = ctLoc.startLine;
54
+ loc.endCol = ctLoc.startCol;
55
+ loc.endOffset = ctLoc.startOffset;
56
+ }
57
+ }
58
+ }
59
+ }
60
+
61
+ _getOverriddenMethods(mxn, orig) {
62
+ return {
63
+ _bootstrap(document, fragmentContext) {
64
+ orig._bootstrap.call(this, document, fragmentContext);
65
+
66
+ mxn.lastStartTagToken = null;
67
+ mxn.lastFosterParentingLocation = null;
68
+ mxn.currentToken = null;
69
+
70
+ const tokenizerMixin = Mixin.install(this.tokenizer, LocationInfoTokenizerMixin);
71
+
72
+ mxn.posTracker = tokenizerMixin.posTracker;
73
+
74
+ Mixin.install(this.openElements, LocationInfoOpenElementStackMixin, {
75
+ onItemPop: function(element) {
76
+ mxn._setEndLocation(element, mxn.currentToken);
77
+ }
78
+ });
79
+ },
80
+
81
+ _runParsingLoop(scriptHandler) {
82
+ orig._runParsingLoop.call(this, scriptHandler);
83
+
84
+ // NOTE: generate location info for elements
85
+ // that remains on open element stack
86
+ for (let i = this.openElements.stackTop; i >= 0; i--) {
87
+ mxn._setEndLocation(this.openElements.items[i], mxn.currentToken);
88
+ }
89
+ },
90
+
91
+ //Token processing
92
+ _processTokenInForeignContent(token) {
93
+ mxn.currentToken = token;
94
+ orig._processTokenInForeignContent.call(this, token);
95
+ },
96
+
97
+ _processToken(token) {
98
+ mxn.currentToken = token;
99
+ orig._processToken.call(this, token);
100
+
101
+ //NOTE: <body> and <html> are never popped from the stack, so we need to updated
102
+ //their end location explicitly.
103
+ const requireExplicitUpdate =
104
+ token.type === Tokenizer.END_TAG_TOKEN &&
105
+ (token.tagName === $.HTML || (token.tagName === $.BODY && this.openElements.hasInScope($.BODY)));
106
+
107
+ if (requireExplicitUpdate) {
108
+ for (let i = this.openElements.stackTop; i >= 0; i--) {
109
+ const element = this.openElements.items[i];
110
+
111
+ if (this.treeAdapter.getTagName(element) === token.tagName) {
112
+ mxn._setEndLocation(element, token);
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ },
118
+
119
+ //Doctype
120
+ _setDocumentType(token) {
121
+ orig._setDocumentType.call(this, token);
122
+
123
+ const documentChildren = this.treeAdapter.getChildNodes(this.document);
124
+ const cnLength = documentChildren.length;
125
+
126
+ for (let i = 0; i < cnLength; i++) {
127
+ const node = documentChildren[i];
128
+
129
+ if (this.treeAdapter.isDocumentTypeNode(node)) {
130
+ this.treeAdapter.setNodeSourceCodeLocation(node, token.location);
131
+ break;
132
+ }
133
+ }
134
+ },
135
+
136
+ //Elements
137
+ _attachElementToTree(element) {
138
+ //NOTE: _attachElementToTree is called from _appendElement, _insertElement and _insertTemplate methods.
139
+ //So we will use token location stored in this methods for the element.
140
+ mxn._setStartLocation(element);
141
+ mxn.lastStartTagToken = null;
142
+ orig._attachElementToTree.call(this, element);
143
+ },
144
+
145
+ _appendElement(token, namespaceURI) {
146
+ mxn.lastStartTagToken = token;
147
+ orig._appendElement.call(this, token, namespaceURI);
148
+ },
149
+
150
+ _insertElement(token, namespaceURI) {
151
+ mxn.lastStartTagToken = token;
152
+ orig._insertElement.call(this, token, namespaceURI);
153
+ },
154
+
155
+ _insertTemplate(token) {
156
+ mxn.lastStartTagToken = token;
157
+ orig._insertTemplate.call(this, token);
158
+
159
+ const tmplContent = this.treeAdapter.getTemplateContent(this.openElements.current);
160
+
161
+ this.treeAdapter.setNodeSourceCodeLocation(tmplContent, null);
162
+ },
163
+
164
+ _insertFakeRootElement() {
165
+ orig._insertFakeRootElement.call(this);
166
+ this.treeAdapter.setNodeSourceCodeLocation(this.openElements.current, null);
167
+ },
168
+
169
+ //Comments
170
+ _appendCommentNode(token, parent) {
171
+ orig._appendCommentNode.call(this, token, parent);
172
+
173
+ const children = this.treeAdapter.getChildNodes(parent);
174
+ const commentNode = children[children.length - 1];
175
+
176
+ this.treeAdapter.setNodeSourceCodeLocation(commentNode, token.location);
177
+ },
178
+
179
+ //Text
180
+ _findFosterParentingLocation() {
181
+ //NOTE: store last foster parenting location, so we will be able to find inserted text
182
+ //in case of foster parenting
183
+ mxn.lastFosterParentingLocation = orig._findFosterParentingLocation.call(this);
184
+
185
+ return mxn.lastFosterParentingLocation;
186
+ },
187
+
188
+ _insertCharacters(token) {
189
+ orig._insertCharacters.call(this, token);
190
+
191
+ const hasFosterParent = this._shouldFosterParentOnInsertion();
192
+
193
+ const parent =
194
+ (hasFosterParent && mxn.lastFosterParentingLocation.parent) ||
195
+ this.openElements.currentTmplContent ||
196
+ this.openElements.current;
197
+
198
+ const siblings = this.treeAdapter.getChildNodes(parent);
199
+
200
+ const textNodeIdx =
201
+ hasFosterParent && mxn.lastFosterParentingLocation.beforeElement
202
+ ? siblings.indexOf(mxn.lastFosterParentingLocation.beforeElement) - 1
203
+ : siblings.length - 1;
204
+
205
+ const textNode = siblings[textNodeIdx];
206
+
207
+ //NOTE: if we have location assigned by another token, then just update end position
208
+ const tnLoc = this.treeAdapter.getNodeSourceCodeLocation(textNode);
209
+
210
+ if (tnLoc) {
211
+ tnLoc.endLine = token.location.endLine;
212
+ tnLoc.endCol = token.location.endCol;
213
+ tnLoc.endOffset = token.location.endOffset;
214
+ } else {
215
+ this.treeAdapter.setNodeSourceCodeLocation(textNode, token.location);
216
+ }
217
+ }
218
+ };
219
+ }
220
+ }
221
+
222
+ module.exports = LocationInfoParserMixin;
@@ -0,0 +1,146 @@
1
+ 'use strict';
2
+
3
+ const Mixin = require('../../utils/mixin');
4
+ const Tokenizer = require('../../tokenizer');
5
+ const PositionTrackingPreprocessorMixin = require('../position-tracking/preprocessor-mixin');
6
+
7
+ class LocationInfoTokenizerMixin extends Mixin {
8
+ constructor(tokenizer) {
9
+ super(tokenizer);
10
+
11
+ this.tokenizer = tokenizer;
12
+ this.posTracker = Mixin.install(tokenizer.preprocessor, PositionTrackingPreprocessorMixin);
13
+ this.currentAttrLocation = null;
14
+ this.ctLoc = null;
15
+ }
16
+
17
+ _getCurrentLocation() {
18
+ return {
19
+ startLine: this.posTracker.line,
20
+ startCol: this.posTracker.col,
21
+ startOffset: this.posTracker.offset,
22
+ endLine: -1,
23
+ endCol: -1,
24
+ endOffset: -1
25
+ };
26
+ }
27
+
28
+ _attachCurrentAttrLocationInfo() {
29
+ this.currentAttrLocation.endLine = this.posTracker.line;
30
+ this.currentAttrLocation.endCol = this.posTracker.col;
31
+ this.currentAttrLocation.endOffset = this.posTracker.offset;
32
+
33
+ const currentToken = this.tokenizer.currentToken;
34
+ const currentAttr = this.tokenizer.currentAttr;
35
+
36
+ if (!currentToken.location.attrs) {
37
+ currentToken.location.attrs = Object.create(null);
38
+ }
39
+
40
+ currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation;
41
+ }
42
+
43
+ _getOverriddenMethods(mxn, orig) {
44
+ const methods = {
45
+ _createStartTagToken() {
46
+ orig._createStartTagToken.call(this);
47
+ this.currentToken.location = mxn.ctLoc;
48
+ },
49
+
50
+ _createEndTagToken() {
51
+ orig._createEndTagToken.call(this);
52
+ this.currentToken.location = mxn.ctLoc;
53
+ },
54
+
55
+ _createCommentToken() {
56
+ orig._createCommentToken.call(this);
57
+ this.currentToken.location = mxn.ctLoc;
58
+ },
59
+
60
+ _createDoctypeToken(initialName) {
61
+ orig._createDoctypeToken.call(this, initialName);
62
+ this.currentToken.location = mxn.ctLoc;
63
+ },
64
+
65
+ _createCharacterToken(type, ch) {
66
+ orig._createCharacterToken.call(this, type, ch);
67
+ this.currentCharacterToken.location = mxn.ctLoc;
68
+ },
69
+
70
+ _createEOFToken() {
71
+ orig._createEOFToken.call(this);
72
+ this.currentToken.location = mxn._getCurrentLocation();
73
+ },
74
+
75
+ _createAttr(attrNameFirstCh) {
76
+ orig._createAttr.call(this, attrNameFirstCh);
77
+ mxn.currentAttrLocation = mxn._getCurrentLocation();
78
+ },
79
+
80
+ _leaveAttrName(toState) {
81
+ orig._leaveAttrName.call(this, toState);
82
+ mxn._attachCurrentAttrLocationInfo();
83
+ },
84
+
85
+ _leaveAttrValue(toState) {
86
+ orig._leaveAttrValue.call(this, toState);
87
+ mxn._attachCurrentAttrLocationInfo();
88
+ },
89
+
90
+ _emitCurrentToken() {
91
+ const ctLoc = this.currentToken.location;
92
+
93
+ //NOTE: if we have pending character token make it's end location equal to the
94
+ //current token's start location.
95
+ if (this.currentCharacterToken) {
96
+ this.currentCharacterToken.location.endLine = ctLoc.startLine;
97
+ this.currentCharacterToken.location.endCol = ctLoc.startCol;
98
+ this.currentCharacterToken.location.endOffset = ctLoc.startOffset;
99
+ }
100
+
101
+ if (this.currentToken.type === Tokenizer.EOF_TOKEN) {
102
+ ctLoc.endLine = ctLoc.startLine;
103
+ ctLoc.endCol = ctLoc.startCol;
104
+ ctLoc.endOffset = ctLoc.startOffset;
105
+ } else {
106
+ ctLoc.endLine = mxn.posTracker.line;
107
+ ctLoc.endCol = mxn.posTracker.col + 1;
108
+ ctLoc.endOffset = mxn.posTracker.offset + 1;
109
+ }
110
+
111
+ orig._emitCurrentToken.call(this);
112
+ },
113
+
114
+ _emitCurrentCharacterToken() {
115
+ const ctLoc = this.currentCharacterToken && this.currentCharacterToken.location;
116
+
117
+ //NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(),
118
+ //then set it's location at the current preprocessor position.
119
+ //We don't need to increment preprocessor position, since character token
120
+ //emission is always forced by the start of the next character token here.
121
+ //So, we already have advanced position.
122
+ if (ctLoc && ctLoc.endOffset === -1) {
123
+ ctLoc.endLine = mxn.posTracker.line;
124
+ ctLoc.endCol = mxn.posTracker.col;
125
+ ctLoc.endOffset = mxn.posTracker.offset;
126
+ }
127
+
128
+ orig._emitCurrentCharacterToken.call(this);
129
+ }
130
+ };
131
+
132
+ //NOTE: patch initial states for each mode to obtain token start position
133
+ Object.keys(Tokenizer.MODE).forEach(modeName => {
134
+ const state = Tokenizer.MODE[modeName];
135
+
136
+ methods[state] = function(cp) {
137
+ mxn.ctLoc = mxn._getCurrentLocation();
138
+ orig[state].call(this, cp);
139
+ };
140
+ });
141
+
142
+ return methods;
143
+ }
144
+ }
145
+
146
+ module.exports = LocationInfoTokenizerMixin;
@@ -0,0 +1,64 @@
1
+ 'use strict';
2
+
3
+ const Mixin = require('../../utils/mixin');
4
+
5
+ class PositionTrackingPreprocessorMixin extends Mixin {
6
+ constructor(preprocessor) {
7
+ super(preprocessor);
8
+
9
+ this.preprocessor = preprocessor;
10
+ this.isEol = false;
11
+ this.lineStartPos = 0;
12
+ this.droppedBufferSize = 0;
13
+
14
+ this.offset = 0;
15
+ this.col = 0;
16
+ this.line = 1;
17
+ }
18
+
19
+ _getOverriddenMethods(mxn, orig) {
20
+ return {
21
+ advance() {
22
+ const pos = this.pos + 1;
23
+ const ch = this.html[pos];
24
+
25
+ //NOTE: LF should be in the last column of the line
26
+ if (mxn.isEol) {
27
+ mxn.isEol = false;
28
+ mxn.line++;
29
+ mxn.lineStartPos = pos;
30
+ }
31
+
32
+ if (ch === '\n' || (ch === '\r' && this.html[pos + 1] !== '\n')) {
33
+ mxn.isEol = true;
34
+ }
35
+
36
+ mxn.col = pos - mxn.lineStartPos + 1;
37
+ mxn.offset = mxn.droppedBufferSize + pos;
38
+
39
+ return orig.advance.call(this);
40
+ },
41
+
42
+ retreat() {
43
+ orig.retreat.call(this);
44
+
45
+ mxn.isEol = false;
46
+ mxn.col = this.pos - mxn.lineStartPos + 1;
47
+ },
48
+
49
+ dropParsedChunk() {
50
+ const prevPos = this.pos;
51
+
52
+ orig.dropParsedChunk.call(this);
53
+
54
+ const reduction = prevPos - this.pos;
55
+
56
+ mxn.lineStartPos -= reduction;
57
+ mxn.droppedBufferSize += reduction;
58
+ mxn.offset = mxn.droppedBufferSize + this.pos;
59
+ }
60
+ };
61
+ }
62
+ }
63
+
64
+ module.exports = PositionTrackingPreprocessorMixin;
package/lib/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  'use strict';
2
2
 
3
- var Parser = require('./parser'),
4
- Serializer = require('./serializer');
5
-
3
+ const Parser = require('./parser');
4
+ const Serializer = require('./serializer');
6
5
 
7
6
  // Shorthands
8
7
  exports.parse = function parse(html, options) {
9
- var parser = new Parser(options);
8
+ const parser = new Parser(options);
10
9
 
11
10
  return parser.parse(html);
12
11
  };
@@ -18,27 +17,13 @@ exports.parseFragment = function parseFragment(fragmentContext, html, options) {
18
17
  fragmentContext = null;
19
18
  }
20
19
 
21
- var parser = new Parser(options);
20
+ const parser = new Parser(options);
22
21
 
23
22
  return parser.parseFragment(html, fragmentContext);
24
23
  };
25
24
 
26
- exports.serialize = function (node, options) {
27
- var serializer = new Serializer(node, options);
25
+ exports.serialize = function(node, options) {
26
+ const serializer = new Serializer(node, options);
28
27
 
29
28
  return serializer.serialize();
30
29
  };
31
-
32
-
33
- // Tree adapters
34
- exports.treeAdapters = {
35
- default: require('./tree_adapters/default'),
36
- htmlparser2: require('./tree_adapters/htmlparser2')
37
- };
38
-
39
-
40
- // Streaming
41
- exports.ParserStream = require('./parser/parser_stream');
42
- exports.PlainTextConversionStream = require('./parser/plain_text_conversion_stream');
43
- exports.SerializerStream = require('./serializer/serializer_stream');
44
- exports.SAXParser = require('./sax');