: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
|''Description''|Enables TiddlyWikiy syntax highlighting using CodeMirror|
|''Source''|[[GitHub|https://github.com/pmario/CodeMirror2/blob/tw-syntax/mode/tiddlywiki]]|
|''Documentation''|http://codemirror.tiddlyspace.com/|
|''License''|[[MIT License|http://www.opensource.org/licenses/mit-license.php]]|
|''Requires''|codemirror.js|
|''Keywords''|syntax highlighting color code mirror codemirror|
CoreVersion parameter is needed for TiddlyWiki only!
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
CodeMirror.defineMode("tiddlywiki", function () {
"allTags": true, "closeAll": true, "list": true,
"newJournal": true, "newTiddler": true,
"permaview": true, "saveChanges": true,
"search": true, "slider": true, "tabs": true,
"tag": true, "tagging": true, "tags": true,
"tiddler": true, "timeline": true,
"today": true, "version": true, "option": true,
"with": true, "filter": true
var isSpaceName = /[\w_\-]/i,
reHR = /^\-\-\-\-+$/, // <hr>
reWikiCommentStart = /^\/\*\*\*$/, // /***
reWikiCommentStop = /^\*\*\*\/$/, // ***/
reJsCodeStart = /^\/\/\{\{\{$/, // //{{{ js block start
reJsCodeStop = /^\/\/\}\}\}$/, // //}}} js stop
reXmlCodeStart = /^<!--\{\{\{-->$/, // xml block start
reXmlCodeStop = /^<!--\}\}\}-->$/, // xml stop
reCodeBlockStart = /^\{\{\{$/, // {{{ TW text div block start
reCodeBlockStop = /^\}\}\}$/, // }}} TW text stop
reUntilCodeStop = /.*?\}\}\}/;
function chain(stream, state, f) {
function tokenBase(stream, state) {
var sol = stream.sol(), ch = stream.peek();
state.block = false; // indicates the start of a code block.
if (sol && /[<\/\*{}\-]/.test(ch)) {
if (stream.match(reCodeBlockStart)) {
return chain(stream, state, twTokenCode);
if (stream.match(reBlockQuote))
if (stream.match(reWikiCommentStart) || stream.match(reWikiCommentStop))
if (stream.match(reJsCodeStart) || stream.match(reJsCodeStop) || stream.match(reXmlCodeStart) || stream.match(reXmlCodeStop))
if (sol && /[\/\*!#;:>|]/.test(ch)) {
if (ch == "!") { // tw header
if (ch == "*") { // tw list
if (ch == "#") { // tw numbered list
if (ch == ";") { // definition list, term
if (ch == ":") { // definition list, description
if (ch == ">") { // single line quote
if (ch == '{' && stream.match(/\{\{/))
return chain(stream, state, twTokenCode);
// rudimentary html:// file:// link matching. TW knows much more ...
/[ti]/i.test(stream.peek()) &&
stream.match(/\b(ttps?|tp|ile):\/\/[\-A-Z0-9+&@#\/%?=~_|$!:,.;]*[A-Z0-9+&@#\/%=~_|$]/i))
// just a little string indicator, don't want to have the whole string covered
if (ch == '~') // _no_ CamelCase indicator should be bold
if (/[\[\]]/.test(ch) && stream.match(ch)) // check for [[..]]
if (ch == "@") { // check for space link. TODO fix @@...@@ highlighting
stream.eatWhile(isSpaceName);
if (/\d/.test(ch)) { // numbers
if (ch == "/") { // tw invisible comment
return chain(stream, state, twTokenComment);
} else if (stream.eat("/")) { //
return chain(stream, state, twTokenEm);
if (ch == "_" && stream.eat("_")) // tw underline
return chain(stream, state, twTokenUnderline);
// strikethrough and mdash handling
if (ch == "-" && stream.eat("-")) {
// if strikethrough looks ugly, change CSS.
if (stream.peek() != ' ')
return chain(stream, state, twTokenStrike);
if (stream.peek() == ' ')
if (ch == "'" && stream.eat("'")) // tw bold
return chain(stream, state, twTokenStrong);
if (ch == "<" && stream.eat("<")) // tw macro
return chain(stream, state, twTokenMacro);
stream.eatWhile(/[\w\$_]/);
return textwords.propertyIsEnumerable(stream.current()) ? "keyword" : null
function twTokenComment(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
function twTokenStrong(stream, state) {
while (ch = stream.next()) {
if (ch == "'" && maybeEnd) {
state.tokenize = tokenBase;
function twTokenCode(stream, state) {
if (sb && stream.current()) {
if (!sb && stream.match(reUntilCodeStop)) {
state.tokenize = tokenBase;
if (sb && stream.sol() && stream.match(reCodeBlockStop)) {
state.tokenize = tokenBase;
function twTokenEm(stream, state) {
while (ch = stream.next()) {
if (ch == "/" && maybeEnd) {
state.tokenize = tokenBase;
function twTokenUnderline(stream, state) {
while (ch = stream.next()) {
if (ch == "_" && maybeEnd) {
state.tokenize = tokenBase;
// tw strike through text looks ugly
function twTokenStrike(stream, state) {
var maybeEnd = false, ch;
while (ch = stream.next()) {
if (ch == "-" && maybeEnd) {
state.tokenize = tokenBase;
function twTokenMacro(stream, state) {
if (stream.current() == '<<') {
state.tokenize = tokenBase;
if (stream.peek() == '>') {
state.tokenize = tokenBase;
stream.eatWhile(/[\w\$_]/);
return keywords.propertyIsEnumerable(stream.current()) ? "keyword" : null
startState: function () {
return {tokenize: tokenBase};
token: function (stream, state) {
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
CodeMirror.defineMIME("text/x-tiddlywiki", "tiddlywiki");