diff --git a/resources/mode/mediawiki/mediawiki.css b/resources/mode/mediawiki/mediawiki.css index 49d8016a..fea9d707 100644 --- a/resources/mode/mediawiki/mediawiki.css +++ b/resources/mode/mediawiki/mediawiki.css @@ -8,7 +8,7 @@ .cm-mw-skipformatting { background-color: #adf; } .cm-mw-list { color: #08f; font-weight: bold; } -.cm-mw-signature, .cm-mw-hr { color: #08f; font-weight: bold; background-color: #eee; } +.cm-mw-doubleUnderscore, .cm-mw-signature, .cm-mw-hr { color: #08f; font-weight: bold; background-color: #eee; } .cm-mw-indenting { color: #08f; font-weight: bold; } .cm-mw-mnemonic { color: #290; } .cm-mw-comment { color: #aaa; font-weight: normal; } diff --git a/resources/mode/mediawiki/mediawiki.js b/resources/mode/mediawiki/mediawiki.js index d7b25412..7f1df0f2 100644 --- a/resources/mode/mediawiki/mediawiki.js +++ b/resources/mode/mediawiki/mediawiki.js @@ -807,6 +807,29 @@ return 'mw-signature'; } break; + case '_': // Maybe double undescored Magic Word as __TOC__ + tmp = 1; + while ( stream.eat( '_' ) ) { // Optimize processing of many underscore symbols + tmp++; + } + if ( tmp > 2 ) { // Many underscore symbols + if ( !stream.eol() ) { + stream.backUp( 2 ); // Leave last two underscore symbols for processing again in next iteration + } + return makeStyle( style, state ); // Optimization: skip regex function at the end for EOL and backuped symbols + } else if ( tmp === 2 ) { // Check on double underscore Magic Word + name = stream.match( /([^\s\u00a0>}[\]<{'|&:~]+?)__/ ); // The same as the end of function except '_' inside and with '__' at the end of string + if ( name && name[ 0 ] ) { + if ( '__' + name[ 0 ].toLowerCase() in mwConfig.doubleUnderscore[ 0 ] || '__' + name[ 0 ] in mwConfig.doubleUnderscore[ 1 ] ) { + return 'mw-doubleUnderscore'; + } + if ( !stream.eol() ) { + stream.backUp( 2 ); // Two underscore symbols at the end can be begining of other double undescored Magic Word + } + return makeStyle( style, state ); // Optimization: skip regex function at the end for EOL and backuped symbols + } + } + break; default: if ( /[\s\u00a0]/.test( ch ) ) { stream.eatSpace();