Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1542)

Unified Diff: Source/devtools/front_end/cm/htmlembedded.js

Issue 18341003: DevTools: [CodeMirror] Add syntax highlighting for some other languages. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebaselined Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/devtools/front_end/cm/coffeescript.js ('k') | Source/devtools/front_end/cm/php.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/devtools/front_end/cm/htmlembedded.js
diff --git a/Source/devtools/front_end/cm/htmlembedded.js b/Source/devtools/front_end/cm/htmlembedded.js
new file mode 100644
index 0000000000000000000000000000000000000000..ff6dfd2f92e0d58f4c07a9e82aa7e196a4e889a6
--- /dev/null
+++ b/Source/devtools/front_end/cm/htmlembedded.js
@@ -0,0 +1,73 @@
+CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
+
+ //config settings
+ var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
+ scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
+
+ //inner modes
+ var scriptingMode, htmlMixedMode;
+
+ //tokenizer when in html mode
+ function htmlDispatch(stream, state) {
+ if (stream.match(scriptStartRegex, false)) {
+ state.token=scriptingDispatch;
+ return scriptingMode.token(stream, state.scriptState);
+ }
+ else
+ return htmlMixedMode.token(stream, state.htmlState);
+ }
+
+ //tokenizer when in scripting mode
+ function scriptingDispatch(stream, state) {
+ if (stream.match(scriptEndRegex, false)) {
+ state.token=htmlDispatch;
+ return htmlMixedMode.token(stream, state.htmlState);
+ }
+ else
+ return scriptingMode.token(stream, state.scriptState);
+ }
+
+
+ return {
+ startState: function() {
+ scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
+ htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
+ return {
+ token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
+ htmlState : CodeMirror.startState(htmlMixedMode),
+ scriptState : CodeMirror.startState(scriptingMode)
+ };
+ },
+
+ token: function(stream, state) {
+ return state.token(stream, state);
+ },
+
+ indent: function(state, textAfter) {
+ if (state.token == htmlDispatch)
+ return htmlMixedMode.indent(state.htmlState, textAfter);
+ else if (scriptingMode.indent)
+ return scriptingMode.indent(state.scriptState, textAfter);
+ },
+
+ copyState: function(state) {
+ return {
+ token : state.token,
+ htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
+ scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
+ };
+ },
+
+ electricChars: "/{}:",
+
+ innerMode: function(state) {
+ if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode};
+ else return {state: state.htmlState, mode: htmlMixedMode};
+ }
+ };
+}, "htmlmixed");
+
+CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
+CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
+CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
+CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingModeSpec:"ruby"});
paulirish 2013/07/03 21:20:48 Looks like we don't include the Ruby mode.
« no previous file with comments | « Source/devtools/front_end/cm/coffeescript.js ('k') | Source/devtools/front_end/cm/php.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698