mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-12-18 00:30:30 +00:00
Much more robust detection of template {{{variables}}}
Variables like {{{foo}}} with 3 brackets typically only appear in templates. But odd combinations of other features that also start with 3 brackets are much more common. These should not be detected as variables. 1. When something starts with 4 or more brackets it's not a variable but something else. E.g. the start of a template where the template name is a variable (2 + 3 = 5 brackets). 2. Tables can start with {{{!}}. Note this doesn't fully solve T292967 but already improves the situation a lot. Bug: T108450 Bug: T292967 Change-Id: Id5e50c2bafb35a211d4b63609126c40b32f06a64
This commit is contained in:
parent
8274034243
commit
aa391c1c77
|
@ -744,7 +744,9 @@
|
|||
}
|
||||
break;
|
||||
case '{':
|
||||
if ( !stream.match( '{{{{', false ) && stream.match( '{{' ) ) { // Template parameter (skip parameters inside a template transclusion, Bug: T108450)
|
||||
// Can't be a variable when it starts with more than 3 brackets (T108450) or
|
||||
// a single { followed by a template. E.g. {{{!}} starts a table (T292967).
|
||||
if ( stream.match( /^{{(?!{|[^{}]*}}(?!}))/ ) ) {
|
||||
stream.eatSpace();
|
||||
state.stack.push( state.tokenize );
|
||||
state.tokenize = inVariable;
|
||||
|
|
|
@ -83,7 +83,7 @@
|
|||
{
|
||||
title: 'T292967: table syntax where all | are escaped with the {{!}} parser function',
|
||||
input: '{{{!}}\n{{!}}-\n{{!}}}',
|
||||
output: '<pre><span><span class="cm-mw-templatevariable-bracket">{{{</span><span class="cm-mw-templatevariable-name">!}}</span></span></pre><pre><span><span class="cm-mw-templatevariable-name">{{!}}-</span></span></pre><pre><span><span class="cm-mw-templatevariable-name">{{!</span><span class="cm-mw-templatevariable-bracket">}}}</span></span></pre>'
|
||||
output: '<pre><span><span class="cm-mw-template-ground cm-mw-template-bracket">{{</span><span class="cm-mw-template-ground cm-mw-template-name cm-mw-pagename">{!</span><span class="cm-mw-template-ground cm-mw-template-bracket">}}</span></span></pre><pre><span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span>-</span></pre><pre><span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">{{</span><span class="cm-mw-ext-ground cm-mw-parserfunction-name">!</span><span class="cm-mw-ext-ground cm-mw-parserfunction-bracket">}}</span>}</span></pre>'
|
||||
},
|
||||
{
|
||||
title: 'section headings',
|
||||
|
|
Loading…
Reference in a new issue