mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/VisualEditor
synced 2024-11-15 10:35:48 +00:00
Convert external link syntax stops to stack
Eat unbalanced external link parts within template parameters. This does not produce the same output as the PHP parser (try echo '{{YouTube}}' | node parse.js), but preserves a level of sanity. Need to check how common this is for external links. If it is rare enough, moving the ']' after the parser function manually would fix the rendering for the YouTube case. Change-Id: I597d808efff36baa22191e7946a0061cc31120e8
This commit is contained in:
parent
1fa462ce92
commit
df050e4481
|
@ -139,7 +139,7 @@ PegTokenizer.prototype.inline_breaks = function (input, pos, stops ) {
|
||||||
return counters.template && input[pos + 1] === "}" || null;
|
return counters.template && input[pos + 1] === "}" || null;
|
||||||
case ":":
|
case ":":
|
||||||
return counters.colon &&
|
return counters.colon &&
|
||||||
! counters.extlink &&
|
! stops.onStack( 'extlink' ) &&
|
||||||
! counters.linkdesc || null;
|
! counters.linkdesc || null;
|
||||||
case "\r":
|
case "\r":
|
||||||
return stops.onStack( 'table' ) &&
|
return stops.onStack( 'table' ) &&
|
||||||
|
@ -151,7 +151,7 @@ PegTokenizer.prototype.inline_breaks = function (input, pos, stops ) {
|
||||||
input[pos + 1] === '|' ||
|
input[pos + 1] === '|' ||
|
||||||
null;
|
null;
|
||||||
case "]":
|
case "]":
|
||||||
return counters.extlink ||
|
return stops.onStack( 'extlink' ) ||
|
||||||
( counters.linkdesc && input[pos + 1] === ']' ) ||
|
( counters.linkdesc && input[pos + 1] === ']' ) ||
|
||||||
null;
|
null;
|
||||||
case "<":
|
case "<":
|
||||||
|
|
|
@ -667,7 +667,7 @@ behavior_switch
|
||||||
**************************************************************/
|
**************************************************************/
|
||||||
|
|
||||||
autolink
|
autolink
|
||||||
= ! { return stops.onCount('extlink') }
|
= ! { return stops.onStack('extlink') }
|
||||||
(urllink / autoref / isbn)
|
(urllink / autoref / isbn)
|
||||||
|
|
||||||
urllink
|
urllink
|
||||||
|
@ -676,16 +676,16 @@ urllink
|
||||||
}
|
}
|
||||||
|
|
||||||
extlink
|
extlink
|
||||||
= ! { return stops.onCount('extlink') } // extlink cannot be nested
|
= ! { return stops.onStack('extlink') } // extlink cannot be nested
|
||||||
(
|
(
|
||||||
"["
|
"["
|
||||||
& { return stops.inc('extlink'); }
|
& { return stops.push('extlink', true); }
|
||||||
//target:urllink
|
//target:urllink
|
||||||
target:extlink_preprocessor_text
|
target:extlink_preprocessor_text
|
||||||
text:(( space / [\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] )*
|
text:(( space / [\u00A0\u1680\u180E\u2000-\u200A\u202F\u205F\u3000] )*
|
||||||
t:inlineline { return t } )?
|
t:inlineline { return t } )?
|
||||||
"]" {
|
"]" {
|
||||||
stops.dec('extlink');
|
stops.pop('extlink');
|
||||||
if ( text === '' ) {
|
if ( text === '' ) {
|
||||||
// XXX: Link numbering should be implemented in post-processor.
|
// XXX: Link numbering should be implemented in post-processor.
|
||||||
text = [ "[" + linkCount + "]" ];
|
text = [ "[" + linkCount + "]" ];
|
||||||
|
@ -699,7 +699,7 @@ extlink
|
||||||
] )
|
] )
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
/ "[" & { stops.dec('extlink'); return false; }
|
/ "[" & { return stops.pop('extlink'); }
|
||||||
)
|
)
|
||||||
|
|
||||||
autoref
|
autoref
|
||||||
|
@ -939,10 +939,12 @@ template_param_text
|
||||||
input.substr( pos +1, 9) ); */
|
input.substr( pos +1, 9) ); */
|
||||||
// re-enable tables within template parameters
|
// re-enable tables within template parameters
|
||||||
stops.push('table', false );
|
stops.push('table', false );
|
||||||
|
stops.push('extlink', false);
|
||||||
return stops.inc('template')
|
return stops.inc('template')
|
||||||
}
|
}
|
||||||
il:nested_block+ {
|
il:nested_block+ {
|
||||||
stops.pop('table');
|
stops.pop('table');
|
||||||
|
stops.pop('extlink');
|
||||||
stops.dec('template');
|
stops.dec('template');
|
||||||
//console.warn( 'tpt match: ' + pp (il) + " stops: " + pp(stops));
|
//console.warn( 'tpt match: ' + pp (il) + " stops: " + pp(stops));
|
||||||
var r = flatten( il ),
|
var r = flatten( il ),
|
||||||
|
@ -962,7 +964,7 @@ template_param_text
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
/ & { stops.pop('table'); return stops.dec('template'); }
|
/ & { stops.pop('table'); stops.pop('extlink'); return stops.dec('template'); }
|
||||||
|
|
||||||
|
|
||||||
// TODO: handle link prefixes as in al[[Razi]]
|
// TODO: handle link prefixes as in al[[Razi]]
|
||||||
|
|
Loading…
Reference in a new issue