From 30a3ae431930daf1958213daec0132c797d70014 Mon Sep 17 00:00:00 2001 From: Pavel Astakhov Date: Thu, 4 Sep 2014 10:23:05 +0600 Subject: [PATCH] add highlighting double underscore Magic words (v 1.12.0) Change-Id: I4eceaa790ca053de49f5d0983bdd8ae288ba985f --- CodeMirror.hooks.php | 13 +++++++++++++ CodeMirror.php | 2 +- resources/ext.CodeMirror.js | 1 + resources/mode/mediawiki/mediawiki.js | 11 ++++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/CodeMirror.hooks.php b/CodeMirror.hooks.php index e324bad2..c1eb67a6 100644 --- a/CodeMirror.hooks.php +++ b/CodeMirror.hooks.php @@ -22,6 +22,18 @@ class CodeMirrorHooks { self::$globalVariableScript['Tags'] = $wgParser->getTags(); $mw = $wgContLang->getMagicWords(); + self::$globalVariableScript['DoubleUnderscore'] = array( array(), array() ); + foreach ( MagicWord::getDoubleUnderscoreArray()->names as $name ) { + if ( isset( $mw[$name] ) ) { + $caseSensitive = array_shift( $mw[$name] ) == 0 ? 0 : 1; + foreach ( $mw[$name] as $n ) { + self::$globalVariableScript['DoubleUnderscore'][$caseSensitive][ $caseSensitive ? $n : $wgContLang->lc( $n ) ] = $name; + } + } else { + self::$globalVariableScript['DoubleUnderscore'][0][] = $name; + } + } + self::$globalVariableScript['FunctionSynonyms'] = $wgParser->mFunctionSynonyms; foreach ( MagicWord::getVariableIDs() as $name ) { if ( isset( $mw[$name] ) ) { @@ -32,6 +44,7 @@ class CodeMirrorHooks { } } +// self::$globalVariableScript['LinkTrailCharacters'] = $wgContLang->linkTrail(); $output->addModules( 'ext.CodeMirror' ); return true; } diff --git a/CodeMirror.php b/CodeMirror.php index 0550b606..79459239 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.11.2'; +const EXT_CODEMIRROR_VERSION = '1.12.0'; // Register this extension on Special:Version $wgExtensionCredits['parserhook'][] = array( diff --git a/resources/ext.CodeMirror.js b/resources/ext.CodeMirror.js index ef3e6386..80a4a382 100644 --- a/resources/ext.CodeMirror.js +++ b/resources/ext.CodeMirror.js @@ -4,6 +4,7 @@ jQuery( document ).ready( function ( $ ) { var codeMirror = CodeMirror.fromTextArea( textbox1[0], { mwextFunctionSynonyms: mw.config.get( 'extCodeMirrorFunctionSynonyms' ), mwextTags: mw.config.get( 'extCodeMirrorTags' ), + mwextDoubleUnderscore: mw.config.get( 'extCodeMirrorDoubleUnderscore' ), styleActiveLine: true, //lineNumbers: true, lineWrapping: true, diff --git a/resources/mode/mediawiki/mediawiki.js b/resources/mode/mediawiki/mediawiki.js index 385d871f..20b5d731 100644 --- a/resources/mode/mediawiki/mediawiki.js +++ b/resources/mode/mediawiki/mediawiki.js @@ -361,8 +361,17 @@ CodeMirror.defineMode('mediawiki', function( config/*, parserConfig */ ) { } } break; + case '_': + name = stream.match( /_[^\s\u00a0_>\}\[\]<\{\'\|\&\:]*__/ ); + if ( name ) { + name = '_' + name[0]; + if ( config.mwextDoubleUnderscore[0][name.toLowerCase()] || config.mwextDoubleUnderscore[1][name] ) { + return 'keyword strong'; + } + } + break; } - stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\'\|\&\:]/ ); + stream.eatWhile( /[^\s\u00a0_>\}\[\]<\{\'\|\&\:]/ ); if ( state.isBold ) { style.push( 'strong' ); }