Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.TokenTransformManager.js |
— | — | @@ -766,6 +766,12 @@ |
767 | 767 | this.kvs.push( kv ); |
768 | 768 | var cur = attributes[i]; |
769 | 769 | |
| 770 | + if ( ! cur ) { |
| 771 | + console.log( JSON.stringify( attributes ) ); |
| 772 | + console.trace(); |
| 773 | + continue; |
| 774 | + } |
| 775 | + |
770 | 776 | if ( cur.k.constructor !== String ) { |
771 | 777 | // Assume that the return is async, will be decremented in callback |
772 | 778 | this.outstanding++; |
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -360,6 +360,27 @@ |
361 | 361 | return flatten_string ( r ); |
362 | 362 | } |
363 | 363 | |
| 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 | + |
364 | 385 | // Plain text, but can contain templates, template arguments, comments etc- |
365 | 386 | // all stuff that is normally handled by the preprocessor |
366 | 387 | // Returns either a list of tokens, or a plain string (if nothing is to be |
— | — | @@ -875,9 +896,11 @@ |
876 | 897 | } |
877 | 898 | } else { |
878 | 899 | if (trail) { |
879 | | - target = target.concat( [ trail.join('') ] ); |
| 900 | + textTokens = target.concat( [ trail.join('') ] ); |
| 901 | + } else { |
| 902 | + // copy list |
| 903 | + textTokens = target.concat([]); |
880 | 904 | } |
881 | | - textTokens = target; |
882 | 905 | } |
883 | 906 | //console.log( "XXX:" + pp(obj) ); |
884 | 907 | return [obj].concat(textTokens, [new EndTagTk( 'a' )]); |
— | — | @@ -1008,8 +1031,8 @@ |
1009 | 1032 | = "<" |
1010 | 1033 | & { tagStartPos = pos; return true; } // remember the start position of this tag |
1011 | 1034 | end:"/"? name:[0-9a-zA-Z]+ |
1012 | | - attribs:generic_attribute* |
1013 | | - space* |
| 1035 | + attribs:generic_newline_attribute* |
| 1036 | + ( space / newline ) * |
1014 | 1037 | selfclose:"/"? |
1015 | 1038 | ">" { |
1016 | 1039 | name = name.join(''); |
— | — | @@ -1025,6 +1048,19 @@ |
1026 | 1049 | return res; |
1027 | 1050 | } |
1028 | 1051 | |
| 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 | + |
1029 | 1065 | generic_attribute |
1030 | 1066 | = s:space* |
1031 | 1067 | name:generic_attribute_name |
— | — | @@ -1045,21 +1081,30 @@ |
1046 | 1082 | return n.join(''); |
1047 | 1083 | } |
1048 | 1084 | |
| 1085 | +generic_attribute_newline_value |
| 1086 | + = "=" (space / newline )* v:xml_att_value { |
| 1087 | + return v; |
| 1088 | + } |
1049 | 1089 | generic_attribute_value |
1050 | 1090 | = "=" space* v:att_value { |
1051 | 1091 | return v; |
1052 | 1092 | } |
1053 | 1093 | |
1054 | 1094 | // 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!! |
1055 | 1101 | att_value |
1056 | 1102 | = t:(!inline_breaks c:[^ \t'"<>='\n] { return c } )+ { |
1057 | 1103 | return t.join(''); |
1058 | 1104 | } |
1059 | | - // XXX: is "\"" also valid html? or just Wikitext? |
| 1105 | + // XXX: is "\"" also valid html? or just Wikitext? |
1060 | 1106 | / "'" t:[^'>]* "'" { return unquote("'", t.join('')); } |
1061 | 1107 | / '"' t:[^">]* '"' { return unquote('"', t.join('')); } |
1062 | 1108 | |
1063 | | - |
1064 | 1109 | /* Lists */ |
1065 | 1110 | lists = e:(dtdd / li) es:(sol (dtdd / li))* |
1066 | 1111 | { |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.AttributeExpander.js |
— | — | @@ -43,7 +43,7 @@ |
44 | 44 | * processes the template. |
45 | 45 | */ |
46 | 46 | AttributeExpander.prototype.onToken = function ( token, frame, cb ) { |
47 | | - if ( token.constructor === TagTk && token.attributes ) { |
| 47 | + if ( token.constructor === TagTk && token.attribs && token.attribs.length ) { |
48 | 48 | var expandData = { |
49 | 49 | token: token, |
50 | 50 | cb: cb |
— | — | @@ -55,8 +55,7 @@ |
56 | 56 | if( atm.process( token.attribs ) ) { |
57 | 57 | // Attributes were transformed synchronously |
58 | 58 | this.manager.env.dp ( |
59 | | - 'sync attribs for ' + JSON.stringify( tplExpandData.target ), |
60 | | - tplExpandData.expandedArgs |
| 59 | + 'sync attribs for ' + JSON.stringify( token ) |
61 | 60 | ); |
62 | 61 | // All attributes are fully expanded synchronously (no IO was needed) |
63 | 62 | return { token: token }; |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -73,7 +73,10 @@ |
74 | 74 | i = 0, |
75 | 75 | res; |
76 | 76 | |
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 | + } |
78 | 81 | |
79 | 82 | this.manager.env.dp( 'before AttributeTransformManager: ' + |
80 | 83 | JSON.stringify( attributes, null, 2 ) ); |