Index: trunk/extensions/VisualEditor/modules/parser/parse.js |
— | — | @@ -50,7 +50,7 @@ |
51 | 51 | wgScriptPath: argv.wgScriptPath, |
52 | 52 | wgScriptExtension: argv.wgScriptExtension, |
53 | 53 | // XXX: add options for this! |
54 | | - wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb/', |
| 54 | + wgUploadPath: 'http://upload.wikimedia.org/wikipedia/commons/thumb', |
55 | 55 | fetchTemplates: argv.fetchTemplates, |
56 | 56 | // enable/disable debug output using this switch |
57 | 57 | debug: argv.debug, |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.LinkHandler.js |
— | — | @@ -119,17 +119,37 @@ |
120 | 120 | |
121 | 121 | // extract options |
122 | 122 | var options = [], |
| 123 | + oHash = {}, |
123 | 124 | caption = null; |
124 | 125 | for( var i = 0, l = content.length; i<l; i++ ) { |
125 | 126 | var oContent = content[i], |
126 | | - oText = manager.env.tokensToString( oContent, true ); |
| 127 | + oText = manager.env.tokensToString( oContent.v, true ); |
| 128 | + //console.log( JSON.stringify( oText, null, 2 ) ); |
127 | 129 | if ( oText.constructor === String ) { |
128 | 130 | oText = oText.trim(); |
129 | 131 | if ( this._simpleImageOptions[ oText ] ) { |
130 | 132 | options.push( new KV( this._simpleImageOptions[ oText ], |
131 | 133 | oText ) ); |
| 134 | + oHash[ this._simpleImageOptions[ oText ] ] = oText; |
132 | 135 | continue; |
133 | | - } |
| 136 | + } else { |
| 137 | + var maybeSize = oText.match(/^(\d*)(?:x(\d+))?px$/); |
| 138 | + //console.log( maybeSize ); |
| 139 | + if ( maybeSize !== null ) { |
| 140 | + var x = maybeSize[1], |
| 141 | + y = maybeSize[2]; |
| 142 | + if ( x !== undefined ) { |
| 143 | + options.push(new KV( 'width', x ) ); |
| 144 | + oHash.width = x; |
| 145 | + } |
| 146 | + if ( y !== undefined ) { |
| 147 | + options.push(new KV( 'height', y ) ); |
| 148 | + oHash.height = y; |
| 149 | + } |
| 150 | + //console.log( JSON.stringify( oHash ) ); |
| 151 | + } |
| 152 | + } |
| 153 | + |
134 | 154 | } else { |
135 | 155 | var bits = oText[0].split( '=', 2 ); |
136 | 156 | if ( bits.length > 1 && this._prefixImageOptions[ bits[0].trim() ] ) { |
— | — | @@ -153,42 +173,17 @@ |
154 | 174 | var img = new SelfclosingTagTk( 'img', |
155 | 175 | [ |
156 | 176 | // FIXME! |
157 | | - new KV( 'height', options.height || '120' ), |
158 | | - new KV( 'width', options.width || '120' ), |
| 177 | + new KV( 'height', oHash.height || '120' ), |
| 178 | + new KV( 'width', oHash.width || '120' ), |
159 | 179 | new KV( 'src', path ), |
160 | | - new KV( 'alt', options.alt || title.key ) |
| 180 | + new KV( 'alt', oHash.alt || title.key ) |
161 | 181 | ] ); |
162 | 182 | |
163 | 183 | return { tokens: [ a, img, new EndTagTk( 'a' )] }; |
164 | 184 | }; |
165 | 185 | |
166 | | -WikiLinkHandler.prototype.parseImageOptions = function ( tokens ) { |
167 | | - var out = [], |
168 | | - s = ''; |
169 | 186 | |
170 | | - for ( var i = 0, l = tokens.length; i < l; i++ ) { |
171 | | - var token = tokens[i]; |
172 | | - if ( token.constructor === String ) { |
173 | | - s += token; |
174 | | - } else if ( token.constructor === NlTk ) { |
175 | | - s += '\n'; // XXX: preserve original newline |
176 | | - } else if ( token.constructor === CommentTk ) { |
177 | | - // strip it |
178 | | - } else { |
179 | | - var res = this.imageParser.processImageOptions( s, 'img_options' ), |
180 | | - last = res.last(); |
181 | 187 | |
182 | | - if ( res.last().k !== 'caption' ) { |
183 | | - last.v.push = [last.v, token]; |
184 | | - } |
185 | | - out.push( s ); |
186 | | - s = ''; |
187 | | - out.push(token); |
188 | | - } |
189 | | - } |
190 | | -}; |
191 | | - |
192 | | - |
193 | 188 | function ExternalLinkHandler( manager, isInclude ) { |
194 | 189 | this.manager = manager; |
195 | 190 | this.manager.addTransform( this.onUrlLink.bind( this ), this.rank, 'tag', 'urllink' ); |