summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMark Macdonald <mamacdon@gmail.com>2013-10-10 20:55:50 -0400
committerMark Macdonald <mamacdon@gmail.com>2013-10-10 22:03:38 -0400
commiteb3d4051502eea0a737567d82503719038e86bed (patch)
treeeaccd76ad57bfee1115959ebe0fb37d2fa4a5b66
parenta4d3d6f2d5e2b89a31d91dc1e026bb0c405d7c38 (diff)
downloadorg.eclipse.orion.client-origin/codemirror.zip
org.eclipse.orion.client-origin/codemirror.tar.gz
org.eclipse.orion.client-origin/codemirror.tar.bz2
[Bug 411188] [codemirror] Markdown files not being highlightedorigin/codemirror
-Implement Mirror.startState(mode) and the "text/plain" mode (aka "null")
-rw-r--r--bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js31
1 files changed, 28 insertions, 3 deletions
diff --git a/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js b/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js
index 2ba124f..33c882c 100644
--- a/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js
+++ b/bundles/org.eclipse.orion.client.editor/web/orion/editor/mirror.js
@@ -1,6 +1,6 @@
/*******************************************************************************
* @license
- * Copyright (c) 2011, 2012 IBM Corporation and others.
+ * Copyright (c) 2011, 2013 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials are made
* available under the terms of the Eclipse Public License v1.0
* (http://www.eclipse.org/legal/epl-v10.html), and the Eclipse Distribution
@@ -9,7 +9,7 @@
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
-/*global define */
+/*global define console*/
/*jslint browser:true forin:true*/
define("orion/editor/mirror", ["i18n!orion/editor/nls/messages", "orion/editor/eventTarget", "orion/editor/annotations"], function(messages, mEventTarget, mAnnotations) {
// TODO this affects indentation, which we don't support. Should be a parameter.
@@ -103,6 +103,17 @@ define("orion/editor/mirror", ["i18n!orion/editor/nls/messages", "orion/editor/e
};
/**
+ * Creates a mode that consumes a stream and generates no tokens.
+ */
+ function NullModeFactory(cmConfig, modeConfig) {
+ return {
+ token: function(stream, state) {
+ return stream.skipToEnd();
+ }
+ };
+ }
+
+ /**
* @name orion.mirror.Mirror
* @class A shim for CodeMirror's <code>CodeMirror</code> API.
* @description A Mirror is a partial implementation of the API provided by the <code><a href="http://codemirror.net/doc/manual.html#api">CodeMirror object</a></code>.
@@ -129,6 +140,9 @@ define("orion/editor/mirror", ["i18n!orion/editor/nls/messages", "orion/editor/e
// Expose Stream as a property named "StringStream". This is required to support CodeMirror's Perl mode,
// which monkey-patches CodeMirror.StringStream.prototype and will fail if that object doesn't exist.
this.StringStream = Stream;
+
+ this.defineMode("null", NullModeFactory);
+ this.defineMIME("text/plain", "null");
}
function keys(obj) {
var k = [];
@@ -161,6 +175,13 @@ define("orion/editor/mirror", ["i18n!orion/editor/nls/messages", "orion/editor/e
}
return newState;
},
+ /**
+ * Alias for mode.startState().
+ * @returns {Object} The start state returned by <code>mode</code>.
+ */
+ startState: function(/**Object*/ mode, /**Number?*/ basecolumn) {
+ return mode.startState(basecolumn);
+ },
/** @see <a href="http://codemirror.net/doc/manual.html#modeapi">http://codemirror.net/doc/manual.html#modeapi</a> */
defineMode: function(/**String*/ name, /**Function(options, config)*/ modeFactory) {
this._modes[name] = modeFactory;
@@ -189,7 +210,11 @@ define("orion/editor/mirror", ["i18n!orion/editor/nls/messages", "orion/editor/e
}
modeFactory = modeFactory || this._modes[modeSpec];
if (typeof modeFactory !== "function") {
- throw "Mode not found " + modeSpec;
+ if (typeof console !== "undefined" && console) {
+ console.log("Mode not found: " + modeSpec);
+ }
+ // Return the null mode here for compatibility with CodeMirror
+ return this.getMode(options, "null");
}
return modeFactory(options, config);
},