add highlighting of indented tables (v 3.1.8)

Bug: T108454
Change-Id: Ib5344fa870954da166314c8ace916861bd71acf9
This commit is contained in:
Pavel Astakhov 2015-08-10 13:48:48 +06:00
parent 27a7499906
commit 545d21ce61
2 changed files with 28 additions and 5 deletions

View file

@ -15,7 +15,7 @@ if ( !defined( 'MEDIAWIKI' ) ) {
die( 'This file is an extension to MediaWiki and thus not a valid entry point.' ); die( 'This file is an extension to MediaWiki and thus not a valid entry point.' );
} }
const EXT_CODEMIRROR_VERSION = '3.1.7'; const EXT_CODEMIRROR_VERSION = '3.1.8';
// Register this extension on Special:Version // Register this extension on Special:Version
$wgExtensionCredits['parserhook'][] = array( $wgExtensionCredits['parserhook'][] = array(

View file

@ -502,6 +502,13 @@ CodeMirror.defineMode( 'mediawiki', function( config/*, parserConfig */ ) {
}; };
} }
function eatStartTable( stream, state ) {
stream.match( '{|' );
stream.eatSpace();
state.tokenize = inTableDefinition;
return 'mw-table-bracket';
}
function inTableDefinition( stream, state ) { function inTableDefinition( stream, state ) {
if ( stream.sol() ) { if ( stream.sol() ) {
state.tokenize = inTable; state.tokenize = inTable;
@ -516,7 +523,7 @@ CodeMirror.defineMode( 'mediawiki', function( config/*, parserConfig */ ) {
state.isItalic = false; state.isItalic = false;
if ( stream.match( /[\s\u00a0]*[\|!]/, false ) ) { if ( stream.match( /[\s\u00a0]*[\|!]/, false ) ) {
state.tokenize = inTable; state.tokenize = inTable;
return state.tokenize( stream, state ); return inTable( stream, state );
} }
} }
return eatWikiText( 'mw-table-caption', '' )( stream, state ); return eatWikiText( 'mw-table-caption', '' )( stream, state );
@ -560,7 +567,7 @@ CodeMirror.defineMode( 'mediawiki', function( config/*, parserConfig */ ) {
state.isItalic = false; state.isItalic = false;
if ( stream.match( /[\s\u00a0]*[\|!]/, false ) ) { if ( stream.match( /[\s\u00a0]*[\|!]/, false ) ) {
state.tokenize = inTable; state.tokenize = inTable;
return state.tokenize( stream, state ); return inTable( stream, state );
} }
} else { } else {
if ( stream.match( /[^'\|\{\[<\&~]+/ ) ) { if ( stream.match( /[^'\|\{\[<\&~]+/ ) ) {
@ -593,8 +600,6 @@ CodeMirror.defineMode( 'mediawiki', function( config/*, parserConfig */ ) {
state.isBold = false; state.isBold = false;
state.isItalic = false; state.isItalic = false;
switch ( ch ) { switch ( ch ) {
case ' ':
return 'mw-skipformatting';
case '-': case '-':
if ( stream.match( '---' ) ) { if ( stream.match( '---' ) ) {
return 'mw-hr'; return 'mw-hr';
@ -616,10 +621,28 @@ CodeMirror.defineMode( 'mediawiki', function( config/*, parserConfig */ ) {
} }
break; break;
case ':': case ':':
if ( stream.match( /:*{\|/, false ) ) { // Highlight indented tables :{|, bug T108454
state.stack.push( state.tokenize );
state.tokenize = eatStartTable;
}
if ( stream.match( /:*[\*#]*/ ) ) { if ( stream.match( /:*[\*#]*/ ) ) {
return 'mw-indenting'; return 'mw-indenting';
} }
break; break;
case ' ':
if ( stream.match( /[\s\u00a0]*:*{\|/, false ) ) { // Leading spaces is the correct syntax for a table, bug T108454
stream.eatSpace();
if ( stream.match( /:+/ ) ) { // ::{|
state.stack.push( state.tokenize );
state.tokenize = eatStartTable;
return 'mw-indenting';
}
stream.eat( '{' );
} else {
return 'mw-skipformatting';
}
// break is not necessary here
/*falls through*/
case '{': case '{':
if ( stream.eat( '|' ) ) { if ( stream.eat( '|' ) ) {
stream.eatSpace(); stream.eatSpace();