Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | // others for serialized tokens etc |
49 | 49 | inputType = 'text/wiki'; |
50 | 50 | } |
| 51 | + this.inputType = inputType; |
51 | 52 | |
52 | 53 | |
53 | 54 | // XXX: create a full-fledged environment based on |
— | — | @@ -58,11 +59,10 @@ |
59 | 60 | } |
60 | 61 | |
61 | 62 | // set up a sub-pipeline cache |
62 | | - this.pipelineCache = { |
63 | | - 'text/wiki': { |
64 | | - 'input': [], |
65 | | - 'attribute': [] |
66 | | - } |
| 63 | + this.pipelineCache = {}; |
| 64 | + this.pipelineCache[this.inputType] = { |
| 65 | + 'input': [], |
| 66 | + 'attribute': [] |
67 | 67 | }; |
68 | 68 | |
69 | 69 | // Create an input pipeline for the given input type. |
— | — | @@ -76,9 +76,10 @@ |
77 | 77 | |
78 | 78 | |
79 | 79 | // Add token transformations.. |
80 | | - new QuoteTransformer( this.tokenPostProcessor ); |
81 | | - new PostExpandParagraphHandler( this.tokenPostProcessor ); |
82 | | - new Sanitizer( this.tokenPostProcessor ); |
| 80 | + this._addTransformers( this.inputType, 'sync23', this.tokenPostProcessor, false ); |
| 81 | + //new QuoteTransformer( this.tokenPostProcessor ); |
| 82 | + //new PostExpandParagraphHandler( this.tokenPostProcessor ); |
| 83 | + //new Sanitizer( this.tokenPostProcessor ); |
83 | 84 | |
84 | 85 | //var citeExtension = new Cite( this.tokenTransformer ); |
85 | 86 | |
— | — | @@ -128,7 +129,59 @@ |
129 | 130 | ParserPipeline.prototype = new events.EventEmitter(); |
130 | 131 | ParserPipeline.prototype.constructor = ParserPipeline; |
131 | 132 | |
| 133 | + |
| 134 | +/** |
| 135 | + * Token stream transformations to register by type and per phase. The |
| 136 | + * possible ranks for individual transformation registrations are [0,1) |
| 137 | + * (excluding 1.0) for sync01, [1,2) for async12 and [2,3) for sync23. |
| 138 | + */ |
| 139 | +ParserPipeline.prototype._transformers = { |
| 140 | + 'text/wiki': { |
| 141 | + // Synchronous in-order per input |
| 142 | + sync01: |
| 143 | + [ |
| 144 | + IncludeOnly, |
| 145 | + NoInclude |
| 146 | + ], |
| 147 | + // Asynchronous out-of-order per input |
| 148 | + async12: |
| 149 | + [ |
| 150 | + TemplateHandler, |
| 151 | + AttributeExpander |
| 152 | + ], |
| 153 | + // Synchronous in-order on fully expanded token stream (including |
| 154 | + // expanded templates etc). |
| 155 | + sync23: |
| 156 | + [ |
| 157 | + QuoteTransformer, |
| 158 | + PostExpandParagraphHandler, |
| 159 | + /* Cite, */ |
| 160 | + Sanitizer |
| 161 | + ] |
| 162 | + } |
| 163 | +}; |
| 164 | + |
132 | 165 | /** |
| 166 | + * Add all transformers to a token transform manager for a given input type |
| 167 | + * and phase. |
| 168 | + */ |
| 169 | +ParserPipeline.prototype._addTransformers = function ( type, phase, manager, isInclude ) |
| 170 | +{ |
| 171 | + var transformers; |
| 172 | + try { |
| 173 | + transformers = this._transformers[type][phase]; |
| 174 | + } catch ( e ) { |
| 175 | + console.warn( 'Error while looking for token transformers for ' + |
| 176 | + type + ' and phase ' + phase ); |
| 177 | + transformers = []; |
| 178 | + } |
| 179 | + for ( var i = 0, l = transformers.length; i < l; i++ ) { |
| 180 | + new transformers[i]( manager, isInclude ); |
| 181 | + } |
| 182 | +}; |
| 183 | + |
| 184 | + |
| 185 | +/** |
133 | 186 | * Factory method for the input (up to async token transforms / phase two) |
134 | 187 | * parts of the parser pipeline. |
135 | 188 | * |
— | — | @@ -163,10 +216,10 @@ |
164 | 217 | var tokenPreProcessor = new TokenTransformManager.SyncTokenTransformManager ( this.env ); |
165 | 218 | tokenPreProcessor.listenForTokensFrom ( wikiTokenizer ); |
166 | 219 | |
167 | | - new IncludeOnly( tokenPreProcessor, ! isNoInclude ); |
168 | | - // Add noinclude transform for now |
169 | | - new NoInclude( tokenPreProcessor, ! isNoInclude ); |
| 220 | + this._addTransformers( 'text/wiki', 'sync01', |
| 221 | + tokenPreProcessor, ! isNoInclude ); |
170 | 222 | |
| 223 | + |
171 | 224 | var tokenExpander = new TokenTransformManager.AsyncTokenTransformManager ( |
172 | 225 | { |
173 | 226 | 'input': this.makeInputPipeline.bind( this ), |
— | — | @@ -176,8 +229,10 @@ |
177 | 230 | ); |
178 | 231 | |
179 | 232 | // Register template expansion extension |
180 | | - new TemplateHandler( tokenExpander ); |
181 | | - new AttributeExpander( tokenExpander ); |
| 233 | + this._addTransformers( 'text/wiki', 'async12', |
| 234 | + tokenExpander, ! isNoInclude ); |
| 235 | + //new TemplateHandler( tokenExpander ); |
| 236 | + //new AttributeExpander( tokenExpander ); |
182 | 237 | |
183 | 238 | tokenExpander.listenForTokensFrom ( tokenPreProcessor ); |
184 | 239 | // XXX: hack. |