From 77c8f73fecba179664df3af3a396559071f02628 Mon Sep 17 00:00:00 2001 From: Pavel Astakhov Date: Thu, 28 Aug 2014 15:46:50 +0600 Subject: [PATCH] add highlighting template variables (v 1.8.0) Change-Id: I0808c518c553bedf0b8cca8a1502c346292c7b5a --- CodeMirror.php | 2 +- resources/mode/mediawiki/mediawiki.js | 21 ++++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/CodeMirror.php b/CodeMirror.php index 6f440730..45a8077a 100644 --- a/CodeMirror.php +++ b/CodeMirror.php @@ -15,7 +15,7 @@ if ( !defined( 'MEDIAWIKI' ) ) { die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); } -const EXT_CODEMIRROR_VERSION = '1.7.4'; +const EXT_CODEMIRROR_VERSION = '1.8.0'; // Register this extension on Special:Version $wgExtensionCredits['parserhook'][] = array( diff --git a/resources/mode/mediawiki/mediawiki.js b/resources/mode/mediawiki/mediawiki.js index ab4bf043..0b80ac61 100644 --- a/resources/mode/mediawiki/mediawiki.js +++ b/resources/mode/mediawiki/mediawiki.js @@ -155,6 +155,21 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { } style.push( 'string' ); break; + case 'TemplateVariable': + if ( stream.eatWhile( /[^\}\&]/ ) ) { + return 'variable-2'; + } + if ( stream.match( '}}}' ) ) { + state.ImInBlock.pop(); + return 'variable-2'; + } + if ( stream.peek() === '&' ) { + style = ['variable-2']; + } else { + stream.next(); + return 'variable-2'; + } + break; case 'ParserFunctionName': if ( stream.eatWhile( /\w/ ) ) { return 'keyword strong'; @@ -267,7 +282,11 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { state.bTempArgName = false; switch ( ch ) { case '{': - if ( stream.eat( '{' ) ) { // Templates + if ( stream.match( '{{' ) ) { // Variable + stream.eatSpace(); + state.ImInBlock.push( 'TemplateVariable' ); + return 'variable-2'; + } else if ( stream.eat( '{' ) ) { // Templates stream.eatSpace(); state.ImInBlock.push( 'TemplatePageName' ); return 'tag bracket';