Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -334,11 +334,12 @@ |
335 | 335 | * @param {Object} args, the argument map for templates |
336 | 336 | * @param {Object} env, the environment. |
337 | 337 | */ |
338 | | -function AsyncTokenTransformManager ( childFactories, args, env ) { |
| 338 | +function AsyncTokenTransformManager ( childFactories, args, env, inputType ) { |
339 | 339 | // Factory function for new AsyncTokenTransformManager creation with |
340 | 340 | // default transforms enabled |
341 | 341 | // Also sets up a tokenizer and phase-1-transform depending on the input format |
342 | 342 | // nestedAsyncTokenTransformManager = manager.newChildPipeline( inputType, args ); |
| 343 | + this.inputType = inputType; |
343 | 344 | this.childFactories = childFactories; |
344 | 345 | this._construct(); |
345 | 346 | this._reset( args, env ); |
— | — | @@ -624,12 +625,13 @@ |
625 | 626 | * @constructor |
626 | 627 | * @param {Object} environment. |
627 | 628 | */ |
628 | | -function SyncTokenTransformManager ( env, phaseEndRank ) { |
| 629 | +function SyncTokenTransformManager ( env, phaseEndRank, inputType ) { |
629 | 630 | // both inherited |
630 | 631 | this._construct(); |
631 | 632 | this.phaseEndRank = phaseEndRank; |
632 | 633 | this.args = {}; // no arguments at the top level |
633 | 634 | this.env = env; |
| 635 | + this.inputType = inputType; |
634 | 636 | } |
635 | 637 | |
636 | 638 | // Inherit from TokenTransformManager, and thus also from EventEmitter. |
— | — | @@ -777,13 +779,14 @@ |
778 | 780 | this.outstanding++; |
779 | 781 | |
780 | 782 | // transform the key |
781 | | - pipe = this.manager.getAttributePipeline( this.manager.args ); |
782 | | - pipe.addListener( 'chunk', |
| 783 | + pipe = this.manager.getAttributePipeline( this.manager.inputType, |
| 784 | + this.manager.args ); |
| 785 | + pipe.addListener( 'chunk', |
783 | 786 | this.onChunk.bind( this, this._returnAttributeKey.bind( this, i ) ) |
784 | | - ); |
| 787 | + ); |
785 | 788 | pipe.addListener( 'end', |
786 | 789 | this.onEnd.bind( this, this._returnAttributeKey.bind( this, i ) ) |
787 | | - ); |
| 790 | + ); |
788 | 791 | pipe.process( attributes[i].k.concat([{type:'END'}]) ); |
789 | 792 | } else { |
790 | 793 | kv.key = cur.k; |
— | — | @@ -794,7 +797,8 @@ |
795 | 798 | this.outstanding++; |
796 | 799 | |
797 | 800 | // transform the value |
798 | | - pipe = this.manager.getAttributePipeline( this.manager.args ); |
| 801 | + pipe = this.manager.getAttributePipeline( this.manager.inputType, |
| 802 | + this.manager.args ); |
799 | 803 | pipe.addListener( 'chunk', |
800 | 804 | this.onChunk.bind( this, this._returnAttributeValue.bind( this, i ) ) |
801 | 805 | ); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -71,7 +71,8 @@ |
72 | 72 | this.inputPipeline.last.atTopLevel = true; |
73 | 73 | |
74 | 74 | |
75 | | - this.tokenPostProcessor = new TokenTransformManager.SyncTokenTransformManager ( env ); |
| 75 | + this.tokenPostProcessor = new TokenTransformManager |
| 76 | + .SyncTokenTransformManager ( env, inputType ); |
76 | 77 | this.tokenPostProcessor.listenForTokensFrom ( this.inputPipeline ); |
77 | 78 | |
78 | 79 | |
— | — | @@ -209,11 +210,11 @@ |
210 | 211 | /** |
211 | 212 | * Token stream transformations. |
212 | 213 | * This is where all the wiki-specific functionality is implemented. |
213 | | - * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
| 214 | + * See |
| 215 | + * https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
214 | 216 | */ |
215 | | - // XXX: Use this.env.config.transforms['inputType'][stage] or |
216 | | - // somesuch to set up the transforms by input type |
217 | | - var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env ); |
| 217 | + var tokenPreProcessor = new TokenTransformManager |
| 218 | + .SyncTokenTransformManager ( this.env ); |
218 | 219 | tokenPreProcessor.listenForTokensFrom ( wikiTokenizer ); |
219 | 220 | |
220 | 221 | this._addTransformers( 'text/wiki', 'sync01', |
— | — | @@ -225,14 +226,12 @@ |
226 | 227 | 'input': this.makeInputPipeline.bind( this ), |
227 | 228 | 'attributes': this.makeAttributePipeline.bind( this ) |
228 | 229 | }, |
229 | | - args, this.env |
| 230 | + args, this.env, inputType |
230 | 231 | ); |
231 | 232 | |
232 | 233 | // Register template expansion extension |
233 | 234 | this._addTransformers( 'text/wiki', 'async12', |
234 | 235 | tokenExpander, ! isNoInclude ); |
235 | | - //new TemplateHandler( tokenExpander ); |
236 | | - //new AttributeExpander( tokenExpander ); |
237 | 236 | |
238 | 237 | tokenExpander.listenForTokensFrom ( tokenPreProcessor ); |
239 | 238 | // XXX: hack. |
— | — | @@ -259,9 +258,9 @@ |
260 | 259 | * Factory for attribute transformations, with input type implicit in the |
261 | 260 | * environment. |
262 | 261 | */ |
263 | | -ParserPipeline.prototype.makeAttributePipeline = function ( args ) { |
264 | | - if ( this.pipelineCache['text/wiki'].attribute.length ) { |
265 | | - var pipe = this.pipelineCache['text/wiki'].attribute.pop(); |
| 262 | +ParserPipeline.prototype.makeAttributePipeline = function ( inputType, args ) { |
| 263 | + if ( this.pipelineCache[inputType].attribute.length ) { |
| 264 | + var pipe = this.pipelineCache[inputType].attribute.pop(); |
266 | 265 | pipe.last.args = args; |
267 | 266 | return pipe; |
268 | 267 | } else { |
— | — | @@ -270,7 +269,12 @@ |
271 | 270 | * This is where all the wiki-specific functionality is implemented. |
272 | 271 | * See https://www.mediawiki.org/wiki/Future/Parser_development/Token_stream_transformations |
273 | 272 | */ |
274 | | - var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env ); |
| 273 | + var tokenPreProcessor = new TokenTransformManager |
| 274 | + .SyncTokenTransformManager ( this.env, inputType ); |
| 275 | + |
| 276 | + // XXX: set include flag properly! |
| 277 | + //this._addTransformers( inputType, 'sync01', tokenPreProcessor, false ); |
| 278 | + |
275 | 279 | new NoInclude( tokenPreProcessor ); |
276 | 280 | |
277 | 281 | var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager ( |
— | — | @@ -278,14 +282,17 @@ |
279 | 283 | 'input': this.makeInputPipeline.bind( this ), |
280 | 284 | 'attributes': this.makeAttributePipeline.bind( this ) |
281 | 285 | }, |
282 | | - args, this.env |
| 286 | + args, this.env, inputType |
283 | 287 | ); |
284 | | - new TemplateHandler( tokenExpander ); |
285 | | - new AttributeExpander( tokenExpander ); |
| 288 | + // Register template expansion extension |
| 289 | + this._addTransformers( 'text/wiki', 'async12', |
| 290 | + tokenExpander, false ); |
| 291 | + //new TemplateHandler( tokenExpander ); |
| 292 | + //new AttributeExpander( tokenExpander ); |
286 | 293 | tokenExpander.listenForTokensFrom ( tokenPreProcessor ); |
287 | 294 | |
288 | 295 | return new CachedTokenPipeline( |
289 | | - this.cachePipeline.bind( this, 'text/wiki', 'attribute' ), |
| 296 | + this.cachePipeline.bind( this, inputType, 'attribute' ), |
290 | 297 | tokenPreProcessor, |
291 | 298 | tokenExpander |
292 | 299 | ); |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -82,7 +82,7 @@ |
83 | 83 | JSON.stringify( attributes, null, 2 ) ); |
84 | 84 | new AttributeTransformManager( |
85 | 85 | this.manager, |
86 | | - this._returnAttributes.bind( this, tplExpandData ) |
| 86 | + this._returnAttributes.bind( this, tplExpandData ) |
87 | 87 | ).process( attributes ); |
88 | 88 | |
89 | 89 | // Unblock finish |