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
@@ -1,117 +0,0 @@
1
- 'use strict';
2
-
3
- var Mixin = require('../../utils/mixin'),
4
- Tokenizer = require('../../tokenizer'),
5
- PositionTrackingPreprocessorMixin = require('../position_tracking/preprocessor_mixin'),
6
- inherits = require('util').inherits;
7
-
8
- var LocationInfoTokenizerMixin = module.exports = function (tokenizer) {
9
- Mixin.call(this, tokenizer);
10
-
11
- this.tokenizer = tokenizer;
12
- this.posTracker = new PositionTrackingPreprocessorMixin(tokenizer.preprocessor);
13
- this.currentAttrLocation = null;
14
- this.currentTokenLocation = null;
15
- };
16
-
17
- inherits(LocationInfoTokenizerMixin, Mixin);
18
-
19
- LocationInfoTokenizerMixin.prototype._getCurrentLocation = function () {
20
- return {
21
- line: this.posTracker.line,
22
- col: this.posTracker.col,
23
- startOffset: this.posTracker.offset,
24
- endOffset: -1
25
- };
26
- };
27
-
28
- LocationInfoTokenizerMixin.prototype._attachCurrentAttrLocationInfo = function () {
29
- this.currentAttrLocation.endOffset = this.posTracker.offset;
30
-
31
- var currentToken = this.tokenizer.currentToken,
32
- currentAttr = this.tokenizer.currentAttr;
33
-
34
- if (!currentToken.location.attrs)
35
- currentToken.location.attrs = Object.create(null);
36
-
37
- currentToken.location.attrs[currentAttr.name] = this.currentAttrLocation;
38
- };
39
-
40
- LocationInfoTokenizerMixin.prototype._getOverriddenMethods = function (mxn, orig) {
41
- var methods = {
42
- _createStartTagToken: function () {
43
- orig._createStartTagToken.call(this);
44
- this.currentToken.location = mxn.currentTokenLocation;
45
- },
46
-
47
- _createEndTagToken: function () {
48
- orig._createEndTagToken.call(this);
49
- this.currentToken.location = mxn.currentTokenLocation;
50
- },
51
-
52
- _createCommentToken: function () {
53
- orig._createCommentToken.call(this);
54
- this.currentToken.location = mxn.currentTokenLocation;
55
- },
56
-
57
- _createDoctypeToken: function (initialName) {
58
- orig._createDoctypeToken.call(this, initialName);
59
- this.currentToken.location = mxn.currentTokenLocation;
60
- },
61
-
62
- _createCharacterToken: function (type, ch) {
63
- orig._createCharacterToken.call(this, type, ch);
64
- this.currentCharacterToken.location = mxn.currentTokenLocation;
65
- },
66
-
67
- _createAttr: function (attrNameFirstCh) {
68
- orig._createAttr.call(this, attrNameFirstCh);
69
- mxn.currentAttrLocation = mxn._getCurrentLocation();
70
- },
71
-
72
- _leaveAttrName: function (toState) {
73
- orig._leaveAttrName.call(this, toState);
74
- mxn._attachCurrentAttrLocationInfo();
75
- },
76
-
77
- _leaveAttrValue: function (toState) {
78
- orig._leaveAttrValue.call(this, toState);
79
- mxn._attachCurrentAttrLocationInfo();
80
- },
81
-
82
- _emitCurrentToken: function () {
83
- //NOTE: if we have pending character token make it's end location equal to the
84
- //current token's start location.
85
- if (this.currentCharacterToken)
86
- this.currentCharacterToken.location.endOffset = this.currentToken.location.startOffset;
87
-
88
- this.currentToken.location.endOffset = mxn.posTracker.offset + 1;
89
- orig._emitCurrentToken.call(this);
90
- },
91
-
92
- _emitCurrentCharacterToken: function () {
93
- //NOTE: if we have character token and it's location wasn't set in the _emitCurrentToken(),
94
- //then set it's location at the current preprocessor position.
95
- //We don't need to increment preprocessor position, since character token
96
- //emission is always forced by the start of the next character token here.
97
- //So, we already have advanced position.
98
- if (this.currentCharacterToken && this.currentCharacterToken.location.endOffset === -1)
99
- this.currentCharacterToken.location.endOffset = mxn.posTracker.offset;
100
-
101
- orig._emitCurrentCharacterToken.call(this);
102
- }
103
- };
104
-
105
- //NOTE: patch initial states for each mode to obtain token start position
106
- Object.keys(Tokenizer.MODE).forEach(function (modeName) {
107
- var state = Tokenizer.MODE[modeName];
108
-
109
- methods[state] = function (cp) {
110
- mxn.currentTokenLocation = mxn._getCurrentLocation();
111
- orig[state].call(this, cp);
112
- };
113
- });
114
-
115
- return methods;
116
- };
117
-
@@ -1,72 +0,0 @@
1
- 'use strict';
2
-
3
- var Mixin = require('../../utils/mixin'),
4
- inherits = require('util').inherits,
5
- UNICODE = require('../../common/unicode');
6
-
7
- //Aliases
8
- var $ = UNICODE.CODE_POINTS;
9
-
10
- var PositionTrackingPreprocessorMixin = module.exports = function (preprocessor) {
11
- // NOTE: avoid installing tracker twice
12
- if (!preprocessor.__locTracker) {
13
- preprocessor.__locTracker = this;
14
-
15
- Mixin.call(this, preprocessor);
16
-
17
- this.preprocessor = preprocessor;
18
- this.isEol = false;
19
- this.lineStartPos = 0;
20
- this.droppedBufferSize = 0;
21
-
22
- this.col = -1;
23
- this.line = 1;
24
- }
25
-
26
- return preprocessor.__locTracker;
27
- };
28
-
29
- inherits(PositionTrackingPreprocessorMixin, Mixin);
30
-
31
- Object.defineProperty(PositionTrackingPreprocessorMixin.prototype, 'offset', {
32
- get: function () {
33
- return this.droppedBufferSize + this.preprocessor.pos;
34
- }
35
- });
36
-
37
- PositionTrackingPreprocessorMixin.prototype._getOverriddenMethods = function (mxn, orig) {
38
- return {
39
- advance: function () {
40
- var cp = orig.advance.call(this);
41
-
42
- //NOTE: LF should be in the last column of the line
43
- if (mxn.isEol) {
44
- mxn.isEol = false;
45
- mxn.line++;
46
- mxn.lineStartPos = mxn.offset;
47
- }
48
-
49
- if (cp === $.LINE_FEED)
50
- mxn.isEol = true;
51
-
52
- mxn.col = mxn.offset - mxn.lineStartPos + 1;
53
-
54
- return cp;
55
- },
56
-
57
- retreat: function () {
58
- orig.retreat.call(this);
59
- mxn.isEol = false;
60
-
61
- mxn.col = mxn.offset - mxn.lineStartPos + 1;
62
- },
63
-
64
- dropParsedChunk: function () {
65
- var prevPos = this.pos;
66
-
67
- orig.dropParsedChunk.call(this);
68
-
69
- mxn.droppedBufferSize += prevPos - this.pos;
70
- }
71
- };
72
- };