diff --git a/modules/parser/mediawiki.parser.environment.js b/modules/parser/mediawiki.parser.environment.js index 6ca76323e7..b8076ad4d8 100644 --- a/modules/parser/mediawiki.parser.environment.js +++ b/modules/parser/mediawiki.parser.environment.js @@ -244,7 +244,7 @@ MWParserEnvironment.prototype.tokensToString = function ( tokens, strict ) { this.dp ( 'MWParserEnvironment.tokensToString, non-text token: ' + tstring + JSON.stringify( tokens, null, 2 ) ); //console.trace(); - out.push( tstring ); + //out.push( tstring ); } } //console.warn( 'MWParserEnvironment.tokensToString result: ' + out.join('') ); diff --git a/modules/parser/mediawiki.tokenizer.peg.js b/modules/parser/mediawiki.tokenizer.peg.js index 611bd3f582..e30f057e00 100644 --- a/modules/parser/mediawiki.tokenizer.peg.js +++ b/modules/parser/mediawiki.tokenizer.peg.js @@ -106,7 +106,10 @@ PegTokenizer.prototype.tokenizeURL = function( text ) { PegTokenizer.prototype.inline_breaks = function (input, pos, syntaxFlags ) { switch( input[pos] ) { case '=': - return syntaxFlags.equal || + return ( syntaxFlags.equalAttrib && + (syntaxFlags.equalTemplate || ! syntaxFlags.template ) ) || + (syntaxFlags.equalTemplate && + (syntaxFlags.equalAttrib || syntaxFlags.template)) || ( syntaxFlags.h && input.substr( pos + 1, 200) .match(/[ \t]*[\r\n]/) !== null ) || null; diff --git a/modules/parser/pegTokenizer.pegjs.txt b/modules/parser/pegTokenizer.pegjs.txt index d8e2f7c480..6452e1bf47 100644 --- a/modules/parser/pegTokenizer.pegjs.txt +++ b/modules/parser/pegTokenizer.pegjs.txt @@ -669,8 +669,12 @@ ipv6_address tplarg_or_template = & '{{{{{' template / tplarg / template template - = "{{" target:template_param_text - params:(newline? "|" newline? p:template_param { return p })* + = "{{" (newline / space)* target:template_param_text + params:(( newline / space )* "|" + r:( &"|" { return new KV( '', '') } // empty argument + / newline? p:template_param { return p } + ) { return r } + )* "}}" { // Insert target as first positional attribute, so that it can be // generically expanded. The TemplateHandler then needs to shift it out @@ -720,15 +724,15 @@ template_param // FIXME: handle template args and templates in key! (or even parser functions?) template_param_name - = & { return setFlag( 'equal' ) } + = & { return setFlag( 'equalTemplate' ) } tpt:template_param_text { - clearFlag( 'equal' ); + clearFlag( 'equalTemplate' ); //console.warn( 'template param name matched: ' + pp( tpt ) ); return tpt; } - / & { return clearFlag( 'equal' ) } + / & { return clearFlag( 'equalTemplate' ) } //= h:( !"}}" x:([^=|\n]) { return x } )* { return h.join(''); } template_param_text @@ -740,6 +744,7 @@ template_param_text } / & { return clearFlag('template'); } + // TODO: handle link prefixes as in al[[Razi]] wikilink = & { return posStack.push('wikilink' , pos); } @@ -1101,6 +1106,7 @@ generic_newline_attribute value:(( space / newline )* v:generic_attribute_newline_value { return v })? { + //console.warn('generic_newline_attribute: ' + pp( name )) if ( value !== '' ) { return new KV( name, value ); } else { @@ -1134,15 +1140,15 @@ generic_attribute // } generic_attribute_name - = & { return setFlag( 'equal' ) } + = & { return setFlag( 'equalAttrib' ) } ! '/>' name:attribute_preprocessor_text_line { - clearFlag( 'equal' ); + clearFlag( 'equalAttrib' ); //console.warn( 'generic attribute name: ' + pp( name ) ); return name; } - / & { return clearFlag( 'equal' ) } + / & { return clearFlag( 'equalAttrib' ) } // A generic attribute, possibly spanning multiple lines. generic_attribute_newline_value