r111042 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r111041‎ | r111042 | r111043 >
Date:16:36, 9 February 2012
Author:gwicke
Status:deferred
Tags:nodeploy, visualeditor 
Comment:
Improve support for preprocessor functionality in attributes; Support
multi-line xmlish tags with preprocessor stuff in attributes.
Modified paths:
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js (modified) (history)
  • /trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt (modified) (history)

Diff [purge]

Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js
@@ -766,6 +766,12 @@
767767 this.kvs.push( kv );
768768 var cur = attributes[i];
769769
 770+ if ( ! cur ) {
 771+ console.log( JSON.stringify( attributes ) );
 772+ console.trace();
 773+ continue;
 774+ }
 775+
770776 if ( cur.k.constructor !== String ) {
771777 // Assume that the return is async, will be decremented in callback
772778 this.outstanding++;
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt
@@ -360,6 +360,27 @@
361361 return flatten_string ( r );
362362 }
363363
 364+attribute_preprocessor_text
 365+ = r:( ts:(!inline_breaks t:[^=<>{\n\r&'"\t ] {return t})+ { return ts.join(''); }
 366+ / directive
 367+ / !inline_breaks [&%] )* {
 368+ //console.log('prep');
 369+ return flatten_string ( r );
 370+ }
 371+attribute_preprocessor_text_single
 372+ = r:( t:[^>{\n\r&']+ { return t.join(''); }
 373+ / directive
 374+ / !inline_breaks [&%] )* {
 375+ return flatten_string ( r );
 376+ }
 377+attribute_preprocessor_text_double
 378+ = r:( t:[^>{\n\r&"]+ { return t.join(''); }
 379+ / directive
 380+ / !inline_breaks [&%] )* {
 381+ //console.log( 'double:' + pp(r) );
 382+ return flatten_string ( r );
 383+ }
 384+
364385 // Plain text, but can contain templates, template arguments, comments etc-
365386 // all stuff that is normally handled by the preprocessor
366387 // Returns either a list of tokens, or a plain string (if nothing is to be
@@ -875,9 +896,11 @@
876897 }
877898 } else {
878899 if (trail) {
879 - target = target.concat( [ trail.join('') ] );
 900+ textTokens = target.concat( [ trail.join('') ] );
 901+ } else {
 902+ // copy list
 903+ textTokens = target.concat([]);
880904 }
881 - textTokens = target;
882905 }
883906 //console.log( "XXX:" + pp(obj) );
884907 return [obj].concat(textTokens, [new EndTagTk( 'a' )]);
@@ -1008,8 +1031,8 @@
10091032 = "<"
10101033 & { tagStartPos = pos; return true; } // remember the start position of this tag
10111034 end:"/"? name:[0-9a-zA-Z]+
1012 - attribs:generic_attribute*
1013 - space*
 1035+ attribs:generic_newline_attribute*
 1036+ ( space / newline ) *
10141037 selfclose:"/"?
10151038 ">" {
10161039 name = name.join('');
@@ -1025,6 +1048,19 @@
10261049 return res;
10271050 }
10281051
 1052+generic_newline_attribute
 1053+ = s:( space / newline )*
 1054+ name:generic_attribute_name
 1055+ value:(( space / newline )*
 1056+ v:generic_attribute_newline_value { return v })?
 1057+{
 1058+ if ( value !== '' ) {
 1059+ return new KV( name, value );
 1060+ } else {
 1061+ return new KV( name, '' );
 1062+ }
 1063+}
 1064+
10291065 generic_attribute
10301066 = s:space*
10311067 name:generic_attribute_name
@@ -1045,21 +1081,30 @@
10461082 return n.join('');
10471083 }
10481084
 1085+generic_attribute_newline_value
 1086+ = "=" (space / newline )* v:xml_att_value {
 1087+ return v;
 1088+ }
10491089 generic_attribute_value
10501090 = "=" space* v:att_value {
10511091 return v;
10521092 }
10531093
10541094 // XXX: attributes can contain templates and template args!!
 1095+xml_att_value
 1096+ = "'" t:attribute_preprocessor_text_single "'" { return t; }
 1097+ / '"' t:attribute_preprocessor_text_double '"' { return t; }
 1098+ / attribute_preprocessor_text
 1099+
 1100+// XXX: attributes can contain templates and template args!!
10551101 att_value
10561102 = t:(!inline_breaks c:[^ \t'"<>='\n] { return c } )+ {
10571103 return t.join('');
10581104 }
1059 - // XXX: is "\"" also valid html? or just Wikitext?
 1105+ // XXX: is "\"" also valid html? or just Wikitext?
10601106 / "'" t:[^'>]* "'" { return unquote("'", t.join('')); }
10611107 / '"' t:[^">]* '"' { return unquote('"', t.join('')); }
10621108
1063 -
10641109 /* Lists */
10651110 lists = e:(dtdd / li) es:(sol (dtdd / li))*
10661111 {
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js
@@ -43,7 +43,7 @@
4444 * processes the template.
4545 */
4646 AttributeExpander.prototype.onToken = function ( token, frame, cb ) {
47 - if ( token.constructor === TagTk && token.attributes ) {
 47+ if ( token.constructor === TagTk && token.attribs && token.attribs.length ) {
4848 var expandData = {
4949 token: token,
5050 cb: cb
@@ -55,8 +55,7 @@
5656 if( atm.process( token.attribs ) ) {
5757 // Attributes were transformed synchronously
5858 this.manager.env.dp (
59 - 'sync attribs for ' + JSON.stringify( tplExpandData.target ),
60 - tplExpandData.expandedArgs
 59+ 'sync attribs for ' + JSON.stringify( token )
6160 );
6261 // All attributes are fully expanded synchronously (no IO was needed)
6362 return { token: token };
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js
@@ -73,7 +73,10 @@
7474 i = 0,
7575 res;
7676
77 - var attributes = [token.attribs.shift()].concat( this._nameArgs( token.attribs ) );
 77+ var attributes = [token.attribs.shift()];
 78+ if( token.attribs.length ) {
 79+ attributes = attributes.concat( this._nameArgs( token.attribs ) );
 80+ }
7881
7982 this.manager.env.dp( 'before AttributeTransformManager: ' +
8083 JSON.stringify( attributes, null, 2 ) );

Status & tagging log