Pastakhov has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/156072

Change subject: fix highlighting templates and parser functions recussive (v 
1.4.0)
......................................................................

fix highlighting templates and parser functions recussive (v 1.4.0)

* increase font

Change-Id: Ife58eb1d27c7549517c954fb152f3eb37fa6decd
---
M CodeMirror.php
M resources/lib/codemirror/lib/codemirror.css
M resources/mode/mediawiki/mediawiki.js
3 files changed, 109 insertions(+), 96 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/CodeMirror 
refs/changes/72/156072/1

diff --git a/CodeMirror.php b/CodeMirror.php
index aa658b3..fc8dc4b 100644
--- a/CodeMirror.php
+++ b/CodeMirror.php
@@ -15,7 +15,7 @@
        die( 'This file is an extension to MediaWiki and thus not a valid entry 
point.' );
 }
 
-const CODEMIRROR_VERSION = '1.3.0';
+const CODEMIRROR_VERSION = '1.4.0';
 
 // Register this extension on Special:Version
 $wgExtensionCredits['parserhook'][] = array(
diff --git a/resources/lib/codemirror/lib/codemirror.css 
b/resources/lib/codemirror/lib/codemirror.css
index f666acb..eacec55 100644
--- a/resources/lib/codemirror/lib/codemirror.css
+++ b/resources/lib/codemirror/lib/codemirror.css
@@ -5,6 +5,7 @@
   font-family: monospace;
   height: 400px;
   border: 1px solid #CCC;
+  font-size: 1.1em;
 }
 .CodeMirror-scroll {
   /* Set scrolling behaviour here */
diff --git a/resources/mode/mediawiki/mediawiki.js 
b/resources/mode/mediawiki/mediawiki.js
index ce30669..84e7e01 100644
--- a/resources/mode/mediawiki/mediawiki.js
+++ b/resources/mode/mediawiki/mediawiki.js
@@ -11,79 +11,6 @@
 'use strict';
 
 CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
-       function inTemplatePageName( stream, state ) { // {{
-               if ( stream.eat( '#' ) ) {
-                       state.tokenize = inParserFunctionName;
-                       return 'strong';
-               }
-               stream.eatWhile( /[^\|\}\s]/ );
-               state.tokenize = inTemplateArgumentSeparator;
-               return 'link';
-       }
-
-       function inTemplateArgumentSeparator( stream, state ) { // {{ Page name 
|
-               if ( stream.eatSpace() && !stream.eol() ) {
-                       var peek = stream.peek();
-                       if ( peek !== '|' && peek !== '}' ) {
-                               state.tokenize = inTemplatePageName;
-                               return 'link';
-                       }
-               }
-               if ( stream.eat( '|' ) ) {
-                       state.tokenize = inTemplateArgument;
-                       return 'tag strong';
-               }
-               if ( stream.eat( '}' ) ) {
-                       if ( stream.eat( '}' ) ) {
-                               state.tokenize = inWikitext;
-                               return 'tag bracket';
-                       }
-               }
-               if ( stream.eol() ) {
-                       return null;
-               }
-               stream.next();
-               return 'error';
-       }
-
-       function inTemplateArgument( stream, state ) { // {{ Page name |
-               stream.eatWhile( /[^\|}]/ );
-               state.tokenize = inTemplateArgumentSeparator;
-               return 'string';
-       }
-
-       function inParserFunctionName( stream, state ) { // {{#
-               if ( stream.eatWhile( /\w/ ) ) {
-                       if ( stream.peek() === ':' ) {
-                               state.tokenize = 
inParserFunctionArgumentSeparator;
-                               return 'keyword strong';
-                       }
-               }
-               state.tokenize = inWikitext;
-               return 'error';
-       }
-
-       function inParserFunctionArgumentSeparator( stream, state ) { // {{ 
Page name |
-               if ( stream.eat( /[|:]/ ) ) {
-                       state.tokenize = inParserFunctionArgument;
-                       return 'tag strong';
-               }
-               if ( stream.eat( '}' ) ) {
-                       if ( stream.eat( '}' ) ) {
-                               state.tokenize = inWikitext;
-                               return 'tag bracket';
-                       }
-               }
-               stream.next();
-               return 'string';
-       }
-
-       function inParserFunctionArgument( stream, state ) { // {{#
-               stream.eatWhile( /[^|}]/ );
-               state.tokenize = inParserFunctionArgumentSeparator;
-               return 'string';
-       }
-
        function inWikitext( stream, state ) {
                function chain( parser ) {
                        state.tokenize = parser;
@@ -92,26 +19,116 @@
 
                var style = [];
                var sol = stream.sol();
-               var ch = stream.next();
-
-               if ( sol ) {
-                       state.isBold = false;
-                       state.isItalic = false;
+               var blockType = null;
+               if ( state.ImInBlock.length > 0 ) {
+                       blockType = state.ImInBlock[state.ImInBlock.length - 1];
                }
 
-               switch ( ch ) {
-                       case '{':
-                               if ( stream.eat( '{' ) ) { // Templates
-                                       state.tokenize = inTemplatePageName;
+               switch ( blockType ) {
+                       case 'TemplatePageName':
+                               state.ImInBlock.pop();
+                               if ( stream.eat( '#' ) ) {
+                                       state.ImInBlock.push( 
'ParserFunctionName' );
+                                       return 'keyword strong';
+                               } else {
+                                       if ( stream.eatWhile( /[^\{\<\&\s\}\|]/ 
) ) {
+                                               state.ImInBlock.push( 
'TemplatePageNameContinue' );
+                                               return 'link';
+                                       }
+                               }
+                               break;
+                       case 'TemplatePageNameContinue':
+                               stream.eatSpace();
+                               if ( stream.match( /\s*[^\{\<\&\s\}\|]/ ) ) {
+                                       return 'link';
+                               }
+                               if ( stream.eat( '|' ) ) {
+                                       state.ImInBlock.pop();
+                                       state.ImInBlock.push( 
'TemplateArgument' );
                                        stream.eatSpace();
+                                       return 'tag strong';
+                               }
+                               if ( stream.match( /\}\}/ ) ) {
+                                       state.ImInBlock.pop();
                                        return 'tag bracket';
                                }
                                break;
-                       case '\'':
-                               if ( stream.match( '\'\'' ) ) {
-                                       state.isBold = state.isBold ? false : 
true;
-                               } else if ( stream.match( '\'' ) ) {
-                                       state.isItalic = state.isItalic ? false 
: true;
+                       case 'TemplateArgument':
+                               if ( stream.eatWhile( /[^=\{\<\&\}\|]/ ) ) {
+                                       if ( blockType === 'TemplateArgument' 
&& stream.eat('=') ) {
+                                               return 'string strong';
+                                       }
+                                       return 'string';
+                               }
+                               // break is not necessary here
+                       case 'TemplateArgumentContinue':
+                               if ( stream.eatWhile( /[^=\{\<\&\}\|]/ ) ) {
+                                       return 'string';
+                               } else if ( stream.eat( '|' ) ) {
+                                       return 'tag strong';
+                               } else if ( stream.eat( '}' ) ) {
+                                       if ( stream.eat( '}' ) ) {
+                                               state.ImInBlock.pop();
+                                               return 'tag bracket';
+                                       }
+                               }
+                               state.ImInBlock.pop();
+                               state.ImInBlock.push( 
'TemplateArgumentContinue' );
+                               break;
+                       case 'ParserFunctionName':
+                               if ( stream.eatWhile( /\w/ ) ) {
+                                       return 'keyword strong';
+                               }
+                               if ( stream.eat( ':' ) ) {
+                                       state.ImInBlock.pop();
+                                       state.ImInBlock.push( 
'ParserFunctionArgument' );
+                                       return 'keyword strong';
+                               }
+                               break;
+                       case 'ParserFunctionArgument':
+                               if ( stream.eatWhile( /[^\{\<\&\}\|]/ ) ) {
+                                       return 'string-2';
+                               } else if ( stream.eat( '|' ) ) {
+                                       return 'tag strong';
+                               } else if ( stream.eat( '}' ) ) {
+                                       if ( stream.eat( '}' ) ) {
+                                               state.ImInBlock.pop();
+                                               return 'tag bracket';
+                                       }
+                               }
+                               break;
+                       case null:
+                               if ( sol ) {
+                                       state.isBold = false;
+                                       state.isItalic = false;
+//                                     if ( ch === ' ' ) {
+//
+//                                     }
+                               }
+                               if ( stream.peek() === '\'' ) {
+                                       if ( stream.match( '\'\'\'' ) ) {
+                                               state.isBold = state.isBold ? 
false : true;
+                                               return null;
+                                       } else if ( stream.match( '\'\'' ) ) {
+                                               state.isItalic = state.isItalic 
? false : true;
+                                               return null;
+                                       }
+                               }
+                               if ( state.isBold ) {
+                                       style.push( 'strong' );
+                               }
+                               if ( state.isItalic ) {
+                                       style.push( 'em' );
+                               }
+               }
+
+               var ch = stream.next();
+               switch ( ch ) {
+                       case '{':
+                               if ( stream.eat( '{' ) ) { // Templates
+                                       stream.eatSpace();
+                                       state.ImInBlock.push( 
'TemplatePageName' );
+                                       return 'tag bracket';
                                }
                                break;
                        case '<':
@@ -132,17 +149,12 @@
                                        ok = stream.eatWhile( /[\w\.\-:]/ ) && 
stream.eat( ';' );
                                }
                                if ( ok ) {
-                                       style.push( 'atom' );
+                                       return 'atom';
                                }
                                break;
                }
+               stream.eatWhile( /[^\{\<\&\n\']/ );
 
-               if ( state.isBold ) {
-                       style.push( 'strong' );
-               }
-               if ( state.isItalic ) {
-                       style.push( 'em' );
-               }
                if ( style.length > 0 ) {
                        return style.join(' ');
                }
@@ -164,7 +176,7 @@
 
        return {
                startState: function() {
-                       return { tokenize: inWikitext, isBold: false, isItalic: 
false };
+                       return { tokenize: inWikitext, ImInBlock: [], isBold: 
false, isItalic: false };
                },
                token: function( stream, state ) {
                        return state.tokenize( stream, state );

-- 
To view, visit https://gerrit.wikimedia.org/r/156072
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ife58eb1d27c7549517c954fb152f3eb37fa6decd
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/CodeMirror
Gerrit-Branch: master
Gerrit-Owner: Pastakhov <pastak...@yandex.ru>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to