1 |
5ae26965
|
horkmi
|
ace.define("ace/mode/xml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
|
2 |
|
|
"use strict";
|
3 |
|
|
|
4 |
|
|
var oop = require("../lib/oop");
|
5 |
|
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
6 |
|
|
|
7 |
|
|
var XmlHighlightRules = function(normalize) {
|
8 |
|
|
var tagRegex = "[_:a-zA-Z\xc0-\uffff][-_:.a-zA-Z0-9\xc0-\uffff]*";
|
9 |
|
|
|
10 |
|
|
this.$rules = {
|
11 |
|
|
start : [
|
12 |
|
|
{token : "string.cdata.xml", regex : "<\\!\\[CDATA\\[", next : "cdata"},
|
13 |
|
|
{
|
14 |
|
|
token : ["punctuation.instruction.xml", "keyword.instruction.xml"],
|
15 |
|
|
regex : "(<\\?)(" + tagRegex + ")", next : "processing_instruction"
|
16 |
|
|
},
|
17 |
|
|
{token : "comment.start.xml", regex : "<\\!--", next : "comment"},
|
18 |
|
|
{
|
19 |
|
|
token : ["xml-pe.doctype.xml", "xml-pe.doctype.xml"],
|
20 |
|
|
regex : "(<\\!)(DOCTYPE)(?=[\\s])", next : "doctype", caseInsensitive: true
|
21 |
|
|
},
|
22 |
|
|
{include : "tag"},
|
23 |
|
|
{token : "text.end-tag-open.xml", regex: "</"},
|
24 |
|
|
{token : "text.tag-open.xml", regex: "<"},
|
25 |
|
|
{include : "reference"},
|
26 |
|
|
{defaultToken : "text.xml"}
|
27 |
|
|
],
|
28 |
|
|
|
29 |
|
|
processing_instruction : [{
|
30 |
|
|
token : "entity.other.attribute-name.decl-attribute-name.xml",
|
31 |
|
|
regex : tagRegex
|
32 |
|
|
}, {
|
33 |
|
|
token : "keyword.operator.decl-attribute-equals.xml",
|
34 |
|
|
regex : "="
|
35 |
|
|
}, {
|
36 |
|
|
include: "whitespace"
|
37 |
|
|
}, {
|
38 |
|
|
include: "string"
|
39 |
|
|
}, {
|
40 |
|
|
token : "punctuation.xml-decl.xml",
|
41 |
|
|
regex : "\\?>",
|
42 |
|
|
next : "start"
|
43 |
|
|
}],
|
44 |
|
|
|
45 |
|
|
doctype : [
|
46 |
|
|
{include : "whitespace"},
|
47 |
|
|
{include : "string"},
|
48 |
|
|
{token : "xml-pe.doctype.xml", regex : ">", next : "start"},
|
49 |
|
|
{token : "xml-pe.xml", regex : "[-_a-zA-Z0-9:]+"},
|
50 |
|
|
{token : "punctuation.int-subset", regex : "\\[", push : "int_subset"}
|
51 |
|
|
],
|
52 |
|
|
|
53 |
|
|
int_subset : [{
|
54 |
|
|
token : "text.xml",
|
55 |
|
|
regex : "\\s+"
|
56 |
|
|
}, {
|
57 |
|
|
token: "punctuation.int-subset.xml",
|
58 |
|
|
regex: "]",
|
59 |
|
|
next: "pop"
|
60 |
|
|
}, {
|
61 |
|
|
token : ["punctuation.markup-decl.xml", "keyword.markup-decl.xml"],
|
62 |
|
|
regex : "(<\\!)(" + tagRegex + ")",
|
63 |
|
|
push : [{
|
64 |
|
|
token : "text",
|
65 |
|
|
regex : "\\s+"
|
66 |
|
|
},
|
67 |
|
|
{
|
68 |
|
|
token : "punctuation.markup-decl.xml",
|
69 |
|
|
regex : ">",
|
70 |
|
|
next : "pop"
|
71 |
|
|
},
|
72 |
|
|
{include : "string"}]
|
73 |
|
|
}],
|
74 |
|
|
|
75 |
|
|
cdata : [
|
76 |
|
|
{token : "string.cdata.xml", regex : "\\]\\]>", next : "start"},
|
77 |
|
|
{token : "text.xml", regex : "\\s+"},
|
78 |
|
|
{token : "text.xml", regex : "(?:[^\\]]|\\](?!\\]>))+"}
|
79 |
|
|
],
|
80 |
|
|
|
81 |
|
|
comment : [
|
82 |
|
|
{token : "comment.end.xml", regex : "-->", next : "start"},
|
83 |
|
|
{defaultToken : "comment.xml"}
|
84 |
|
|
],
|
85 |
|
|
|
86 |
|
|
reference : [{
|
87 |
|
|
token : "constant.language.escape.reference.xml",
|
88 |
|
|
regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
|
89 |
|
|
}],
|
90 |
|
|
|
91 |
|
|
attr_reference : [{
|
92 |
|
|
token : "constant.language.escape.reference.attribute-value.xml",
|
93 |
|
|
regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
|
94 |
|
|
}],
|
95 |
|
|
|
96 |
|
|
tag : [{
|
97 |
|
|
token : ["meta.tag.punctuation.tag-open.xml", "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml"],
|
98 |
|
|
regex : "(?:(<)|(</))((?:" + tagRegex + ":)?" + tagRegex + ")",
|
99 |
|
|
next: [
|
100 |
|
|
{include : "attributes"},
|
101 |
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : "start"}
|
102 |
|
|
]
|
103 |
|
|
}],
|
104 |
|
|
|
105 |
|
|
tag_whitespace : [
|
106 |
|
|
{token : "text.tag-whitespace.xml", regex : "\\s+"}
|
107 |
|
|
],
|
108 |
|
|
whitespace : [
|
109 |
|
|
{token : "text.whitespace.xml", regex : "\\s+"}
|
110 |
|
|
],
|
111 |
|
|
string: [{
|
112 |
|
|
token : "string.xml",
|
113 |
|
|
regex : "'",
|
114 |
|
|
push : [
|
115 |
|
|
{token : "string.xml", regex: "'", next: "pop"},
|
116 |
|
|
{defaultToken : "string.xml"}
|
117 |
|
|
]
|
118 |
|
|
}, {
|
119 |
|
|
token : "string.xml",
|
120 |
|
|
regex : '"',
|
121 |
|
|
push : [
|
122 |
|
|
{token : "string.xml", regex: '"', next: "pop"},
|
123 |
|
|
{defaultToken : "string.xml"}
|
124 |
|
|
]
|
125 |
|
|
}],
|
126 |
|
|
|
127 |
|
|
attributes: [{
|
128 |
|
|
token : "entity.other.attribute-name.xml",
|
129 |
|
|
regex : tagRegex
|
130 |
|
|
}, {
|
131 |
|
|
token : "keyword.operator.attribute-equals.xml",
|
132 |
|
|
regex : "="
|
133 |
|
|
}, {
|
134 |
|
|
include: "tag_whitespace"
|
135 |
|
|
}, {
|
136 |
|
|
include: "attribute_value"
|
137 |
|
|
}],
|
138 |
|
|
|
139 |
|
|
attribute_value: [{
|
140 |
|
|
token : "string.attribute-value.xml",
|
141 |
|
|
regex : "'",
|
142 |
|
|
push : [
|
143 |
|
|
{token : "string.attribute-value.xml", regex: "'", next: "pop"},
|
144 |
|
|
{include : "attr_reference"},
|
145 |
|
|
{defaultToken : "string.attribute-value.xml"}
|
146 |
|
|
]
|
147 |
|
|
}, {
|
148 |
|
|
token : "string.attribute-value.xml",
|
149 |
|
|
regex : '"',
|
150 |
|
|
push : [
|
151 |
|
|
{token : "string.attribute-value.xml", regex: '"', next: "pop"},
|
152 |
|
|
{include : "attr_reference"},
|
153 |
|
|
{defaultToken : "string.attribute-value.xml"}
|
154 |
|
|
]
|
155 |
|
|
}]
|
156 |
|
|
};
|
157 |
|
|
|
158 |
|
|
if (this.constructor === XmlHighlightRules)
|
159 |
|
|
this.normalizeRules();
|
160 |
|
|
};
|
161 |
|
|
|
162 |
|
|
|
163 |
|
|
(function() {
|
164 |
|
|
|
165 |
|
|
this.embedTagRules = function(HighlightRules, prefix, tag){
|
166 |
|
|
this.$rules.tag.unshift({
|
167 |
|
|
token : ["meta.tag.punctuation.tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
|
168 |
|
|
regex : "(<)(" + tag + "(?=\\s|>|$))",
|
169 |
|
|
next: [
|
170 |
|
|
{include : "attributes"},
|
171 |
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : prefix + "start"}
|
172 |
|
|
]
|
173 |
|
|
});
|
174 |
|
|
|
175 |
|
|
this.$rules[tag + "-end"] = [
|
176 |
|
|
{include : "attributes"},
|
177 |
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next: "start",
|
178 |
|
|
onMatch : function(value, currentState, stack) {
|
179 |
|
|
stack.splice(0);
|
180 |
|
|
return this.token;
|
181 |
|
|
}}
|
182 |
|
|
];
|
183 |
|
|
|
184 |
|
|
this.embedRules(HighlightRules, prefix, [{
|
185 |
|
|
token: ["meta.tag.punctuation.end-tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
|
186 |
|
|
regex : "(</)(" + tag + "(?=\\s|>|$))",
|
187 |
|
|
next: tag + "-end"
|
188 |
|
|
}, {
|
189 |
|
|
token: "string.cdata.xml",
|
190 |
|
|
regex : "<\\!\\[CDATA\\["
|
191 |
|
|
}, {
|
192 |
|
|
token: "string.cdata.xml",
|
193 |
|
|
regex : "\\]\\]>"
|
194 |
|
|
}]);
|
195 |
|
|
};
|
196 |
|
|
|
197 |
|
|
}).call(TextHighlightRules.prototype);
|
198 |
|
|
|
199 |
|
|
oop.inherits(XmlHighlightRules, TextHighlightRules);
|
200 |
|
|
|
201 |
|
|
exports.XmlHighlightRules = XmlHighlightRules;
|
202 |
|
|
});
|
203 |
|
|
|
204 |
|
|
ace.define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
|
205 |
|
|
"use strict";
|
206 |
|
|
|
207 |
|
|
var oop = require("../../lib/oop");
|
208 |
|
|
var Behaviour = require("../behaviour").Behaviour;
|
209 |
|
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
210 |
|
|
var lang = require("../../lib/lang");
|
211 |
|
|
|
212 |
|
|
function is(token, type) {
|
213 |
|
|
return token && token.type.lastIndexOf(type + ".xml") > -1;
|
214 |
|
|
}
|
215 |
|
|
|
216 |
|
|
var XmlBehaviour = function () {
|
217 |
|
|
|
218 |
|
|
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
|
219 |
|
|
if (text == '"' || text == "'") {
|
220 |
|
|
var quote = text;
|
221 |
|
|
var selected = session.doc.getTextRange(editor.getSelectionRange());
|
222 |
|
|
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
|
223 |
|
|
return {
|
224 |
|
|
text: quote + selected + quote,
|
225 |
|
|
selection: false
|
226 |
|
|
};
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
var cursor = editor.getCursorPosition();
|
230 |
|
|
var line = session.doc.getLine(cursor.row);
|
231 |
|
|
var rightChar = line.substring(cursor.column, cursor.column + 1);
|
232 |
|
|
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
233 |
|
|
var token = iterator.getCurrentToken();
|
234 |
|
|
|
235 |
|
|
if (rightChar == quote && (is(token, "attribute-value") || is(token, "string"))) {
|
236 |
|
|
return {
|
237 |
|
|
text: "",
|
238 |
|
|
selection: [1, 1]
|
239 |
|
|
};
|
240 |
|
|
}
|
241 |
|
|
|
242 |
|
|
if (!token)
|
243 |
|
|
token = iterator.stepBackward();
|
244 |
|
|
|
245 |
|
|
if (!token)
|
246 |
|
|
return;
|
247 |
|
|
|
248 |
|
|
while (is(token, "tag-whitespace") || is(token, "whitespace")) {
|
249 |
|
|
token = iterator.stepBackward();
|
250 |
|
|
}
|
251 |
|
|
var rightSpace = !rightChar || rightChar.match(/\s/);
|
252 |
|
|
if (is(token, "attribute-equals") && (rightSpace || rightChar == '>') || (is(token, "decl-attribute-equals") && (rightSpace || rightChar == '?'))) {
|
253 |
|
|
return {
|
254 |
|
|
text: quote + quote,
|
255 |
|
|
selection: [1, 1]
|
256 |
|
|
};
|
257 |
|
|
}
|
258 |
|
|
}
|
259 |
|
|
});
|
260 |
|
|
|
261 |
|
|
this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
|
262 |
|
|
var selected = session.doc.getTextRange(range);
|
263 |
|
|
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
|
264 |
|
|
var line = session.doc.getLine(range.start.row);
|
265 |
|
|
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
|
266 |
|
|
if (rightChar == selected) {
|
267 |
|
|
range.end.column++;
|
268 |
|
|
return range;
|
269 |
|
|
}
|
270 |
|
|
}
|
271 |
|
|
});
|
272 |
|
|
|
273 |
|
|
this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
|
274 |
|
|
if (text == '>') {
|
275 |
|
|
var position = editor.getSelectionRange().start;
|
276 |
|
|
var iterator = new TokenIterator(session, position.row, position.column);
|
277 |
|
|
var token = iterator.getCurrentToken() || iterator.stepBackward();
|
278 |
|
|
if (!token || !(is(token, "tag-name") || is(token, "tag-whitespace") || is(token, "attribute-name") || is(token, "attribute-equals") || is(token, "attribute-value")))
|
279 |
|
|
return;
|
280 |
|
|
if (is(token, "reference.attribute-value"))
|
281 |
|
|
return;
|
282 |
|
|
if (is(token, "attribute-value")) {
|
283 |
|
|
var tokenEndColumn = iterator.getCurrentTokenColumn() + token.value.length;
|
284 |
|
|
if (position.column < tokenEndColumn)
|
285 |
|
|
return;
|
286 |
|
|
if (position.column == tokenEndColumn) {
|
287 |
|
|
var nextToken = iterator.stepForward();
|
288 |
|
|
if (nextToken && is(nextToken, "attribute-value"))
|
289 |
|
|
return;
|
290 |
|
|
iterator.stepBackward();
|
291 |
|
|
}
|
292 |
|
|
}
|
293 |
|
|
|
294 |
|
|
if (/^\s*>/.test(session.getLine(position.row).slice(position.column)))
|
295 |
|
|
return;
|
296 |
|
|
while (!is(token, "tag-name")) {
|
297 |
|
|
token = iterator.stepBackward();
|
298 |
|
|
if (token.value == "<") {
|
299 |
|
|
token = iterator.stepForward();
|
300 |
|
|
break;
|
301 |
|
|
}
|
302 |
|
|
}
|
303 |
|
|
|
304 |
|
|
var tokenRow = iterator.getCurrentTokenRow();
|
305 |
|
|
var tokenColumn = iterator.getCurrentTokenColumn();
|
306 |
|
|
if (is(iterator.stepBackward(), "end-tag-open"))
|
307 |
|
|
return;
|
308 |
|
|
|
309 |
|
|
var element = token.value;
|
310 |
|
|
if (tokenRow == position.row)
|
311 |
|
|
element = element.substring(0, position.column - tokenColumn);
|
312 |
|
|
|
313 |
|
|
if (this.voidElements.hasOwnProperty(element.toLowerCase()))
|
314 |
|
|
return;
|
315 |
|
|
|
316 |
|
|
return {
|
317 |
|
|
text: ">" + "</" + element + ">",
|
318 |
|
|
selection: [1, 1]
|
319 |
|
|
};
|
320 |
|
|
}
|
321 |
|
|
});
|
322 |
|
|
|
323 |
|
|
this.add("autoindent", "insertion", function (state, action, editor, session, text) {
|
324 |
|
|
if (text == "\n") {
|
325 |
|
|
var cursor = editor.getCursorPosition();
|
326 |
|
|
var line = session.getLine(cursor.row);
|
327 |
|
|
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
328 |
|
|
var token = iterator.getCurrentToken();
|
329 |
|
|
|
330 |
|
|
if (token && token.type.indexOf("tag-close") !== -1) {
|
331 |
|
|
if (token.value == "/>")
|
332 |
|
|
return;
|
333 |
|
|
while (token && token.type.indexOf("tag-name") === -1) {
|
334 |
|
|
token = iterator.stepBackward();
|
335 |
|
|
}
|
336 |
|
|
|
337 |
|
|
if (!token) {
|
338 |
|
|
return;
|
339 |
|
|
}
|
340 |
|
|
|
341 |
|
|
var tag = token.value;
|
342 |
|
|
var row = iterator.getCurrentTokenRow();
|
343 |
|
|
token = iterator.stepBackward();
|
344 |
|
|
if (!token || token.type.indexOf("end-tag") !== -1) {
|
345 |
|
|
return;
|
346 |
|
|
}
|
347 |
|
|
|
348 |
|
|
if (this.voidElements && !this.voidElements[tag]) {
|
349 |
|
|
var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
|
350 |
|
|
var line = session.getLine(row);
|
351 |
|
|
var nextIndent = this.$getIndent(line);
|
352 |
|
|
var indent = nextIndent + session.getTabString();
|
353 |
|
|
|
354 |
|
|
if (nextToken && nextToken.value === "</") {
|
355 |
|
|
return {
|
356 |
|
|
text: "\n" + indent + "\n" + nextIndent,
|
357 |
|
|
selection: [1, indent.length, 1, indent.length]
|
358 |
|
|
};
|
359 |
|
|
} else {
|
360 |
|
|
return {
|
361 |
|
|
text: "\n" + indent
|
362 |
|
|
};
|
363 |
|
|
}
|
364 |
|
|
}
|
365 |
|
|
}
|
366 |
|
|
}
|
367 |
|
|
});
|
368 |
|
|
|
369 |
|
|
};
|
370 |
|
|
|
371 |
|
|
oop.inherits(XmlBehaviour, Behaviour);
|
372 |
|
|
|
373 |
|
|
exports.XmlBehaviour = XmlBehaviour;
|
374 |
|
|
});
|
375 |
|
|
|
376 |
|
|
ace.define("ace/mode/folding/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/range","ace/mode/folding/fold_mode","ace/token_iterator"], function(require, exports, module) {
|
377 |
|
|
"use strict";
|
378 |
|
|
|
379 |
|
|
var oop = require("../../lib/oop");
|
380 |
|
|
var lang = require("../../lib/lang");
|
381 |
|
|
var Range = require("../../range").Range;
|
382 |
|
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
383 |
|
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
384 |
|
|
|
385 |
|
|
var FoldMode = exports.FoldMode = function(voidElements, optionalEndTags) {
|
386 |
|
|
BaseFoldMode.call(this);
|
387 |
|
|
this.voidElements = voidElements || {};
|
388 |
|
|
this.optionalEndTags = oop.mixin({}, this.voidElements);
|
389 |
|
|
if (optionalEndTags)
|
390 |
|
|
oop.mixin(this.optionalEndTags, optionalEndTags);
|
391 |
|
|
|
392 |
|
|
};
|
393 |
|
|
oop.inherits(FoldMode, BaseFoldMode);
|
394 |
|
|
|
395 |
|
|
var Tag = function() {
|
396 |
|
|
this.tagName = "";
|
397 |
|
|
this.closing = false;
|
398 |
|
|
this.selfClosing = false;
|
399 |
|
|
this.start = {row: 0, column: 0};
|
400 |
|
|
this.end = {row: 0, column: 0};
|
401 |
|
|
};
|
402 |
|
|
|
403 |
|
|
function is(token, type) {
|
404 |
|
|
return token.type.lastIndexOf(type + ".xml") > -1;
|
405 |
|
|
}
|
406 |
|
|
|
407 |
|
|
(function() {
|
408 |
|
|
|
409 |
|
|
this.getFoldWidget = function(session, foldStyle, row) {
|
410 |
|
|
var tag = this._getFirstTagInLine(session, row);
|
411 |
|
|
|
412 |
|
|
if (!tag)
|
413 |
|
|
return this.getCommentFoldWidget(session, row);
|
414 |
|
|
|
415 |
|
|
if (tag.closing || (!tag.tagName && tag.selfClosing))
|
416 |
|
|
return foldStyle == "markbeginend" ? "end" : "";
|
417 |
|
|
|
418 |
|
|
if (!tag.tagName || tag.selfClosing || this.voidElements.hasOwnProperty(tag.tagName.toLowerCase()))
|
419 |
|
|
return "";
|
420 |
|
|
|
421 |
|
|
if (this._findEndTagInLine(session, row, tag.tagName, tag.end.column))
|
422 |
|
|
return "";
|
423 |
|
|
|
424 |
|
|
return "start";
|
425 |
|
|
};
|
426 |
|
|
|
427 |
|
|
this.getCommentFoldWidget = function(session, row) {
|
428 |
|
|
if (/comment/.test(session.getState(row)) && /<!-/.test(session.getLine(row)))
|
429 |
|
|
return "start";
|
430 |
|
|
return "";
|
431 |
|
|
};
|
432 |
|
|
this._getFirstTagInLine = function(session, row) {
|
433 |
|
|
var tokens = session.getTokens(row);
|
434 |
|
|
var tag = new Tag();
|
435 |
|
|
|
436 |
|
|
for (var i = 0; i < tokens.length; i++) {
|
437 |
|
|
var token = tokens[i];
|
438 |
|
|
if (is(token, "tag-open")) {
|
439 |
|
|
tag.end.column = tag.start.column + token.value.length;
|
440 |
|
|
tag.closing = is(token, "end-tag-open");
|
441 |
|
|
token = tokens[++i];
|
442 |
|
|
if (!token)
|
443 |
|
|
return null;
|
444 |
|
|
tag.tagName = token.value;
|
445 |
|
|
tag.end.column += token.value.length;
|
446 |
|
|
for (i++; i < tokens.length; i++) {
|
447 |
|
|
token = tokens[i];
|
448 |
|
|
tag.end.column += token.value.length;
|
449 |
|
|
if (is(token, "tag-close")) {
|
450 |
|
|
tag.selfClosing = token.value == '/>';
|
451 |
|
|
break;
|
452 |
|
|
}
|
453 |
|
|
}
|
454 |
|
|
return tag;
|
455 |
|
|
} else if (is(token, "tag-close")) {
|
456 |
|
|
tag.selfClosing = token.value == '/>';
|
457 |
|
|
return tag;
|
458 |
|
|
}
|
459 |
|
|
tag.start.column += token.value.length;
|
460 |
|
|
}
|
461 |
|
|
|
462 |
|
|
return null;
|
463 |
|
|
};
|
464 |
|
|
|
465 |
|
|
this._findEndTagInLine = function(session, row, tagName, startColumn) {
|
466 |
|
|
var tokens = session.getTokens(row);
|
467 |
|
|
var column = 0;
|
468 |
|
|
for (var i = 0; i < tokens.length; i++) {
|
469 |
|
|
var token = tokens[i];
|
470 |
|
|
column += token.value.length;
|
471 |
|
|
if (column < startColumn)
|
472 |
|
|
continue;
|
473 |
|
|
if (is(token, "end-tag-open")) {
|
474 |
|
|
token = tokens[i + 1];
|
475 |
|
|
if (token && token.value == tagName)
|
476 |
|
|
return true;
|
477 |
|
|
}
|
478 |
|
|
}
|
479 |
|
|
return false;
|
480 |
|
|
};
|
481 |
|
|
this._readTagForward = function(iterator) {
|
482 |
|
|
var token = iterator.getCurrentToken();
|
483 |
|
|
if (!token)
|
484 |
|
|
return null;
|
485 |
|
|
|
486 |
|
|
var tag = new Tag();
|
487 |
|
|
do {
|
488 |
|
|
if (is(token, "tag-open")) {
|
489 |
|
|
tag.closing = is(token, "end-tag-open");
|
490 |
|
|
tag.start.row = iterator.getCurrentTokenRow();
|
491 |
|
|
tag.start.column = iterator.getCurrentTokenColumn();
|
492 |
|
|
} else if (is(token, "tag-name")) {
|
493 |
|
|
tag.tagName = token.value;
|
494 |
|
|
} else if (is(token, "tag-close")) {
|
495 |
|
|
tag.selfClosing = token.value == "/>";
|
496 |
|
|
tag.end.row = iterator.getCurrentTokenRow();
|
497 |
|
|
tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
|
498 |
|
|
iterator.stepForward();
|
499 |
|
|
return tag;
|
500 |
|
|
}
|
501 |
|
|
} while(token = iterator.stepForward());
|
502 |
|
|
|
503 |
|
|
return null;
|
504 |
|
|
};
|
505 |
|
|
|
506 |
|
|
this._readTagBackward = function(iterator) {
|
507 |
|
|
var token = iterator.getCurrentToken();
|
508 |
|
|
if (!token)
|
509 |
|
|
return null;
|
510 |
|
|
|
511 |
|
|
var tag = new Tag();
|
512 |
|
|
do {
|
513 |
|
|
if (is(token, "tag-open")) {
|
514 |
|
|
tag.closing = is(token, "end-tag-open");
|
515 |
|
|
tag.start.row = iterator.getCurrentTokenRow();
|
516 |
|
|
tag.start.column = iterator.getCurrentTokenColumn();
|
517 |
|
|
iterator.stepBackward();
|
518 |
|
|
return tag;
|
519 |
|
|
} else if (is(token, "tag-name")) {
|
520 |
|
|
tag.tagName = token.value;
|
521 |
|
|
} else if (is(token, "tag-close")) {
|
522 |
|
|
tag.selfClosing = token.value == "/>";
|
523 |
|
|
tag.end.row = iterator.getCurrentTokenRow();
|
524 |
|
|
tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
|
525 |
|
|
}
|
526 |
|
|
} while(token = iterator.stepBackward());
|
527 |
|
|
|
528 |
|
|
return null;
|
529 |
|
|
};
|
530 |
|
|
|
531 |
|
|
this._pop = function(stack, tag) {
|
532 |
|
|
while (stack.length) {
|
533 |
|
|
|
534 |
|
|
var top = stack[stack.length-1];
|
535 |
|
|
if (!tag || top.tagName == tag.tagName) {
|
536 |
|
|
return stack.pop();
|
537 |
|
|
}
|
538 |
|
|
else if (this.optionalEndTags.hasOwnProperty(top.tagName)) {
|
539 |
|
|
stack.pop();
|
540 |
|
|
continue;
|
541 |
|
|
} else {
|
542 |
|
|
return null;
|
543 |
|
|
}
|
544 |
|
|
}
|
545 |
|
|
};
|
546 |
|
|
|
547 |
|
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
548 |
|
|
var firstTag = this._getFirstTagInLine(session, row);
|
549 |
|
|
|
550 |
|
|
if (!firstTag) {
|
551 |
|
|
return this.getCommentFoldWidget(session, row)
|
552 |
|
|
&& session.getCommentFoldRange(row, session.getLine(row).length);
|
553 |
|
|
}
|
554 |
|
|
|
555 |
|
|
var isBackward = firstTag.closing || firstTag.selfClosing;
|
556 |
|
|
var stack = [];
|
557 |
|
|
var tag;
|
558 |
|
|
|
559 |
|
|
if (!isBackward) {
|
560 |
|
|
var iterator = new TokenIterator(session, row, firstTag.start.column);
|
561 |
|
|
var start = {
|
562 |
|
|
row: row,
|
563 |
|
|
column: firstTag.start.column + firstTag.tagName.length + 2
|
564 |
|
|
};
|
565 |
|
|
if (firstTag.start.row == firstTag.end.row)
|
566 |
|
|
start.column = firstTag.end.column;
|
567 |
|
|
while (tag = this._readTagForward(iterator)) {
|
568 |
|
|
if (tag.selfClosing) {
|
569 |
|
|
if (!stack.length) {
|
570 |
|
|
tag.start.column += tag.tagName.length + 2;
|
571 |
|
|
tag.end.column -= 2;
|
572 |
|
|
return Range.fromPoints(tag.start, tag.end);
|
573 |
|
|
} else
|
574 |
|
|
continue;
|
575 |
|
|
}
|
576 |
|
|
|
577 |
|
|
if (tag.closing) {
|
578 |
|
|
this._pop(stack, tag);
|
579 |
|
|
if (stack.length == 0)
|
580 |
|
|
return Range.fromPoints(start, tag.start);
|
581 |
|
|
}
|
582 |
|
|
else {
|
583 |
|
|
stack.push(tag);
|
584 |
|
|
}
|
585 |
|
|
}
|
586 |
|
|
}
|
587 |
|
|
else {
|
588 |
|
|
var iterator = new TokenIterator(session, row, firstTag.end.column);
|
589 |
|
|
var end = {
|
590 |
|
|
row: row,
|
591 |
|
|
column: firstTag.start.column
|
592 |
|
|
};
|
593 |
|
|
|
594 |
|
|
while (tag = this._readTagBackward(iterator)) {
|
595 |
|
|
if (tag.selfClosing) {
|
596 |
|
|
if (!stack.length) {
|
597 |
|
|
tag.start.column += tag.tagName.length + 2;
|
598 |
|
|
tag.end.column -= 2;
|
599 |
|
|
return Range.fromPoints(tag.start, tag.end);
|
600 |
|
|
} else
|
601 |
|
|
continue;
|
602 |
|
|
}
|
603 |
|
|
|
604 |
|
|
if (!tag.closing) {
|
605 |
|
|
this._pop(stack, tag);
|
606 |
|
|
if (stack.length == 0) {
|
607 |
|
|
tag.start.column += tag.tagName.length + 2;
|
608 |
|
|
if (tag.start.row == tag.end.row && tag.start.column < tag.end.column)
|
609 |
|
|
tag.start.column = tag.end.column;
|
610 |
|
|
return Range.fromPoints(tag.start, end);
|
611 |
|
|
}
|
612 |
|
|
}
|
613 |
|
|
else {
|
614 |
|
|
stack.push(tag);
|
615 |
|
|
}
|
616 |
|
|
}
|
617 |
|
|
}
|
618 |
|
|
|
619 |
|
|
};
|
620 |
|
|
|
621 |
|
|
}).call(FoldMode.prototype);
|
622 |
|
|
|
623 |
|
|
});
|
624 |
|
|
|
625 |
|
|
ace.define("ace/mode/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text","ace/mode/xml_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/xml","ace/worker/worker_client"], function(require, exports, module) {
|
626 |
|
|
"use strict";
|
627 |
|
|
|
628 |
|
|
var oop = require("../lib/oop");
|
629 |
|
|
var lang = require("../lib/lang");
|
630 |
|
|
var TextMode = require("./text").Mode;
|
631 |
|
|
var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
|
632 |
|
|
var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
|
633 |
|
|
var XmlFoldMode = require("./folding/xml").FoldMode;
|
634 |
|
|
var WorkerClient = require("../worker/worker_client").WorkerClient;
|
635 |
|
|
|
636 |
|
|
var Mode = function() {
|
637 |
|
|
this.HighlightRules = XmlHighlightRules;
|
638 |
|
|
this.$behaviour = new XmlBehaviour();
|
639 |
|
|
this.foldingRules = new XmlFoldMode();
|
640 |
|
|
};
|
641 |
|
|
|
642 |
|
|
oop.inherits(Mode, TextMode);
|
643 |
|
|
|
644 |
|
|
(function() {
|
645 |
|
|
|
646 |
|
|
this.voidElements = lang.arrayToMap([]);
|
647 |
|
|
|
648 |
|
|
this.blockComment = {start: "<!--", end: "-->"};
|
649 |
|
|
|
650 |
|
|
this.createWorker = function(session) {
|
651 |
|
|
var worker = new WorkerClient(["ace"], "ace/mode/xml_worker", "Worker");
|
652 |
|
|
worker.attachToDocument(session.getDocument());
|
653 |
|
|
|
654 |
|
|
worker.on("error", function(e) {
|
655 |
|
|
session.setAnnotations(e.data);
|
656 |
|
|
});
|
657 |
|
|
|
658 |
|
|
worker.on("terminate", function() {
|
659 |
|
|
session.clearAnnotations();
|
660 |
|
|
});
|
661 |
|
|
|
662 |
|
|
return worker;
|
663 |
|
|
};
|
664 |
|
|
|
665 |
|
|
this.$id = "ace/mode/xml";
|
666 |
|
|
}).call(Mode.prototype);
|
667 |
|
|
|
668 |
|
|
exports.Mode = Mode;
|
669 |
|
|
}); (function() {
|
670 |
|
|
ace.require(["ace/mode/xml"], function(m) {
|
671 |
|
|
if (typeof module == "object" && typeof exports == "object" && module) {
|
672 |
|
|
module.exports = m;
|
673 |
|
|
}
|
674 |
|
|
});
|
675 |
|
|
})();
|
676 |
|
|
|