PageSourceSearch

https://alquiler.feltrero.com/web/static/lib/ace/mode-xml.js

js feltrero.com collected 2026-10-08 18:27:21 UTC 23,724 bytes, 670 lines download raw bytes

1define("ace/mode/xml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
2"use strict";
3
4var oop = require("../lib/oop");
5var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
6
7var 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
199oop.inherits(XmlHighlightRules, TextHighlightRules);
200
201exports.XmlHighlightRules = XmlHighlightRules;
202});
203
204define("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
207var oop = require("../../lib/oop");
208var Behaviour = require("../behaviour").Behaviour;
209var TokenIterator = require("../../token_iterator").TokenIterator;
210var lang = require("../../lib/lang");
211
212function is(token, type) {
213    return token && token.type.lastIndexOf(type + ".xml") > -1;
214}
215
216var 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                    // TODO also handle non-closed string at the end of the line
289                    if (nextToken && is(nextToken, "attribute-value"))
290                        return;
291                    iterator.stepBackward();
292                }
293            }
294
295            if (/^\s*>/.test(session.getLine(position.row).slice(position.column)))
296                return;
297            while (!is(token, "tag-name")) {
298                token = iterator.stepBackward();
299                if (token.value == "<") {
300                    token = iterator.stepForward();
301                    break;
302                }
303            }
304
305            var tokenRow = iterator.getCurrentTokenRow();
306            var tokenColumn = iterator.getCurrentTokenColumn();
307            if (is(iterator.stepBackward(), "end-tag-open"))
308                return;
309
310            var element = token.value;
311            if (tokenRow == position.row)
312                element = element.substring(0, position.column - tokenColumn);
313
314            if (this.voidElements.hasOwnProperty(element.toLowerCase()))
315                 return;
316
317            return {
318               text: ">" + "</" + element + ">",
319               selection: [1, 1]
320            };
321        }
322    });
323
324    this.add("autoindent", "insertion", function (state, action, editor, session, text) {
325        if (text == "\n") {
326            var cursor = editor.getCursorPosition();
327            var line = session.getLine(cursor.row);
328            var iterator = new TokenIterator(session, cursor.row, cursor.column);
329            var token = iterator.getCurrentToken();
330
331            if (token && token.type.indexOf("tag-close") !== -1) {
332                if (token.value == "/>")
333                    return;
334                while (token && token.type.indexOf("tag-name") === -1) {
335                    token = iterator.stepBackward();
336                }
337
338                if (!token) {
339                    return;
340                }
341
342                var tag = token.value;
343                var row = iterator.getCurrentTokenRow();
344                token = iterator.stepBackward();
345                if (!token || token.type.indexOf("end-tag") !== -1) {
346                    return;
347                }
348
349                if (this.voidElements && !this.voidElements[tag]) {
350                    var nextToken = session.getTokenAt(cursor.row, cursor.column+1);
351                    var line = session.getLine(row);
352                    var nextIndent = this.$getIndent(line);
353                    var indent = nextIndent + session.getTabString();
354
355                    if (nextToken && nextToken.value === "</") {
356                        return {
357                            text: "\n" + indent + "\n" + nextIndent,
358                            selection: [1, indent.length, 1, indent.length]
359                        };
360                    } else {
361                        return {
362                            text: "\n" + indent
363                        };
364                    }
365                }
366            }
367        }
368    });
369
370};
371
372oop.inherits(XmlBehaviour, Behaviour);
373
374exports.XmlBehaviour = XmlBehaviour;
375});
376
377define("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) {
378"use strict";
379
380var oop = require("../../lib/oop");
381var lang = require("../../lib/lang");
382var Range = require("../../range").Range;
383var BaseFoldMode = require("./fold_mode").FoldMode;
384var TokenIterator = require("../../token_iterator").TokenIterator;
385
386var FoldMode = exports.FoldMode = function(voidElements, optionalEndTags) {
387    BaseFoldMode.call(this);
388    this.voidElements = voidElements || {};
389    this.optionalEndTags = oop.mixin({}, this.voidElements);
390    if (optionalEndTags)
391        oop.mixin(this.optionalEndTags, optionalEndTags);
392    
393};
394oop.inherits(FoldMode, BaseFoldMode);
395
396var Tag = function() {
397    this.tagName = "";
398    this.closing = false;
399    this.selfClosing = false;
400    this.start = {row: 0, column: 0};
401    this.end = {row: 0, column: 0};
402};
403
404function is(token, type) {
405    return token.type.lastIndexOf(type + ".xml") > -1;
406}
407
408(function() {
409
410    this.getFoldWidget = function(session, foldStyle, row) {
411        var tag = this._getFirstTagInLine(session, row);
412
413        if (!tag)
414            return this.getCommentFoldWidget(session, row);
415
416        if (tag.closing || (!tag.tagName && tag.selfClosing))
417            return foldStyle == "markbeginend" ? "end" : "";
418
419        if (!tag.tagName || tag.selfClosing || this.voidElements.hasOwnProperty(tag.tagName.toLowerCase()))
420            return "";
421
422        if (this._findEndTagInLine(session, row, tag.tagName, tag.end.column))
423            return "";
424
425        return "start";
426    };
427    
428    this.getCommentFoldWidget = function(session, row) {
429        if (/comment/.test(session.getState(row)) && /<!-/.test(session.getLine(row)))
430            return "start";
431        return "";
432    };
433    this._getFirstTagInLine = function(session, row) {
434        var tokens = session.getTokens(row);
435        var tag = new Tag();
436
437        for (var i = 0; i < tokens.length; i++) {
438            var token = tokens[i];
439            if (is(token, "tag-open")) {
440                tag.end.column = tag.start.column + token.value.length;
441                tag.closing = is(token, "end-tag-open");
442                token = tokens[++i];
443                if (!token)
444                    return null;
445                tag.tagName = token.value;
446                tag.end.column += token.value.length;
447                for (i++; i < tokens.length; i++) {
448                    token = tokens[i];
449                    tag.end.column += token.value.length;
450                    if (is(token, "tag-close")) {
451                        tag.selfClosing = token.value == '/>';
452                        break;
453                    }
454                }
455                return tag;
456            } else if (is(token, "tag-close")) {
457                tag.selfClosing = token.value == '/>';
458                return tag;
459            }
460            tag.start.column += token.value.length;
461        }
462
463        return null;
464    };
465
466    this._findEndTagInLine = function(session, row, tagName, startColumn) {
467        var tokens = session.getTokens(row);
468        var column = 0;
469        for (var i = 0; i < tokens.length; i++) {
470            var token = tokens[i];
471            column += token.value.length;
472            if (column < startColumn)
473                continue;
474            if (is(token, "end-tag-open")) {
475                token = tokens[i + 1];
476                if (token && token.value == tagName)
477                    return true;
478            }
479        }
480        return false;
481    };
482    this._readTagForward = function(iterator) {
483        var token = iterator.getCurrentToken();
484        if (!token)
485            return null;
486
487        var tag = new Tag();
488        do {
489            if (is(token, "tag-open")) {
490                tag.closing = is(token, "end-tag-open");
491                tag.start.row = iterator.getCurrentTokenRow();
492                tag.start.column = iterator.getCurrentTokenColumn();
493            } else if (is(token, "tag-name")) {
494                tag.tagName = token.value;
495            } else if (is(token, "tag-close")) {
496                tag.selfClosing = token.value == "/>";
497                tag.end.row = iterator.getCurrentTokenRow();
498                tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
499                iterator.stepForward();
500                return tag;
501            }
502        } while(token = iterator.stepForward());
503
504        return null;
505    };
506    
507    this._readTagBackward = function(iterator) {
508        var token = iterator.getCurrentToken();
509        if (!token)
510            return null;
511
512        var tag = new Tag();
513        do {
514            if (is(token, "tag-open")) {
515                tag.closing = is(token, "end-tag-open");
516                tag.start.row = iterator.getCurrentTokenRow();
517                tag.start.column = iterator.getCurrentTokenColumn();
518                iterator.stepBackward();
519                return tag;
520            } else if (is(token, "tag-name")) {
521                tag.tagName = token.value;
522            } else if (is(token, "tag-close")) {
523                tag.selfClosing = token.value == "/>";
524                tag.end.row = iterator.getCurrentTokenRow();
525                tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
526            }
527        } while(token = iterator.stepBackward());
528
529        return null;
530    };
531    
532    this._pop = function(stack, tag) {
533        while (stack.length) {
534            
535            var top = stack[stack.length-1];
536            if (!tag || top.tagName == tag.tagName) {
537                return stack.pop();
538            }
539            else if (this.optionalEndTags.hasOwnProperty(top.tagName)) {
540                stack.pop();
541                continue;
542            } else {
543                return null;
544            }
545        }
546    };
547    
548    this.getFoldWidgetRange = function(session, foldStyle, row) {
549        var firstTag = this._getFirstTagInLine(session, row);
550        
551        if (!firstTag) {
552            return this.getCommentFoldWidget(session, row)
553                && session.getCommentFoldRange(row, session.getLine(row).length);
554        }
555        
556        var isBackward = firstTag.closing || firstTag.selfClosing;
557        var stack = [];
558        var tag;
559        
560        if (!isBackward) {
561            var iterator = new TokenIterator(session, row, firstTag.start.column);
562            var start = {
563                row: row,
564                column: firstTag.start.column + firstTag.tagName.length + 2
565            };
566            if (firstTag.start.row == firstTag.end.row)
567                start.column = firstTag.end.column;
568            while (tag = this._readTagForward(iterator)) {
569                if (tag.selfClosing) {
570                    if (!stack.length) {
571                        tag.start.column += tag.tagName.length + 2;
572                        tag.end.column -= 2;
573                        return Range.fromPoints(tag.start, tag.end);
574                    } else
575                        continue;
576                }
577                
578                if (tag.closing) {
579                    this._pop(stack, tag);
580                    if (stack.length == 0)
581                        return Range.fromPoints(start, tag.start);
582                }
583                else {
584                    stack.push(tag);
585                }
586            }
587        }
588        else {
589            var iterator = new TokenIterator(session, row, firstTag.end.column);
590            var end = {
591                row: row,
592                column: firstTag.start.column
593            };
594            
595            while (tag = this._readTagBackward(iterator)) {
596                if (tag.selfClosing) {
597                    if (!stack.length) {
598                        tag.start.column += tag.tagName.length + 2;
599                        tag.end.column -= 2;
600                        return Range.fromPoints(tag.start, tag.end);
601                    } else
602                        continue;
603                }
604                
605                if (!tag.closing) {
606                    this._pop(stack, tag);
607                    if (stack.length == 0) {
608                        tag.start.column += tag.tagName.length + 2;
609                        if (tag.start.row == tag.end.row && tag.start.column < tag.end.column)
610                            tag.start.column = tag.end.column;
611                        return Range.fromPoints(tag.start, end);
612                    }
613                }
614                else {
615                    stack.push(tag);
616                }
617            }
618        }
619        
620    };
621
622}).call(FoldMode.prototype);
623
624});
625
626define("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) {
627"use strict";
628
629var oop = require("../lib/oop");
630var lang = require("../lib/lang");
631var TextMode = require("./text").Mode;
632var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
633var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
634var XmlFoldMode = require("./folding/xml").FoldMode;
635var WorkerClient = require("../worker/worker_client").WorkerClient;
636
637var Mode = function() {
638   this.HighlightRules = XmlHighlightRules;
639   this.$behaviour = new XmlBehaviour();
640   this.foldingRules = new XmlFoldMode();
641};
642
643oop.inherits(Mode, TextMode);
644
645(function() {
646
647    this.voidElements = lang.arrayToMap([]);
648
649    this.blockComment = {start: "<!--", end: "-->"};
650
651    this.createWorker = function(session) {
652        var worker = new WorkerClient(["ace"], "ace/mode/xml_worker", "Worker");
653        worker.attachToDocument(session.getDocument());
654
655        worker.on("error", function(e) {
656            session.setAnnotations(e.data);
657        });
658
659        worker.on("terminate", function() {
660            session.clearAnnotations();
661        });
662
663        return worker;
664    };
665    
666    this.$id = "ace/mode/xml";
667}).call(Mode.prototype);
668
669exports.Mode = Mode;
670});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.