Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / Source / devtools / front_end / cm / htmlembedded.js
blobe8f7ba803f64fe3d2986f3797dc91e6e0a7eceb4
1 // CodeMirror, copyright (c) by Marijn Haverbeke and others
2 // Distributed under an MIT license: http://codemirror.net/LICENSE
4 (function(mod) {
5 if (typeof exports == "object" && typeof module == "object") // CommonJS
6 mod(require("../../lib/codemirror"), require("../htmlmixed/htmlmixed"));
7 else if (typeof define == "function" && define.amd) // AMD
8 define(["../../lib/codemirror", "../htmlmixed/htmlmixed"], mod);
9 else // Plain browser env
10 mod(CodeMirror);
11 })(function(CodeMirror) {
12 "use strict";
14 CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
16 //config settings
17 var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
18 scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
20 //inner modes
21 var scriptingMode, htmlMixedMode;
23 //tokenizer when in html mode
24 function htmlDispatch(stream, state) {
25 if (stream.match(scriptStartRegex, false)) {
26 state.token=scriptingDispatch;
27 return scriptingMode.token(stream, state.scriptState);
29 else
30 return htmlMixedMode.token(stream, state.htmlState);
33 //tokenizer when in scripting mode
34 function scriptingDispatch(stream, state) {
35 if (stream.match(scriptEndRegex, false)) {
36 state.token=htmlDispatch;
37 return htmlMixedMode.token(stream, state.htmlState);
39 else
40 return scriptingMode.token(stream, state.scriptState);
44 return {
45 startState: function() {
46 scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
47 htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
48 return {
49 token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
50 htmlState : CodeMirror.startState(htmlMixedMode),
51 scriptState : CodeMirror.startState(scriptingMode)
55 token: function(stream, state) {
56 return state.token(stream, state);
59 indent: function(state, textAfter) {
60 if (state.token == htmlDispatch)
61 return htmlMixedMode.indent(state.htmlState, textAfter);
62 else if (scriptingMode.indent)
63 return scriptingMode.indent(state.scriptState, textAfter);
66 copyState: function(state) {
67 return {
68 token : state.token,
69 htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
70 scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
74 innerMode: function(state) {
75 if (state.token == scriptingDispatch) return {state: state.scriptState, mode: scriptingMode};
76 else return {state: state.htmlState, mode: htmlMixedMode};
79 }, "htmlmixed");
81 CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
82 CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
83 CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
84 CodeMirror.defineMIME("application/x-erb", { name: "htmlembedded", scriptingModeSpec:"ruby"});
86 });