https://www.mediawiki.org/wiki/Special:Code/MediaWiki/109200
Revision: 109200 Author: gwicke Date: 2012-01-17 20:01:21 +0000 (Tue, 17 Jan 2012) Log Message: ----------- Clean up 'END' token handling a bit. Modified Paths: -------------- trunk/extensions/VisualEditor/modules/parser/ext.Util.js trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js Modified: trunk/extensions/VisualEditor/modules/parser/ext.Util.js =================================================================== --- trunk/extensions/VisualEditor/modules/parser/ext.Util.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/ext.Util.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -1,5 +1,6 @@ /** * General utilities for token transforms + * XXX: move this to MWParserEnvironment? */ function Util () { Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js =================================================================== --- trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/ext.core.PostExpandParagraphHandler.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -32,7 +32,7 @@ }; PostExpandParagraphHandler.prototype.reset = function ( token, cb, frame, prevToken ) { - //console.log( 'PostExpandParagraphHandler.reset' ); + //console.log( 'PostExpandParagraphHandler.reset ' + JSON.stringify( this.tokens ) ); if ( this.newLines ) { return { tokens: this._finish() }; } else { Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js =================================================================== --- trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/ext.core.QuoteTransformer.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -38,8 +38,8 @@ this.quoteAndNewlineRank, 'newline' ); dispatcher.addTransform( this.onQuote.bind(this), this.quoteAndNewlineRank, 'tag', 'mw-quote' ); - // Reset internal state when we are done - dispatcher.addTransform( this.reset.bind(this), + // Treat end-of-input just the same as a newline + dispatcher.addTransform( this.onNewLine.bind(this), this.quoteAndNewlineRank, 'end' ); }; Modified: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js =================================================================== --- trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -18,8 +18,9 @@ this.register( manager ); } -TemplateHandler.prototype.reset = function () { +TemplateHandler.prototype.reset = function ( token ) { this.resultTokens = []; + return {token: token}; }; // constants @@ -34,8 +35,8 @@ this.rank, 'tag', 'templatearg' ); // Reset internal state when the parser pipeline is done - manager.addTransform( this.reset.bind(this), - this.rank, 'end' ); + //manager.addTransform( this.reset.bind(this), + // this.rank, 'end' ); }; @@ -119,7 +120,20 @@ tokens: [ { type: 'TEXT', - value: 'Template expansion loop detected!' + value: 'Template loop detected: ' + }, + { + type: 'TAG', + name: 'a', + attrib: [['href', target]] + }, + { + type: 'TEXT', + value: target + }, + { + type: 'ENDTAG', + name: 'a' } ] }; @@ -186,12 +200,18 @@ }; /** - * Handle the end event by calling our parentCB with notYetDone set to false. + * Handle the end event emitted by the parser pipeline by calling our parentCB + * with notYetDone set to false. */ -TemplateHandler.prototype._onEnd = function( ) { +TemplateHandler.prototype._onEnd = function( token ) { // Encapsulate the template in a single token, which contains all the // information needed for the editor. var res = this.resultTokens; + // Remove 'end' token from end + if ( res.length && res[res.length - 1].type === 'END' ) { + res.pop(); + } + /* [{ type: 'TAG', @@ -209,7 +229,6 @@ if ( this.isAsync ) { this.parentCB( res, false ); - this.reset(); } else { this.result = { tokens: res }; this.reset(); Modified: trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js =================================================================== --- trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/mediawiki.tokenizer.peg.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -49,7 +49,7 @@ out = this.parser.parse(text); // emit tokens here until we get that to work per toplevelblock in the // actual tokenizer - this.emit('chunk', out); + this.emit('chunk', out.concat( [{ type: 'END' }] ) ); this.emit('end'); //} catch (e) { //err = e; Modified: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt =================================================================== --- trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt 2012-01-17 20:01:21 UTC (rev 109200) @@ -769,7 +769,8 @@ "]]" // XXX In real MediaWiki, this is a language-dependent positive character // class. Can we work out a static negative class instead? - trail:(! [ \t(),.:-] tc:text_char { return tc })* { + // XXX: Exclude uppercase chars from non-latin languages too! + trail:(! [A-Z \t(),.:-] tc:text_char { return tc })* { var obj = { type: 'TAG', name: 'a', Modified: trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js =================================================================== --- trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js 2012-01-17 20:00:31 UTC (rev 109199) +++ trunk/extensions/VisualEditor/tests/parser/parserTests-whitelist.js 2012-01-17 20:01:21 UTC (rev 109200) @@ -20,7 +20,11 @@ // This is a rare edge case, and the new behavior is arguably more consistent testWhiteList["5 quotes, code coverage +1 line"] = "<p>'<i></i></p>"; +// The comment in the test already suggests this result as correct, but +// supplies the old result without preformatting. +testWhiteList["Bug 6200: Preformatted in <blockquote>"] = "<blockquote data-sourcePos=\"0:12\"><pre>\nBlah</pre></blockquote>"; + // empty table tags / with only a caption are legal in HTML5. testWhiteList["A table with no data."] = "<table></table>"; testWhiteList["A table with nothing but a caption"] = "<table><caption> caption</caption></table>"; _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs