Index: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js |
— | — | @@ -167,7 +167,7 @@ |
168 | 168 | firstmultiletterword = j; |
169 | 169 | } |
170 | 170 | } |
171 | | - } else if ( ( ctx.prevToken.type === 'NEWLINE' || |
| 171 | + } else if ( ( ctx.prevToken.constructor === NlTk || |
172 | 172 | ctx.prevToken.type === 'TAG' ) && |
173 | 173 | firstmultiletterword == -1 ) { |
174 | 174 | // This is an approximation, as the original doQuotes |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.HTML5TreeBuilder.node.js |
— | — | @@ -71,55 +71,56 @@ |
72 | 72 | // html tree builder by emitting the token. |
73 | 73 | FauxHTML5.TreeBuilder.prototype.processToken = function (token) { |
74 | 74 | |
75 | | - if ( token.constructor === String ) { |
76 | | - this.emit('token', {type: 'Characters', data: token}); |
77 | | - } else { |
78 | | - switch (token.type) { |
79 | | - case "TAG": |
80 | | - this.emit('token', {type: 'StartTag', |
81 | | - name: token.name, |
82 | | - data: this._att(token.attribs)}); |
83 | | - break; |
84 | | - case "ENDTAG": |
85 | | - this.emit('token', {type: 'EndTag', |
86 | | - name: token.name, |
87 | | - data: this._att(token.attribs)}); |
88 | | - break; |
89 | | - case "SELFCLOSINGTAG": |
90 | | - this.emit('token', {type: 'StartTag', |
91 | | - name: token.name, |
92 | | - data: this._att(token.attribs)}); |
93 | | - if ( HTML5.VOID_ELEMENTS.indexOf( token.name.toLowerCase() ) < 0 ) { |
94 | | - // VOID_ELEMENTS are automagically treated as self-closing by |
95 | | - // the tree builder |
| 75 | + switch( token.constructor ) { |
| 76 | + case String: |
| 77 | + this.emit('token', {type: 'Characters', data: token}); |
| 78 | + break; |
| 79 | + case NlTk: |
| 80 | + break; |
| 81 | + default: |
| 82 | + 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": |
96 | 89 | this.emit('token', {type: 'EndTag', |
97 | 90 | name: token.name, |
98 | 91 | data: this._att(token.attribs)}); |
99 | | - } |
100 | | - break; |
101 | | - case "COMMENT": |
102 | | - this.emit('token', {type: 'Comment', |
103 | | - data: token.value}); |
104 | | - break; |
105 | | - case "END": |
106 | | - this.emit('end'); |
107 | | - this.emit('token', { type: 'EOF' } ); |
108 | | - this.document = this.parser.document; |
109 | | - if ( ! this.document.body ) { |
110 | | - // HACK: This should not be needed really. |
111 | | - this.document.body = this.parser.document.getElementsByTagName('body')[0]; |
112 | | - } |
113 | | - // Emit the document to consumers |
114 | | - //this.emit('document', this.document); |
115 | | - break; |
116 | | - case "NEWLINE": |
117 | | - //this.emit('end'); |
118 | | - //this.emit('token', {type: 'Characters', data: "\n"}); |
119 | | - break; |
120 | | - default: |
121 | | - console.log("Unhandled token: " + JSON.stringify(token)); |
122 | | - break; |
123 | | - } |
| 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 | + case "COMMENT": |
| 106 | + this.emit('token', {type: 'Comment', |
| 107 | + data: token.value}); |
| 108 | + break; |
| 109 | + case "END": |
| 110 | + this.emit('end'); |
| 111 | + this.emit('token', { type: 'EOF' } ); |
| 112 | + this.document = this.parser.document; |
| 113 | + if ( ! this.document.body ) { |
| 114 | + // HACK: This should not be needed really. |
| 115 | + this.document.body = this.parser.document.getElementsByTagName('body')[0]; |
| 116 | + } |
| 117 | + // Emit the document to consumers |
| 118 | + //this.emit('document', this.document); |
| 119 | + break; |
| 120 | + default: |
| 121 | + console.log("Unhandled token: " + JSON.stringify(token)); |
| 122 | + break; |
| 123 | + } |
| 124 | + break; |
124 | 125 | } |
125 | 126 | }; |
126 | 127 | |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -487,29 +487,31 @@ |
488 | 488 | for ( var i = 0; i < tokensLength; i++ ) { |
489 | 489 | token = tokens[i]; |
490 | 490 | |
491 | | - if ( token.constructor === String ) { |
492 | | - res = this._transformToken( token, cb, phaseEndRank, ts.text ); |
493 | | - //console.log( 'transform string ' + token + ' res:' + JSON.stringify( res ) ); |
494 | | - } else { |
495 | | - switch( token.type ) { |
496 | | - case 'TAG': |
497 | | - case 'ENDTAG': |
498 | | - case 'SELFCLOSINGTAG': |
499 | | - res = this._transformTagToken( token, cb, phaseEndRank ); |
500 | | - break; |
501 | | - case 'COMMENT': |
502 | | - res = this._transformToken( token, cb, phaseEndRank, ts.comment); |
503 | | - break; |
504 | | - case 'NEWLINE': |
505 | | - res = this._transformToken( token, cb, phaseEndRank, ts.newline ); |
506 | | - break; |
507 | | - case 'END': |
508 | | - res = this._transformToken( token, cb, phaseEndRank, ts.end ); |
509 | | - break; |
510 | | - default: |
511 | | - res = this._transformToken( token, cb, phaseEndRank, ts.martian ); |
512 | | - break; |
513 | | - } |
| 491 | + switch ( token.constructor ) { |
| 492 | + case String: |
| 493 | + res = this._transformToken( token, cb, phaseEndRank, ts.text ); |
| 494 | + break; |
| 495 | + case NlTk: |
| 496 | + res = this._transformToken( token, cb, phaseEndRank, ts.newline ); |
| 497 | + break; |
| 498 | + default: |
| 499 | + switch( token.type ) { |
| 500 | + case 'TAG': |
| 501 | + case 'ENDTAG': |
| 502 | + case 'SELFCLOSINGTAG': |
| 503 | + res = this._transformTagToken( token, cb, phaseEndRank ); |
| 504 | + break; |
| 505 | + case 'COMMENT': |
| 506 | + res = this._transformToken( token, cb, phaseEndRank, ts.comment); |
| 507 | + break; |
| 508 | + case 'END': |
| 509 | + res = this._transformToken( token, cb, phaseEndRank, ts.end ); |
| 510 | + break; |
| 511 | + default: |
| 512 | + res = this._transformToken( token, cb, phaseEndRank, ts.martian ); |
| 513 | + break; |
| 514 | + } |
| 515 | + break; |
514 | 516 | } |
515 | 517 | |
516 | 518 | if( res.tokens ) { |
— | — | @@ -666,30 +668,31 @@ |
667 | 669 | for ( var i = 0; i < tokensLength; i++ ) { |
668 | 670 | token = tokens[i]; |
669 | 671 | |
670 | | - if ( token.constructor === String ) { |
671 | | - res = this._transformToken( token, cb, this.phaseEndRank, |
672 | | - ts.text ); |
673 | | - } else { |
674 | | - |
675 | | - switch( token.type ) { |
676 | | - case 'TAG': |
677 | | - case 'ENDTAG': |
678 | | - case 'SELFCLOSINGTAG': |
679 | | - res = this._transformTagToken( token, cb, this.phaseEndRank ); |
680 | | - break; |
681 | | - case 'COMMENT': |
682 | | - res = this._transformToken( token, cb, this.phaseEndRank, ts.comment ); |
683 | | - break; |
684 | | - case 'NEWLINE': |
685 | | - res = this._transformToken( token, cb, this.phaseEndRank, ts.newline ); |
686 | | - break; |
687 | | - case 'END': |
688 | | - res = this._transformToken( token, cb, this.phaseEndRank, ts.end ); |
689 | | - break; |
690 | | - default: |
691 | | - res = this._transformToken( token, cb, this.phaseEndRank, ts.martian ); |
692 | | - break; |
693 | | - } |
| 672 | + switch( token.constructor ) { |
| 673 | + case String: |
| 674 | + res = this._transformToken( token, cb, this.phaseEndRank, |
| 675 | + ts.text ); |
| 676 | + break; |
| 677 | + case NlTk: |
| 678 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.newline ); |
| 679 | + break; |
| 680 | + default: |
| 681 | + switch( token.type ) { |
| 682 | + case 'TAG': |
| 683 | + case 'ENDTAG': |
| 684 | + case 'SELFCLOSINGTAG': |
| 685 | + res = this._transformTagToken( token, cb, this.phaseEndRank ); |
| 686 | + break; |
| 687 | + case 'COMMENT': |
| 688 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.comment ); |
| 689 | + break; |
| 690 | + case 'END': |
| 691 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.end ); |
| 692 | + break; |
| 693 | + default: |
| 694 | + res = this._transformToken( token, cb, this.phaseEndRank, ts.martian ); |
| 695 | + break; |
| 696 | + } |
694 | 697 | } |
695 | 698 | |
696 | 699 | if( res.tokens ) { |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js |
— | — | @@ -0,0 +1,47 @@ |
| 2 | +/** |
| 3 | + * Constructors for different token types. Plain text is represented as simple |
| 4 | + * strings or String objects (if attributes are needed). |
| 5 | + */ |
| 6 | +function TagTk( name, attribs ) { |
| 7 | + this.type = 'TAG'; |
| 8 | + this.name = name; |
| 9 | + this.attribs = attribs || []; |
| 10 | +} |
| 11 | + |
| 12 | +function EndTagTk( name, attribs ) { |
| 13 | + this.type = 'ENDTAG'; |
| 14 | + this.name = name; |
| 15 | + this.attribs = attribs || []; |
| 16 | +} |
| 17 | +function SelfclosingTagTk( name, attribs ) { |
| 18 | + this.type = 'SELFCLOSINGTAG'; |
| 19 | + this.name = name; |
| 20 | + this.attribs = attribs || []; |
| 21 | +} |
| 22 | +function NlTk( ) { |
| 23 | + //this.type = 'NEWLINE'; |
| 24 | +} |
| 25 | +function CommentTk( value ) { |
| 26 | + this.type = 'COMMENT'; |
| 27 | + this.value = value; |
| 28 | +} |
| 29 | +function EOFTk( ) { |
| 30 | + this.type = 'END'; |
| 31 | +} |
| 32 | + |
| 33 | +// A key-value pair |
| 34 | +function KV ( k, v ) { |
| 35 | + this.k = k; |
| 36 | + this.v = v; |
| 37 | +} |
| 38 | + |
| 39 | +if (typeof module == "object") { |
| 40 | + module.exports = {}; |
| 41 | + global.TagTk = TagTk; |
| 42 | + global.EndTagTk = EndTagTk; |
| 43 | + global.SelfclosingTagTk = SelfclosingTagTk; |
| 44 | + global.NlTk = NlTk; |
| 45 | + global.CommentTk = CommentTk; |
| 46 | + global.EOFTk = EOFTk; |
| 47 | + global.KV = KV; |
| 48 | +} |
Property changes on: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.defines.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 49 | + native |