From 675e892f8d634dc7c88e92d31eadbf0fbfe90def Mon Sep 17 00:00:00 2001 From: Pavel Astakhov Date: Thu, 28 Aug 2014 10:20:03 +0600 Subject: [PATCH] fix highlighting mnemonic (v 1.7.3) Change-Id: I10a650b26caf8ce6d2d5d60706d8bd1f5adfd4c4 --- CodeMirror.php | 2 +- resources/mode/mediawiki/mediawiki.js | 65 ++++++++++++++++++--------- 2 files changed, 44 insertions(+), 23 deletions(-) diff --git a/CodeMirror.php b/CodeMirror.php index 81cbd4b4..18c09210 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.2'; +const EXT_CODEMIRROR_VERSION = '1.7.3'; // Register this extension on Special:Version $wgExtensionCredits['parserhook'][] = array( diff --git a/resources/mode/mediawiki/mediawiki.js b/resources/mode/mediawiki/mediawiki.js index a0cdf9fa..052e43d5 100644 --- a/resources/mode/mediawiki/mediawiki.js +++ b/resources/mode/mediawiki/mediawiki.js @@ -22,6 +22,7 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { } var style = []; + var mnemonicStyle = []; // character entity references style var sol = stream.sol(); var blockType = null; if ( state.ImInBlock.length > 0 ) { @@ -33,8 +34,11 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { if ( sol ) { state.ImInBlock.pop(); //FIXME: it is wrong Link return null; - } else if ( stream.eatWhile( /[^#\s\u00a0\|\]]/ ) ) { //FIXME '{{' brokes Link, sample [[z{{page]] + } else if ( stream.eatWhile( /[^#\s\u00a0\|\]\&]/ ) ) { //FIXME '{{' brokes Link, sample [[z{{page]] return 'attribute mw-underline strong'; + } else if ( stream.peek() === '&' ) { // check for character entity references + style = ['attribute', 'mw-underline', 'strong']; + mnemonicStyle = ['mw-underline']; } else if ( stream.eat( '#' ) ) { state.ImInBlock.push( 'LinkToSection' ); return 'attribute strong'; @@ -59,43 +63,55 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { } break; case 'LinkToSection': - state.ImInBlock.pop(); if ( sol ) { + state.ImInBlock.pop(); state.ImInBlock.pop(); //FIXME: it is wrong Link return null; } - stream.eatWhile( /[^\|\]]/ ); //FIXME '{{' brokes Link, sample [[z{{page]] - return 'attribute'; + if ( stream.eatWhile( /[^\|\]\&]/ ) ) { //FIXME '{{' brokes Link, sample [[z{{page]] + mustEat = false; + style = ['attribute']; + } else if ( stream.peek() === '&' ) { + style = ['attribute']; + } else { + state.ImInBlock.pop(); + return 'attribute'; + } + break; case 'LinkText': stream.eatSpace(); if ( stream.match( /[\s\u00a0]*\]\]/ ) ) { state.ImInBlock.pop(); - if ( !stream.eatSpace() ) { - state.ImInBlock.push( 'LinkTrail' ); - } +// if ( !stream.eatSpace() ) { +// state.ImInBlock.push( 'LinkTrail' ); +// } return 'tag bracket'; } - mustEat = false; - stream.eatWhile( /[^\]\s\u00a0]/ ); - style.push( 'mw-underline' ); - break; - case 'LinkTrail': // FIXME with Language::linkTrail() - state.ImInBlock.pop(); - if ( !stream.sol && stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\']/ ) ) { // & + + if ( stream.eatWhile( /[^\]\s\u00a0\&]/ ) ) { mustEat = false; - style.push( 'mw-underline' ); + style = ['mw-underline']; + } else if ( stream.peek() === '&' ) { + style = ['mw-underline']; + mnemonicStyle = ['mw-underline']; } break; +// case 'LinkTrail': // FIXME with Language::linkTrail() +// state.ImInBlock.pop(); +// if ( sol !== true && stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\']/ ) ) { // & +// mustEat = false; +// style.push( 'mw-underline' ); +// } +// break; case 'TemplatePageName': state.ImInBlock.pop(); if ( stream.eat( '#' ) ) { state.ImInBlock.push( 'ParserFunctionName' ); return 'keyword strong'; - } else { - if ( stream.eatWhile( /[^\s\u00a0\}\|<\{\&]/ ) ) { - state.ImInBlock.push( 'TemplatePageNameContinue' ); - return 'attribute mw-underline'; - } + } + if ( stream.eatWhile( /[^\s\u00a0\}\|<\{\&]/ ) ) { + state.ImInBlock.push( 'TemplatePageNameContinue' ); + return 'attribute mw-underline'; } break; case 'TemplatePageNameContinue': @@ -114,6 +130,10 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { state.ImInBlock.pop(); return 'tag bracket'; } + if ( stream.peek() === '&' ) { + style = ['attribute', 'mw-underline']; + mnemonicStyle = ['mw-underline']; + } break; case 'TemplateArgument': if ( state.bTempArgName && stream.eatWhile( /[^=\}\|<\{\&]/ ) ) { @@ -242,7 +262,8 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { ok = stream.eatWhile( /[\w\.\-:]/ ) && stream.eat( ';' ); } if ( ok ) { - return 'atom'; + mnemonicStyle.push( 'atom' ); + return mnemonicStyle.join(' '); } } else if ( state.allowWikimarkup ) { state.bTempArgName = false; @@ -282,7 +303,7 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) { } break; } - stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\'\&]/ ); + stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\'\|\&]/ ); if ( state.isBold ) { style.push( 'strong' ); }