Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | } |
170 | 170 | } |
171 | 171 | } else if ( ( ctx.prevToken.constructor === NlTk || |
172 | | - ctx.prevToken.type === 'TAG' ) && |
| 172 | + ctx.prevToken.constructor === TagTk ) && |
173 | 173 | firstmultiletterword == -1 ) { |
174 | 174 | // This is an approximation, as the original doQuotes |
175 | 175 | // operates on the source and just looks at space vs. |
— | — | @@ -244,18 +244,15 @@ |
245 | 245 | //console.log( 'quotesToTags t: ' + JSON.stringify( t, null, 2)); |
246 | 246 | |
247 | 247 | if(toggle) { |
248 | | - t.type = 'TAG'; |
| 248 | + chunks[j][0] = new TagTk( name, t.attribs ); |
249 | 249 | } else { |
250 | | - t.type = 'ENDTAG'; |
| 250 | + chunks[j][0] = new EndTagTk( name, t.attribs ); |
251 | 251 | } |
252 | | - t.name = name; |
253 | | - delete t.value; |
254 | | - chunks[j][0] = t; |
255 | 252 | toggle = !toggle; |
256 | 253 | } |
257 | 254 | if (!toggle) { |
258 | 255 | // Add end tag |
259 | | - this.currentChunk.push( {type: 'ENDTAG', name: name} ); |
| 256 | + this.currentChunk.push( new EndTagTk( name ) ); |
260 | 257 | } |
261 | 258 | }; |
262 | 259 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | this.parser.parse(this); |
19 | 19 | |
20 | 20 | // implicitly start a new document |
21 | | - this.processToken({type: 'TAG', name: 'body'}); |
| 21 | + this.processToken(new TagTk( 'body' )); |
22 | 22 | }; |
23 | 23 | |
24 | 24 | // Inherit from EventEmitter |
— | — | @@ -53,7 +53,7 @@ |
54 | 54 | |
55 | 55 | // XXX: more clean up to allow reuse. |
56 | 56 | this.parser.setup(); |
57 | | - this.processToken({type: 'TAG', name: 'body'}); |
| 57 | + this.processToken(new TagTk( 'body' )); |
58 | 58 | }; |
59 | 59 | |
60 | 60 | FauxHTML5.TreeBuilder.prototype._att = function (maybeAttribs) { |
— | — | @@ -77,30 +77,30 @@ |
78 | 78 | break; |
79 | 79 | case NlTk: |
80 | 80 | break; |
| 81 | + case TagTk: |
| 82 | + this.emit('token', {type: 'StartTag', |
| 83 | + name: token.name, |
| 84 | + data: this._att(token.attribs)}); |
| 85 | + break; |
| 86 | + case SelfclosingTagTk: |
| 87 | + this.emit('token', {type: 'StartTag', |
| 88 | + name: token.name, |
| 89 | + data: this._att(token.attribs)}); |
| 90 | + if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) { |
| 91 | + // VOID_ELEMENTS are automagically treated as self-closing by |
| 92 | + // the tree builder |
| 93 | + this.emit('token', {type: 'EndTag', |
| 94 | + name: token.name, |
| 95 | + data: this._att(token.attribs)}); |
| 96 | + } |
| 97 | + break; |
| 98 | + case EndTagTk: |
| 99 | + this.emit('token', {type: 'EndTag', |
| 100 | + name: token.name, |
| 101 | + data: this._att(token.attribs)}); |
| 102 | + break; |
81 | 103 | default: |
82 | 104 | switch (token.type) { |
83 | | - case "TAG": |
84 | | - this.emit('token', {type: 'StartTag', |
85 | | - name: token.name, |
86 | | - data: this._att(token.attribs)}); |
87 | | - break; |
88 | | - case "ENDTAG": |
89 | | - this.emit('token', {type: 'EndTag', |
90 | | - name: token.name, |
91 | | - data: this._att(token.attribs)}); |
92 | | - break; |
93 | | - case "SELFCLOSINGTAG": |
94 | | - this.emit('token', {type: 'StartTag', |
95 | | - name: token.name, |
96 | | - data: this._att(token.attribs)}); |
97 | | - if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) { |
98 | | - // VOID_ELEMENTS are automagically treated as self-closing by |
99 | | - // the tree builder |
100 | | - this.emit('token', {type: 'EndTag', |
101 | | - name: token.name, |
102 | | - data: this._att(token.attribs)}); |
103 | | - } |
104 | | - break; |
105 | 105 | case "COMMENT": |
106 | 106 | this.emit('token', {type: 'Comment', |
107 | 107 | data: token.value}); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -494,13 +494,13 @@ |
495 | 495 | case NlTk: |
496 | 496 | res = this._transformToken( token, cb, phaseEndRank, ts.newline ); |
497 | 497 | break; |
| 498 | + case TagTk: |
| 499 | + case EndTagTk: |
| 500 | + case SelfclosingTagTk: |
| 501 | + res = this._transformTagToken( token, cb, phaseEndRank ); |
| 502 | + break; |
498 | 503 | default: |
499 | 504 | switch( token.type ) { |
500 | | - case 'TAG': |
501 | | - case 'ENDTAG': |
502 | | - case 'SELFCLOSINGTAG': |
503 | | - res = this._transformTagToken( token, cb, phaseEndRank ); |
504 | | - break; |
505 | 505 | case 'COMMENT': |
506 | 506 | res = this._transformToken( token, cb, phaseEndRank, ts.comment); |
507 | 507 | break; |
— | — | @@ -676,13 +676,13 @@ |
677 | 677 | case NlTk: |
678 | 678 | res = this._transformToken( token, cb, this.phaseEndRank, ts.newline ); |
679 | 679 | break; |
| 680 | + case TagTk: |
| 681 | + case EndTagTk: |
| 682 | + case SelfclosingTagTk: |
| 683 | + res = this._transformTagToken( token, cb, this.phaseEndRank ); |
| 684 | + break; |
680 | 685 | default: |
681 | 686 | switch( token.type ) { |
682 | | - case 'TAG': |
683 | | - case 'ENDTAG': |
684 | | - case 'SELFCLOSINGTAG': |
685 | | - res = this._transformTagToken( token, cb, this.phaseEndRank ); |
686 | | - break; |
687 | 687 | case 'COMMENT': |
688 | 688 | res = this._transformToken( token, cb, this.phaseEndRank, ts.comment ); |
689 | 689 | break; |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js |
— | — | @@ -3,18 +3,18 @@ |
4 | 4 | * strings or String objects (if attributes are needed). |
5 | 5 | */ |
6 | 6 | function TagTk( name, attribs ) { |
7 | | - this.type = 'TAG'; |
| 7 | + //this.type = 'TAG'; |
8 | 8 | this.name = name; |
9 | 9 | this.attribs = attribs || []; |
10 | 10 | } |
11 | 11 | |
12 | 12 | function EndTagTk( name, attribs ) { |
13 | | - this.type = 'ENDTAG'; |
| 13 | + //this.type = 'ENDTAG'; |
14 | 14 | this.name = name; |
15 | 15 | this.attribs = attribs || []; |
16 | 16 | } |
17 | 17 | function SelfclosingTagTk( name, attribs ) { |
18 | | - this.type = 'SELFCLOSINGTAG'; |
| 18 | + //this.type = 'SELFCLOSINGTAG'; |
19 | 19 | this.name = name; |
20 | 20 | this.attribs = attribs || []; |
21 | 21 | } |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js |
— | — | @@ -80,7 +80,7 @@ |
81 | 81 | }; |
82 | 82 | |
83 | 83 | ParserFunctions.prototype['pf_#tag'] = function ( target, argList, argDict ) { |
84 | | - return [{type: 'TAG', name: target, attribs: argList}]; |
| 84 | + return [new TagTk(target, argList)]; |
85 | 85 | }; |
86 | 86 | |
87 | 87 | // A first approximation, anyway.. |
Index: trunk/extensions/VisualEditor/modules/parser/ext.Util.js |
— | — | @@ -16,9 +16,9 @@ |
17 | 17 | * @returns {Boolean}: True if token is block-level, false otherwise. |
18 | 18 | */ |
19 | 19 | Util.prototype.isBlockToken = function ( token ) { |
20 | | - if ( token.type === 'TAG' || |
21 | | - token.type === 'ENDTAG' || |
22 | | - token.type === 'SELFCLOSINGTAG' ) { |
| 20 | + if ( token.constructor === TagTk || |
| 21 | + token.constructor === EndTagTk || |
| 22 | + token.constructor === SelfclosingTagTk ) { |
23 | 23 | return this.isBlockTag( token.name.toLowerCase() ); |
24 | 24 | } else { |
25 | 25 | return false; |
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -150,8 +150,8 @@ |
151 | 151 | |
152 | 152 | for (var i = 0, length = tokens.length; i < length; i++) { |
153 | 153 | var token = tokens[i]; |
154 | | - switch ( token.type ) { |
155 | | - case 'TAG': |
| 154 | + switch ( token.constructor ) { |
| 155 | + case TagTk: |
156 | 156 | switch (token.name) { |
157 | 157 | case 'list': |
158 | 158 | // ignore token |
— | — | @@ -168,7 +168,7 @@ |
169 | 169 | break; |
170 | 170 | } |
171 | 171 | break; |
172 | | - case 'ENDTAG': |
| 172 | + case EndTagTk: |
173 | 173 | if ( token.name == 'list' ) { |
174 | 174 | // pop all open list item tokens |
175 | 175 | popTags(bstack.length); |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.Sanitizer.js |
— | — | @@ -29,7 +29,7 @@ |
30 | 30 | |
31 | 31 | Sanitizer.prototype.onAnchor = function ( token ) { |
32 | 32 | // perform something similar to Sanitizer::cleanUrl |
33 | | - if ( token.type === 'ENDTAG' ) { |
| 33 | + if ( token.constructor === EndTagTk ) { |
34 | 34 | return { token: token }; |
35 | 35 | } |
36 | 36 | var hrefKV = this.manager.env.lookupKV( token.attribs, 'href' ); |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js |
— | — | @@ -85,7 +85,7 @@ |
86 | 86 | // None of the tokens we are interested in, so abort processing.. |
87 | 87 | //console.log( 'PostExpandParagraphHandler.onAny: ' + JSON.stringify( this.tokens, null , 2 ) ); |
88 | 88 | if ( this.newLines >= 2 && ! u.isBlockToken( token ) ) { |
89 | | - return { tokens: [ { type: 'TAG', name: 'p' } ].concat( this._finish() ) }; |
| 89 | + return { tokens: [ new TagTk( 'p' ) ].concat( this._finish() ) }; |
90 | 90 | } else { |
91 | 91 | return { tokens: this._finish() }; |
92 | 92 | } |