|
50 | 50 | }; |
51 | 51 |
|
52 | 52 | CodeMirror.defineMode("php", function(config, parserConfig) { |
53 | | - var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true}); |
54 | | - var jsMode = CodeMirror.getMode(config, "javascript"); |
55 | | - var cssMode = CodeMirror.getMode(config, "css"); |
| 53 | + var htmlMode = CodeMirror.getMode(config, "text/html"); |
56 | 54 | var phpMode = CodeMirror.getMode(config, phpConfig); |
57 | 55 |
|
58 | | - function dispatch(stream, state) { // TODO open PHP inside text/css |
| 56 | + function dispatch(stream, state) { |
59 | 57 | var isPHP = state.curMode == phpMode; |
60 | 58 | if (stream.sol() && state.pending != '"') state.pending = null; |
61 | | - if (state.curMode == htmlMode) { |
| 59 | + if (!isPHP) { |
62 | 60 | if (stream.match(/^<\?\w*/)) { |
63 | 61 | state.curMode = phpMode; |
64 | 62 | state.curState = state.php; |
65 | | - state.curClose = "?>"; |
66 | 63 | return "meta"; |
67 | 64 | } |
68 | 65 | if (state.pending == '"') { |
|
80 | 77 | if (style == "string" && /\"$/.test(cur) && !/\?>/.test(cur)) state.pending = '"'; |
81 | 78 | else state.pending = {end: stream.pos, style: style}; |
82 | 79 | stream.backUp(cur.length - openPHP); |
83 | | - } else if (style == "tag" && stream.current() == ">" && state.curState.context) { |
84 | | - if (/^script$/i.test(state.curState.context.tagName)) { |
85 | | - state.curMode = jsMode; |
86 | | - state.curState = jsMode.startState(htmlMode.indent(state.curState, "")); |
87 | | - state.curClose = /^<\/\s*script\s*>/i; |
88 | | - } |
89 | | - else if (/^style$/i.test(state.curState.context.tagName)) { |
90 | | - state.curMode = cssMode; |
91 | | - state.curState = cssMode.startState(htmlMode.indent(state.curState, "")); |
92 | | - state.curClose = /^<\/\s*style\s*>/i; |
93 | | - } |
94 | 80 | } |
95 | 81 | return style; |
96 | | - } else if ((!isPHP || state.php.tokenize == null) && |
97 | | - stream.match(state.curClose, isPHP)) { |
| 82 | + } else if (isPHP && state.php.tokenize == null && stream.match("?>")) { |
98 | 83 | state.curMode = htmlMode; |
99 | 84 | state.curState = state.html; |
100 | | - state.curClose = null; |
101 | | - if (isPHP) return "meta"; |
102 | | - else return dispatch(stream, state); |
| 85 | + return "meta"; |
103 | 86 | } else { |
104 | | - return state.curMode.token(stream, state.curState); |
| 87 | + return phpMode.token(stream, state.curState); |
105 | 88 | } |
106 | 89 | } |
107 | 90 |
|
108 | 91 | return { |
109 | 92 | startState: function() { |
110 | | - var html = htmlMode.startState(); |
| 93 | + var html = CodeMirror.startState(htmlMode), php = CodeMirror.startState(phpMode); |
111 | 94 | return {html: html, |
112 | | - php: phpMode.startState(), |
| 95 | + php: php, |
113 | 96 | curMode: parserConfig.startOpen ? phpMode : htmlMode, |
114 | | - curState: parserConfig.startOpen ? phpMode.startState() : html, |
115 | | - curClose: parserConfig.startOpen ? /^\?>/ : null, |
116 | | - mode: parserConfig.startOpen ? "php" : "html", |
| 97 | + curState: parserConfig.startOpen ? php : html, |
117 | 98 | pending: null}; |
118 | 99 | }, |
119 | 100 |
|
120 | 101 | copyState: function(state) { |
121 | 102 | var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html), |
122 | 103 | php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur; |
123 | | - if (state.curState == html) cur = htmlNew; |
124 | | - else if (state.curState == php) cur = phpNew; |
125 | | - else cur = CodeMirror.copyState(state.curMode, state.curState); |
| 104 | + if (state.curMode == htmlMode) cur = htmlNew; |
| 105 | + else cur = phpNew; |
126 | 106 | return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur, |
127 | | - curClose: state.curClose, mode: state.mode, |
128 | 107 | pending: state.pending}; |
129 | 108 | }, |
130 | 109 |
|
|
141 | 120 |
|
142 | 121 | innerMode: function(state) { return {state: state.curState, mode: state.curMode}; } |
143 | 122 | }; |
144 | | - }, "xml", "clike", "javascript", "css"); |
| 123 | + }, "htmlmixed"); |
| 124 | + |
145 | 125 | CodeMirror.defineMIME("application/x-httpd-php", "php"); |
146 | 126 | CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true}); |
147 | 127 | CodeMirror.defineMIME("text/x-php", phpConfig); |
|
0 commit comments