From 1a05b6c9d25d51b14ee364844659f487e10304c7 Mon Sep 17 00:00:00 2001 From: Pavel Astakhov Date: Thu, 21 Aug 2014 20:36:09 +0600 Subject: [PATCH] add highlighting bold and italic wikitext (v 1.1.0) Change-Id: I6576d0b592dee8242c05dc60b45f282349af475d --- CodeMirror.php | 2 +- resources/mode/mediawiki/mediawiki.js | 33 +++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/CodeMirror.php b/CodeMirror.php index 0561b1a0..59b95643 100644 --- a/CodeMirror.php +++ b/CodeMirror.php @@ -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( diff --git a/resources/mode/mediawiki/mediawiki.js b/resources/mode/mediawiki/mediawiki.js index aff17a6d..2064e08f 100644 --- a/resources/mode/mediawiki/mediawiki.js +++ b/resources/mode/mediawiki/mediawiki.js @@ -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);