Temporary fix for template tokenization, especially needed for

[[Template:Cite core]].
This commit is contained in:
Gabriel Wicke 2012-03-08 14:24:04 +00:00
parent 62e8312535
commit ffc9383096
Notes: Gabriel Wicke 2012-03-08 14:24:04 +00:00
3 changed files with 19 additions and 10 deletions

View file

@ -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('') );

View file

@ -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;

View file

@ -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