Index: trunk/extensions/VisualEditor/modules/parser/ext.core.ParserFunctions.js |
— | — | @@ -44,7 +44,7 @@ |
45 | 45 | |
46 | 46 | // #ifeq |
47 | 47 | ParserFunctions.prototype['pf_#ifeq'] = function ( target, argList, argDict ) { |
48 | | - if ( ! argList.length ) { |
| 48 | + if ( argList.length < 2 ) { |
49 | 49 | return []; |
50 | 50 | } else { |
51 | 51 | if ( target.trim() === this.manager.env.tokensToString( argList[0][1] ).trim() ) { |
— | — | @@ -80,7 +80,9 @@ |
81 | 81 | }; |
82 | 82 | |
83 | 83 | ParserFunctions.prototype['pf_#tag'] = function ( target, argList, argDict ) { |
84 | | - return [new TagTk(target, argList)]; |
| 84 | + return [ new TagTk( target ), |
| 85 | + argList[0].v, |
| 86 | + new EndTagTk( target ) ]; |
85 | 87 | }; |
86 | 88 | |
87 | 89 | // A first approximation, anyway.. |
Index: trunk/extensions/VisualEditor/modules/parser/pegTokenizer.pegjs.txt |
— | — | @@ -29,6 +29,36 @@ |
30 | 30 | return es; |
31 | 31 | }; |
32 | 32 | |
| 33 | + |
| 34 | + var flatten_string = function ( c ) { |
| 35 | + var out = [], |
| 36 | + text = []; |
| 37 | + c = flatten(c); |
| 38 | + for (var i = 0, l = c.length; i < l; i++) { |
| 39 | + var ci = c[i]; |
| 40 | + if (ci.constructor === String) { |
| 41 | + if(ci !== '') { |
| 42 | + text.push(ci); |
| 43 | + } |
| 44 | + } else { |
| 45 | + if (text.length) { |
| 46 | + out.push( text.join('') ); |
| 47 | + text = []; |
| 48 | + } |
| 49 | + out.push(ci); |
| 50 | + } |
| 51 | + } |
| 52 | + if (text.length) { |
| 53 | + out.push( text.join('') ); |
| 54 | + } |
| 55 | + |
| 56 | + if ( out.length === 1 && out[0].constructor === String ) { |
| 57 | + return out[0]; |
| 58 | + } else { |
| 59 | + return out; |
| 60 | + } |
| 61 | + }; |
| 62 | + |
33 | 63 | // Remove escaped quotes from attributes etc |
34 | 64 | // This was in the original PEG parser, but could not find anything in |
35 | 65 | // MediaWiki that supports \' and \"-style escaping. So remove? -- gwicke |
— | — | @@ -308,6 +338,40 @@ |
309 | 339 | / ' ' & ':' { return "\u00a0"; } |
310 | 340 | / t:text_char )+ |
311 | 341 | |
| 342 | +directive |
| 343 | + = comment |
| 344 | + / tplarg_or_template |
| 345 | + / htmlentity |
| 346 | + |
| 347 | +spaceless_preprocessor_text |
| 348 | + = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); } |
| 349 | + / directive |
| 350 | + / !inline_breaks !' ' text_char )+ { |
| 351 | + return flatten_string ( r ); |
| 352 | + } |
| 353 | + |
| 354 | +link_preprocessor_text |
| 355 | + = r:( t:[^'<~[{\n\r|!\]}\t &=]+ { return t.join(''); } |
| 356 | + / directive |
| 357 | + / !inline_breaks no_punctuation_char |
| 358 | + / s:[.:,] !(space / eolf) { return s } |
| 359 | + / urlencoded_char |
| 360 | + / [&%] )+ { |
| 361 | + return flatten_string ( r ); |
| 362 | + } |
| 363 | + |
| 364 | +// Plain text, but can contain templates, template arguments, comments etc- |
| 365 | +// all stuff that is normally handled by the preprocessor |
| 366 | +// Returns either a list of tokens, or a plain string (if nothing is to be |
| 367 | +// processed). |
| 368 | +preprocessor_text |
| 369 | + = r:( t:[^'<~[{\n\r\t|!\]} &=]+ { return t.join(''); } |
| 370 | + / directive |
| 371 | + / !inline_breaks text_char )+ { |
| 372 | + return flatten_string ( r ); |
| 373 | + } |
| 374 | + |
| 375 | + |
312 | 376 | /* |
313 | 377 | '//', // for protocol-relative URLs, but not in text! |
314 | 378 | 'ftp://', |
— | — | @@ -553,6 +617,7 @@ |
554 | 618 | = //& { dp('inline_element enter' + input.substr(pos, 10)); return true; } |
555 | 619 | & '<' ( comment / xmlish_tag ) |
556 | 620 | / & '{' ( & '{{{{{' template / tplarg / template ) |
| 621 | + / & '{' tplarg_or_template |
557 | 622 | /// & '{' ( tplarg / template ) |
558 | 623 | // Eat three opening brackets as text. |
559 | 624 | / '[[[' { return '[[[' } |
— | — | @@ -632,9 +697,9 @@ |
633 | 698 | extlink |
634 | 699 | = "[" |
635 | 700 | & { return setFlag('extlink'); } |
636 | | - target:(url / tplarg / template) |
637 | | - space* |
638 | | - text:inlineline? |
| 701 | + //target:urllink |
| 702 | + target:link_preprocessor_text |
| 703 | + text:(space* t:inlineline { return t } )? |
639 | 704 | "]" { |
640 | 705 | clearFlag('extlink'); |
641 | 706 | if ( text == '' ) { |
— | — | @@ -642,13 +707,15 @@ |
643 | 708 | text = [ "[" + linkCount + "]" ]; |
644 | 709 | linkCount++; |
645 | 710 | } |
646 | | - return [ |
| 711 | + var res = [ |
647 | 712 | new TagTk( 'a', [ |
648 | 713 | new KV('href', target), |
649 | 714 | new KV('data-type', 'external') |
650 | 715 | ] ), |
651 | 716 | ].concat( text |
652 | 717 | , [ new EndTagTk( 'a' )]); |
| 718 | + //console.log( JSON.stringify( res, null, 2 ) ); |
| 719 | + return res; |
653 | 720 | } |
654 | 721 | / "[" & { clearFlag('extlink'); return false; } |
655 | 722 | |
— | — | @@ -713,6 +780,8 @@ |
714 | 781 | return flatten( a ).join(''); |
715 | 782 | } |
716 | 783 | |
| 784 | +tplarg_or_template = & '{{{{{' template / tplarg / template |
| 785 | + |
717 | 786 | template |
718 | 787 | = "{{" target:template_param_text |
719 | 788 | params:(newline? "|" newline? p:template_param { return p })* |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.js |
— | — | @@ -77,7 +77,7 @@ |
78 | 78 | // Add token transformations.. |
79 | 79 | new QuoteTransformer( this.tokenPostProcessor ); |
80 | 80 | new PostExpandParagraphHandler( this.tokenPostProcessor ); |
81 | | - new Sanitizer( this.tokenPostProcessor ); |
| 81 | + //new Sanitizer( this.tokenPostProcessor ); |
82 | 82 | |
83 | 83 | //var citeExtension = new Cite( this.tokenTransformer ); |
84 | 84 | |
Index: trunk/extensions/VisualEditor/modules/parser/ext.core.TemplateHandler.js |
— | — | @@ -168,7 +168,9 @@ |
169 | 169 | var prefix = target.split(':', 1)[0].toLowerCase().trim(); |
170 | 170 | if ( prefix && 'pf_' + prefix in this.parserFunctions ) { |
171 | 171 | var funcArg = target.substr( prefix.length + 1 ); |
172 | | - this.manager.env.tp( 'func prefix: ' + prefix + ' arg=' + funcArg ); |
| 172 | + this.manager.env.tp( 'func prefix: ' + prefix + |
| 173 | + ' args=' + JSON.stringify( tplExpandData.expandedArgs, null, 2) + |
| 174 | + ' funcArg=' + funcArg); |
173 | 175 | //this.manager.env.dp( 'entering prefix', funcArg, args ); |
174 | 176 | res = this.parserFunctions[ 'pf_' + prefix ]( funcArg, |
175 | 177 | tplExpandData.expandedArgs, args ); |
Index: trunk/extensions/VisualEditor/modules/parser/mediawiki.parser.environment.js |
— | — | @@ -116,10 +116,11 @@ |
117 | 117 | } |
118 | 118 | for ( var i = 0, l = tokens.length; i < l; i++ ) { |
119 | 119 | var token = tokens[i]; |
120 | | - if ( ! token ) { |
| 120 | + if ( token === undefined ) { |
121 | 121 | console.trace(); |
122 | | - this.dp( 'MWParserEnvironment.tokensToString, invalid token: ' + |
123 | | - JSON.stringify( token ) ); |
| 122 | + this.tp( 'MWParserEnvironment.tokensToString, invalid token: ' + |
| 123 | + JSON.stringify( token ) + |
| 124 | + ' tokens:' + JSON.stringify( tokens, null, 2 )); |
124 | 125 | continue; |
125 | 126 | } |
126 | 127 | if ( token.constructor === String ) { |