add highlighting bold and italic wikitext (v 1.1.0)

Change-Id: I6576d0b592dee8242c05dc60b45f282349af475d
This commit is contained in:
Pavel Astakhov 2014-08-21 20:36:09 +06:00
parent 47d5f45baf
commit 1a05b6c9d2
2 changed files with 29 additions and 6 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.' );
}
const CODEMIRROR_VERSION = '1.0.2';
const CODEMIRROR_VERSION = '1.1.0';
// Register this extension on Special:Version
$wgExtensionCredits['parserhook'][] = array(

View file

@ -36,7 +36,7 @@ CodeMirror.defineMode("mediawiki", function(config, parserConfig) {
}
if (stream.eat("}")) {
if (stream.eat("}")) {
state.tokenize = inText;
state.tokenize = inWikitext;
return "tag bracket";
}
}
@ -60,7 +60,7 @@ CodeMirror.defineMode("mediawiki", function(config, parserConfig) {
return "keyword strong";
}
}
state.tokenize = inText;
state.tokenize = inWikitext;
return "error";
}
@ -71,7 +71,7 @@ CodeMirror.defineMode("mediawiki", function(config, parserConfig) {
}
if (stream.eat("}")) {
if (stream.eat("}")) {
state.tokenize = inText;
state.tokenize = inWikitext;
return "tag bracket";
}
}
@ -85,9 +85,16 @@ CodeMirror.defineMode("mediawiki", function(config, parserConfig) {
return "string";
}
function inText(stream, state) {
function inWikitext(stream, state) {
var style = [];
var sol = stream.sol();
var ch = stream.next();
if (sol) {
state.isBold = false;
state.isItalic = false;
}
switch (ch) {
case "{":
if (stream.eat("{")) { // Templates
@ -96,13 +103,29 @@ CodeMirror.defineMode("mediawiki", function(config, parserConfig) {
return "tag bracket";
}
break;
case "'":
if (stream.match("''")) {
state.isBold = (state.isBold ? false : true);
} else if (stream.match("'")) {
state.isItalic = (state.isItalic ? false : true);
}
break;
}
if (state.isBold) {
style.push("strong");
}
if (state.isItalic) {
style.push("em");
}
if (style.length > 0) {
return style.join(" ");
}
return null;
}
return {
startState: function() {
return {tokenize: inText, style: null};
return {tokenize: inWikitext, style: null};
},
token: function(stream, state) {
return state.tokenize(stream, state);