mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-15 02:04:02 +00:00
add highlighting internal link (v 1.7.0)
Change-Id: I9609c62e67ff61650d7e4efed802246a99f0703c
This commit is contained in:
parent
3627671730
commit
9b4faf39b1
|
@ -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.6.1';
|
||||
const EXT_CODEMIRROR_VERSION = '1.7.0';
|
||||
|
||||
// Register this extension on Special:Version
|
||||
$wgExtensionCredits['parserhook'][] = array(
|
||||
|
@ -53,5 +53,8 @@ $wgResourceModules['ext.CodeMirror.lib'] = array(
|
|||
//'lib/codemirror/edit/closebrackets.js',
|
||||
'mode/mediawiki/mediawiki.js',
|
||||
),
|
||||
'styles' => 'lib/codemirror/lib/codemirror.css',
|
||||
'styles' => array(
|
||||
'lib/codemirror/lib/codemirror.css',
|
||||
'mode/mediawiki/mediawiki.css',
|
||||
),
|
||||
) + $tpl;
|
||||
|
|
4
resources/mode/mediawiki/mediawiki.css
Normal file
4
resources/mode/mediawiki/mediawiki.css
Normal file
|
@ -0,0 +1,4 @@
|
|||
.cm-mw-underline {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
|
@ -13,6 +13,7 @@
|
|||
CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
||||
|
||||
var tagName = false;
|
||||
var mustEat = true;
|
||||
|
||||
function inWikitext( stream, state ) {
|
||||
function chain( parser ) {
|
||||
|
@ -28,6 +29,63 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
|||
}
|
||||
|
||||
switch ( blockType ) {
|
||||
case 'Link':
|
||||
if ( sol ) {
|
||||
state.ImInBlock.pop(); //FIXME: it is wrong Link
|
||||
return null;
|
||||
} else if ( stream.eatWhile( /[^#\s\u00a0\|\]]/ ) ) { //FIXME '{{' brokes Link, sample [[z{{page]]
|
||||
return 'attribute mw-underline strong';
|
||||
} else if ( stream.eat( '#' ) ) {
|
||||
state.ImInBlock.push( 'LinkToSection' );
|
||||
return 'attribute strong';
|
||||
} else if ( stream.eat( '|' ) ) {
|
||||
stream.eatSpace();
|
||||
state.ImInBlock.pop();
|
||||
state.ImInBlock.push( 'LinkText' );
|
||||
return 'tag strong';
|
||||
} else if ( stream.eatSpace() ) {
|
||||
if ( /[^#\|\]]/.test( stream.peek() ) ) {
|
||||
return 'attribute mw-underline strong';
|
||||
}
|
||||
return null;
|
||||
} else if ( stream.eat( ']' ) ) {
|
||||
if ( stream.eat( ']' ) ) {
|
||||
state.ImInBlock.pop();
|
||||
if ( !stream.eatSpace() ) {
|
||||
state.ImInBlock.push( 'LinkTrail' );
|
||||
}
|
||||
return 'tag bracket';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'LinkToSection':
|
||||
state.ImInBlock.pop();
|
||||
if ( sol ) {
|
||||
state.ImInBlock.pop(); //FIXME: it is wrong Link
|
||||
return null;
|
||||
}
|
||||
stream.eatWhile( /[^\|\]]/ ); //FIXME '{{' brokes Link, sample [[z{{page]]
|
||||
return 'attribute';
|
||||
case 'LinkText':
|
||||
stream.eatSpace();
|
||||
if ( stream.match( /[\s\u00a0]*\]\]/ ) ) {
|
||||
state.ImInBlock.pop();
|
||||
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>\}\[\]<\{\']/ ) ) { // &
|
||||
mustEat = false;
|
||||
style.push( 'mw-underline' );
|
||||
}
|
||||
break;
|
||||
case 'TemplatePageName':
|
||||
state.ImInBlock.pop();
|
||||
if ( stream.eat( '#' ) ) {
|
||||
|
@ -36,14 +94,14 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
|||
} else {
|
||||
if ( stream.eatWhile( /[^\s\u00a0\}\|<\{\&]/ ) ) {
|
||||
state.ImInBlock.push( 'TemplatePageNameContinue' );
|
||||
return 'link';
|
||||
return 'attribute mw-underline';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'TemplatePageNameContinue':
|
||||
stream.eatSpace();
|
||||
if ( stream.match( /[\s\u00a0]*[^\s\u00a0\}\|<\{\&]/ ) ) {
|
||||
return 'link';
|
||||
return 'attribute mw-underline';
|
||||
}
|
||||
if ( stream.eat( '|' ) ) {
|
||||
state.ImInBlock.pop();
|
||||
|
@ -162,15 +220,15 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
|||
return null;
|
||||
}
|
||||
}
|
||||
if ( state.isBold ) {
|
||||
style.push( 'strong' );
|
||||
}
|
||||
if ( state.isItalic ) {
|
||||
style.push( 'em' );
|
||||
}
|
||||
}
|
||||
|
||||
var ch = stream.next();
|
||||
var ch = null;
|
||||
if ( mustEat ) {
|
||||
ch = stream.next();
|
||||
} else {
|
||||
mustEat = true;
|
||||
}
|
||||
|
||||
if ( ch === '&' ) {
|
||||
// this code was copied from mode/xml/xml.js
|
||||
var ok;
|
||||
|
@ -196,6 +254,15 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
|||
return 'tag bracket';
|
||||
}
|
||||
break;
|
||||
case '[':
|
||||
if ( stream.eat( '[' ) ) { // Link Example: [[ Foo | Bar ]]
|
||||
stream.eatSpace();
|
||||
if ( /[^\]\|\[\{]/.test( stream.peek() ) ) {
|
||||
state.ImInBlock.push( 'Link' );
|
||||
return 'tag bracket';
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '<':
|
||||
if ( stream.match( '!--' ) ) {
|
||||
return chain( inBlock( 'comment', '-->' ) );
|
||||
|
@ -215,7 +282,13 @@ CodeMirror.defineMode('mediawiki', function( /*config, parserConfig*/ ) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
stream.eatWhile( /[^>\}<\{\'\&]/ );
|
||||
stream.eatWhile( /[^\s\u00a0>\}\[\]<\{\'\&]/ );
|
||||
if ( state.isBold ) {
|
||||
style.push( 'strong' );
|
||||
}
|
||||
if ( state.isItalic ) {
|
||||
style.push( 'em' );
|
||||
}
|
||||
if ( !state.allowWikiformatting ) {
|
||||
style.push( 'qualifier' );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue