mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/CodeMirror
synced 2024-11-15 02:04:02 +00:00
add highlighting bold and italic wikitext (v 1.1.0)
Change-Id: I6576d0b592dee8242c05dc60b45f282349af475d
This commit is contained in:
parent
47d5f45baf
commit
1a05b6c9d2
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue