2012-07-05 06:37:09 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2013-12-30 15:00:16 +00:00
|
|
|
* Distributed under the BSD license:
|
2012-07-05 06:37:09 +00:00
|
|
|
*
|
2013-12-30 15:00:16 +00:00
|
|
|
* Copyright (c) 2010, Ajax.org B.V.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
* * Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* * Neither the name of Ajax.org B.V. nor the
|
|
|
|
* names of its contributors may be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
|
|
|
|
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
2012-07-05 06:37:09 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
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'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
var oop = require("../lib/oop");
|
2014-04-29 09:03:14 +00:00
|
|
|
var lang = require("../lib/lang");
|
2012-07-05 06:37:09 +00:00
|
|
|
var TextMode = require("./text").Mode;
|
|
|
|
var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
|
|
|
|
var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
|
|
|
|
var XmlFoldMode = require("./folding/xml").FoldMode;
|
|
|
|
|
|
|
|
var Mode = function() {
|
2013-12-30 15:00:16 +00:00
|
|
|
this.HighlightRules = XmlHighlightRules;
|
2012-07-05 06:37:09 +00:00
|
|
|
this.$behaviour = new XmlBehaviour();
|
|
|
|
this.foldingRules = new XmlFoldMode();
|
|
|
|
};
|
|
|
|
|
|
|
|
oop.inherits(Mode, TextMode);
|
|
|
|
|
|
|
|
(function() {
|
2014-04-29 09:03:14 +00:00
|
|
|
|
|
|
|
this.voidElements = lang.arrayToMap([]);
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
this.blockComment = {start: "<!--", end: "-->"};
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
this.$id = "ace/mode/xml";
|
2012-07-05 06:37:09 +00:00
|
|
|
}).call(Mode.prototype);
|
|
|
|
|
|
|
|
exports.Mode = Mode;
|
|
|
|
});
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
define('ace/mode/xml_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
var oop = require("../lib/oop");
|
|
|
|
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
var XmlHighlightRules = function(normalize) {
|
2012-07-05 06:37:09 +00:00
|
|
|
this.$rules = {
|
2013-12-30 15:00:16 +00:00
|
|
|
start : [
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "string.cdata.xml", regex : "<\\!\\[CDATA\\[", next : "cdata"},
|
2013-12-30 15:00:16 +00:00
|
|
|
{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["punctuation.xml-decl.xml", "keyword.xml-decl.xml"],
|
|
|
|
regex : "(<\\?)(xml)(?=[\\s])", next : "xml_decl", caseInsensitive: true
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
|
|
|
{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["punctuation.instruction.xml", "keyword.instruction.xml"],
|
|
|
|
regex : "(<\\?)([-_a-zA-Z0-9]+)", next : "processing_instruction",
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "comment.xml", regex : "<\\!--", next : "comment"},
|
2013-12-30 15:00:16 +00:00
|
|
|
{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["xml-pe.doctype.xml", "xml-pe.doctype.xml"],
|
|
|
|
regex : "(<\\!)(DOCTYPE)(?=[\\s])", next : "doctype", caseInsensitive: true
|
2013-12-30 15:00:16 +00:00
|
|
|
},
|
|
|
|
{include : "tag"},
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "text.end-tag-open.xml", regex: "</"},
|
|
|
|
{token : "text.tag-open.xml", regex: "<"},
|
|
|
|
{include : "reference"},
|
|
|
|
{defaultToken : "text.xml"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
xml_decl : [{
|
|
|
|
token : "entity.other.attribute-name.decl-attribute-name.xml",
|
|
|
|
regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
|
|
|
|
}, {
|
|
|
|
token : "keyword.operator.decl-attribute-equals.xml",
|
|
|
|
regex : "="
|
|
|
|
}, {
|
|
|
|
include: "whitespace"
|
|
|
|
}, {
|
|
|
|
include: "string"
|
|
|
|
}, {
|
|
|
|
token : "punctuation.xml-decl.xml",
|
|
|
|
regex : "\\?>",
|
|
|
|
next : "start"
|
|
|
|
}],
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
processing_instruction : [
|
|
|
|
{token : "punctuation.instruction.xml", regex : "\\?>", next : "start"},
|
|
|
|
{defaultToken : "instruction.xml"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
doctype : [
|
2014-04-29 09:03:14 +00:00
|
|
|
{include : "whitespace"},
|
2013-12-30 15:00:16 +00:00
|
|
|
{include : "string"},
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "xml-pe.doctype.xml", regex : ">", next : "start"},
|
|
|
|
{token : "xml-pe.xml", regex : "[-_a-zA-Z0-9:]+"},
|
|
|
|
{token : "punctuation.int-subset", regex : "\\[", push : "int_subset"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
int_subset : [{
|
|
|
|
token : "text.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "\\s+"
|
2012-07-05 06:37:09 +00:00
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token: "punctuation.int-subset.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex: "]",
|
|
|
|
next: "pop"
|
2012-07-05 06:37:09 +00:00
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["punctuation.markup-decl.xml", "keyword.markup-decl.xml"],
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "(<\\!)([-_a-zA-Z0-9]+)",
|
|
|
|
push : [{
|
|
|
|
token : "text",
|
|
|
|
regex : "\\s+"
|
|
|
|
},
|
|
|
|
{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : "punctuation.markup-decl.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : ">",
|
|
|
|
next : "pop"
|
|
|
|
},
|
|
|
|
{include : "string"}]
|
|
|
|
}],
|
|
|
|
|
|
|
|
cdata : [
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "string.cdata.xml", regex : "\\]\\]>", next : "start"},
|
|
|
|
{token : "text.xml", regex : "\\s+"},
|
|
|
|
{token : "text.xml", regex : "(?:[^\\]]|\\](?!\\]>))+"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
comment : [
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "comment.xml", regex : "-->", next : "start"},
|
|
|
|
{defaultToken : "comment.xml"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
reference : [{
|
|
|
|
token : "constant.language.escape.reference.xml",
|
|
|
|
regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
|
|
|
|
}],
|
|
|
|
|
|
|
|
attr_reference : [{
|
|
|
|
token : "constant.language.escape.reference.attribute-value.xml",
|
|
|
|
regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
|
|
|
|
}],
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
tag : [{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["meta.tag.punctuation.tag-open.xml", "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml"],
|
|
|
|
regex : "(?:(<)|(</))((?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+)",
|
2013-12-30 15:00:16 +00:00
|
|
|
next: [
|
|
|
|
{include : "attributes"},
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : "start"}
|
2013-12-30 15:00:16 +00:00
|
|
|
]
|
|
|
|
}],
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
tag_whitespace : [
|
|
|
|
{token : "text.tag-whitespace.xml", regex : "\\s+"}
|
|
|
|
],
|
|
|
|
whitespace : [
|
|
|
|
{token : "text.whitespace.xml", regex : "\\s+"}
|
2013-12-30 15:00:16 +00:00
|
|
|
],
|
|
|
|
string: [{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : "string.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "'",
|
2014-04-29 09:03:14 +00:00
|
|
|
push : [
|
|
|
|
{token : "string.xml", regex: "'", next: "pop"},
|
|
|
|
{defaultToken : "string.xml"}
|
|
|
|
]
|
2012-07-05 06:37:09 +00:00
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token : "string.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : '"',
|
2014-04-29 09:03:14 +00:00
|
|
|
push : [
|
|
|
|
{token : "string.xml", regex: '"', next: "pop"},
|
|
|
|
{defaultToken : "string.xml"}
|
|
|
|
]
|
2012-07-05 06:37:09 +00:00
|
|
|
}],
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
attributes: [{
|
2014-04-29 09:03:14 +00:00
|
|
|
token : "entity.other.attribute-name.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
|
2012-07-05 06:37:09 +00:00
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token : "keyword.operator.attribute-equals.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "="
|
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
include: "tag_whitespace"
|
2013-12-30 15:00:16 +00:00
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
include: "attribute_value"
|
|
|
|
}],
|
|
|
|
|
|
|
|
attribute_value: [{
|
|
|
|
token : "string.attribute-value.xml",
|
|
|
|
regex : "'",
|
|
|
|
push : [
|
|
|
|
{token : "string.attribute-value.xml", regex: "'", next: "pop"},
|
|
|
|
{include : "attr_reference"},
|
|
|
|
{defaultToken : "string.attribute-value.xml"}
|
|
|
|
]
|
|
|
|
}, {
|
|
|
|
token : "string.attribute-value.xml",
|
|
|
|
regex : '"',
|
|
|
|
push : [
|
|
|
|
{token : "string.attribute-value.xml", regex: '"', next: "pop"},
|
|
|
|
{include : "attr_reference"},
|
|
|
|
{defaultToken : "string.attribute-value.xml"}
|
|
|
|
]
|
2012-07-05 06:37:09 +00:00
|
|
|
}]
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
if (this.constructor === XmlHighlightRules)
|
|
|
|
this.normalizeRules();
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
2013-12-30 15:00:16 +00:00
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
this.embedTagRules = function(HighlightRules, prefix, tag){
|
|
|
|
this.$rules.tag.unshift({
|
2014-04-29 09:03:14 +00:00
|
|
|
token : ["meta.tag.punctuation.tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
|
|
|
|
regex : "(<)(" + tag + "(?=\\s|>|$))",
|
2013-12-30 15:00:16 +00:00
|
|
|
next: [
|
|
|
|
{include : "attributes"},
|
2014-04-29 09:03:14 +00:00
|
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : prefix + "start"}
|
2013-12-30 15:00:16 +00:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$rules[tag + "-end"] = [
|
2014-04-29 09:03:14 +00:00
|
|
|
{include : "attributes"},
|
|
|
|
{token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next: "start",
|
2013-12-30 15:00:16 +00:00
|
|
|
onMatch : function(value, currentState, stack) {
|
|
|
|
stack.splice(0);
|
|
|
|
return this.token;
|
|
|
|
}}
|
|
|
|
]
|
|
|
|
|
|
|
|
this.embedRules(HighlightRules, prefix, [{
|
2014-04-29 09:03:14 +00:00
|
|
|
token: ["meta.tag.punctuation.end-tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
|
|
|
|
regex : "(</)(" + tag + "(?=\\s|>|$))",
|
2013-12-30 15:00:16 +00:00
|
|
|
next: tag + "-end"
|
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token: "string.cdata.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "<\\!\\[CDATA\\["
|
|
|
|
}, {
|
2014-04-29 09:03:14 +00:00
|
|
|
token: "string.cdata.xml",
|
2013-12-30 15:00:16 +00:00
|
|
|
regex : "\\]\\]>"
|
|
|
|
}]);
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(TextHighlightRules.prototype);
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
oop.inherits(XmlHighlightRules, TextHighlightRules);
|
|
|
|
|
|
|
|
exports.XmlHighlightRules = XmlHighlightRules;
|
|
|
|
});
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
define('ace/mode/behaviour/xml', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/behaviour', 'ace/token_iterator'], function(require, exports, module) {
|
2012-07-05 06:37:09 +00:00
|
|
|
|
|
|
|
|
|
|
|
var oop = require("../../lib/oop");
|
|
|
|
var Behaviour = require("../behaviour").Behaviour;
|
|
|
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
function is(token, type) {
|
|
|
|
return token.type.lastIndexOf(type + ".xml") > -1;
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var XmlBehaviour = function () {
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
|
|
|
|
if (text == '"' || text == "'") {
|
|
|
|
var quote = text;
|
|
|
|
var selected = session.doc.getTextRange(editor.getSelectionRange());
|
|
|
|
if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return {
|
2014-04-29 09:03:14 +00:00
|
|
|
text: quote + selected + quote,
|
2012-07-05 06:37:09 +00:00
|
|
|
selection: false
|
|
|
|
};
|
2013-12-30 15:00:16 +00:00
|
|
|
}
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
var cursor = editor.getCursorPosition();
|
|
|
|
var line = session.doc.getLine(cursor.row);
|
|
|
|
var rightChar = line.substring(cursor.column, cursor.column + 1);
|
2014-04-29 09:03:14 +00:00
|
|
|
var iterator = new TokenIterator(session, cursor.row, cursor.column);
|
|
|
|
var token = iterator.getCurrentToken();
|
2012-07-05 06:37:09 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (rightChar == quote && (is(token, "attribute-value") || is(token, "string"))) {
|
2013-12-30 15:00:16 +00:00
|
|
|
return {
|
2014-04-29 09:03:14 +00:00
|
|
|
text: "",
|
2013-12-30 15:00:16 +00:00
|
|
|
selection: [1, 1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (!token)
|
|
|
|
token = iterator.stepBackward();
|
2013-12-30 15:00:16 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (!token)
|
|
|
|
return;
|
|
|
|
|
|
|
|
while (is(token, "tag-whitespace") || is(token, "whitespace")) {
|
|
|
|
token = iterator.stepBackward();
|
|
|
|
}
|
|
|
|
var rightSpace = !rightChar || rightChar.match(/\s/);
|
|
|
|
if (is(token, "attribute-equals") && (rightSpace || rightChar == '>') || (is(token, "decl-attribute-equals") && (rightSpace || rightChar == '?'))) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return {
|
2014-04-29 09:03:14 +00:00
|
|
|
text: quote + quote,
|
|
|
|
selection: [1, 1]
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-16 18:05:39 +00:00
|
|
|
this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
|
2012-07-05 06:37:09 +00:00
|
|
|
var selected = session.doc.getTextRange(range);
|
|
|
|
if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
|
|
|
|
var line = session.doc.getLine(range.start.row);
|
|
|
|
var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
|
2013-12-30 15:00:16 +00:00
|
|
|
if (rightChar == selected) {
|
2012-07-05 06:37:09 +00:00
|
|
|
range.end.column++;
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
|
|
|
|
if (text == '>') {
|
|
|
|
var position = editor.getCursorPosition();
|
|
|
|
var iterator = new TokenIterator(session, position.row, position.column);
|
|
|
|
var token = iterator.getCurrentToken() || iterator.stepBackward();
|
|
|
|
if (!token || !(is(token, "tag-name") || is(token, "tag-whitespace") || is(token, "attribute-name") || is(token, "attribute-equals") || is(token, "attribute-value")))
|
|
|
|
return;
|
|
|
|
if (is(token, "reference.attribute-value"))
|
|
|
|
return;
|
|
|
|
if (is(token, "attribute-value")) {
|
|
|
|
var firstChar = token.value.charAt(0);
|
|
|
|
if (firstChar == '"' || firstChar == "'") {
|
|
|
|
var lastChar = token.value.charAt(token.value.length - 1);
|
|
|
|
var tokenEnd = iterator.getCurrentTokenColumn() + token.value.length;
|
|
|
|
if (tokenEnd > position.column || tokenEnd == position.column && firstChar != lastChar)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (!is(token, "tag-name")) {
|
|
|
|
token = iterator.stepBackward();
|
|
|
|
}
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
var tokenRow = iterator.getCurrentTokenRow();
|
|
|
|
var tokenColumn = iterator.getCurrentTokenColumn();
|
|
|
|
if (is(iterator.stepBackward(), "end-tag-open"))
|
|
|
|
return;
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
var element = token.value;
|
|
|
|
if (tokenRow == position.row)
|
|
|
|
element = element.substring(0, position.column - tokenColumn);
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (this.voidElements.hasOwnProperty(element.toLowerCase()))
|
|
|
|
return;
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
return {
|
|
|
|
text: '>' + '</' + element + '>',
|
|
|
|
selection: [1, 1]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
this.add('autoindent', 'insertion', function (state, action, editor, session, text) {
|
|
|
|
if (text == "\n") {
|
|
|
|
var cursor = editor.getCursorPosition();
|
|
|
|
var line = session.getLine(cursor.row);
|
|
|
|
var rightChars = line.substring(cursor.column, cursor.column + 2);
|
|
|
|
if (rightChars == '</') {
|
|
|
|
var next_indent = this.$getIndent(line);
|
|
|
|
var indent = next_indent + session.getTabString();
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
return {
|
|
|
|
text: '\n' + indent + '\n' + next_indent,
|
|
|
|
selection: [1, indent.length, 1, indent.length]
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2014-03-16 18:05:39 +00:00
|
|
|
};
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
oop.inherits(XmlBehaviour, Behaviour);
|
2014-03-16 18:05:39 +00:00
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
exports.XmlBehaviour = XmlBehaviour;
|
2012-07-05 06:37:09 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
|
|
|
|
var oop = require("../../lib/oop");
|
|
|
|
var lang = require("../../lib/lang");
|
|
|
|
var Range = require("../../range").Range;
|
|
|
|
var BaseFoldMode = require("./fold_mode").FoldMode;
|
|
|
|
var TokenIterator = require("../../token_iterator").TokenIterator;
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
var FoldMode = exports.FoldMode = function(voidElements, optionalEndTags) {
|
2012-07-05 06:37:09 +00:00
|
|
|
BaseFoldMode.call(this);
|
2014-04-29 09:03:14 +00:00
|
|
|
this.voidElements = oop.mixin(voidElements || {}, optionalEndTags || {});
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
oop.inherits(FoldMode, BaseFoldMode);
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
var Tag = function() {
|
|
|
|
this.tagName = "";
|
|
|
|
this.closing = false;
|
|
|
|
this.selfClosing = false;
|
|
|
|
this.start = {row: 0, column: 0};
|
|
|
|
this.end = {row: 0, column: 0};
|
|
|
|
};
|
|
|
|
|
|
|
|
function is(token, type) {
|
|
|
|
return token.type.lastIndexOf(type + ".xml") > -1;
|
|
|
|
}
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
(function() {
|
|
|
|
|
|
|
|
this.getFoldWidget = function(session, foldStyle, row) {
|
|
|
|
var tag = this._getFirstTagInLine(session, row);
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (!tag)
|
2012-07-05 06:37:09 +00:00
|
|
|
return "";
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (tag.closing || (!tag.tagName && tag.selfClosing))
|
|
|
|
return foldStyle == "markbeginend" ? "end" : "";
|
|
|
|
|
|
|
|
if (!tag.tagName || tag.selfClosing || this.voidElements.hasOwnProperty(tag.tagName.toLowerCase()))
|
2012-07-05 06:37:09 +00:00
|
|
|
return "";
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (this._findEndTagInLine(session, row, tag.tagName, tag.end.column))
|
2012-07-05 06:37:09 +00:00
|
|
|
return "";
|
|
|
|
|
|
|
|
return "start";
|
|
|
|
};
|
|
|
|
this._getFirstTagInLine = function(session, row) {
|
|
|
|
var tokens = session.getTokens(row);
|
2014-04-29 09:03:14 +00:00
|
|
|
var tag = new Tag();
|
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
var token = tokens[i];
|
2014-04-29 09:03:14 +00:00
|
|
|
if (is(token, "tag-open")) {
|
|
|
|
tag.end.column = tag.start.column + token.value.length;
|
|
|
|
tag.closing = is(token, "end-tag-open");
|
|
|
|
token = tokens[++i];
|
|
|
|
if (!token)
|
|
|
|
return null;
|
|
|
|
tag.tagName = token.value;
|
|
|
|
tag.end.column += token.value.length;
|
|
|
|
for (i++; i < tokens.length; i++) {
|
|
|
|
token = tokens[i];
|
|
|
|
tag.end.column += token.value.length;
|
|
|
|
if (is(token, "tag-close")) {
|
|
|
|
tag.selfClosing = token.value == '/>';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tag;
|
|
|
|
} else if (is(token, "tag-close")) {
|
|
|
|
tag.selfClosing = token.value == '/>';
|
|
|
|
return tag;
|
|
|
|
}
|
|
|
|
tag.start.column += token.value.length;
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
2014-04-29 09:03:14 +00:00
|
|
|
|
|
|
|
return null;
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
this._findEndTagInLine = function(session, row, tagName, startColumn) {
|
|
|
|
var tokens = session.getTokens(row);
|
2013-12-30 15:00:16 +00:00
|
|
|
var column = 0;
|
2014-04-29 09:03:14 +00:00
|
|
|
for (var i = 0; i < tokens.length; i++) {
|
|
|
|
var token = tokens[i];
|
|
|
|
column += token.value.length;
|
|
|
|
if (column < startColumn)
|
|
|
|
continue;
|
|
|
|
if (is(token, "end-tag-open")) {
|
|
|
|
token = tokens[i + 1];
|
|
|
|
if (token && token.value == tagName)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
this._readTagForward = function(iterator) {
|
|
|
|
var token = iterator.getCurrentToken();
|
|
|
|
if (!token)
|
|
|
|
return null;
|
2014-04-29 09:03:14 +00:00
|
|
|
|
|
|
|
var tag = new Tag();
|
2012-07-05 06:37:09 +00:00
|
|
|
do {
|
2014-04-29 09:03:14 +00:00
|
|
|
if (is(token, "tag-open")) {
|
|
|
|
tag.closing = is(token, "end-tag-open");
|
|
|
|
tag.start.row = iterator.getCurrentTokenRow();
|
|
|
|
tag.start.column = iterator.getCurrentTokenColumn();
|
|
|
|
} else if (is(token, "tag-name")) {
|
|
|
|
tag.tagName = token.value;
|
|
|
|
} else if (is(token, "tag-close")) {
|
|
|
|
tag.selfClosing = token.value == "/>";
|
|
|
|
tag.end.row = iterator.getCurrentTokenRow();
|
|
|
|
tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
|
|
|
|
iterator.stepForward();
|
|
|
|
return tag;
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
} while(token = iterator.stepForward());
|
2014-04-29 09:03:14 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
this._readTagBackward = function(iterator) {
|
|
|
|
var token = iterator.getCurrentToken();
|
|
|
|
if (!token)
|
|
|
|
return null;
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
var tag = new Tag();
|
2012-07-05 06:37:09 +00:00
|
|
|
do {
|
2014-04-29 09:03:14 +00:00
|
|
|
if (is(token, "tag-open")) {
|
|
|
|
tag.closing = is(token, "end-tag-open");
|
|
|
|
tag.start.row = iterator.getCurrentTokenRow();
|
|
|
|
tag.start.column = iterator.getCurrentTokenColumn();
|
|
|
|
iterator.stepBackward();
|
|
|
|
return tag;
|
|
|
|
} else if (is(token, "tag-name")) {
|
|
|
|
tag.tagName = token.value;
|
|
|
|
} else if (is(token, "tag-close")) {
|
|
|
|
tag.selfClosing = token.value == "/>";
|
|
|
|
tag.end.row = iterator.getCurrentTokenRow();
|
|
|
|
tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
} while(token = iterator.stepBackward());
|
2014-04-29 09:03:14 +00:00
|
|
|
|
2012-07-05 06:37:09 +00:00
|
|
|
return null;
|
|
|
|
};
|
|
|
|
|
|
|
|
this._pop = function(stack, tag) {
|
|
|
|
while (stack.length) {
|
|
|
|
|
|
|
|
var top = stack[stack.length-1];
|
|
|
|
if (!tag || top.tagName == tag.tagName) {
|
|
|
|
return stack.pop();
|
|
|
|
}
|
2014-04-29 09:03:14 +00:00
|
|
|
else if (this.voidElements.hasOwnProperty(tag.tagName)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
return;
|
|
|
|
}
|
2014-04-29 09:03:14 +00:00
|
|
|
else if (this.voidElements.hasOwnProperty(top.tagName)) {
|
2012-07-05 06:37:09 +00:00
|
|
|
stack.pop();
|
|
|
|
continue;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.getFoldWidgetRange = function(session, foldStyle, row) {
|
|
|
|
var firstTag = this._getFirstTagInLine(session, row);
|
|
|
|
|
2014-04-29 09:03:14 +00:00
|
|
|
if (!firstTag)
|
2012-07-05 06:37:09 +00:00
|
|
|
return null;
|
|
|
|
|
|
|
|
var isBackward = firstTag.closing || firstTag.selfClosing;
|
|
|
|
var stack = [];
|
|
|
|
var tag;
|
|
|
|
|
|
|
|
if (!isBackward) {
|
2014-04-29 09:03:14 +00:00
|
|
|
var iterator = new TokenIterator(session, row, firstTag.start.column);
|
2012-07-05 06:37:09 +00:00
|
|
|
var start = {
|
|
|
|
row: row,
|
2014-04-29 09:03:14 +00:00
|
|
|
column: firstTag.start.column + firstTag.tagName.length + 2
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
while (tag = this._readTagForward(iterator)) {
|
|
|
|
if (tag.selfClosing) {
|
|
|
|
if (!stack.length) {
|
|
|
|
tag.start.column += tag.tagName.length + 2;
|
|
|
|
tag.end.column -= 2;
|
|
|
|
return Range.fromPoints(tag.start, tag.end);
|
|
|
|
} else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (tag.closing) {
|
|
|
|
this._pop(stack, tag);
|
|
|
|
if (stack.length == 0)
|
|
|
|
return Range.fromPoints(start, tag.start);
|
|
|
|
}
|
|
|
|
else {
|
2014-04-29 09:03:14 +00:00
|
|
|
stack.push(tag);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-04-29 09:03:14 +00:00
|
|
|
var iterator = new TokenIterator(session, row, firstTag.end.column);
|
2012-07-05 06:37:09 +00:00
|
|
|
var end = {
|
|
|
|
row: row,
|
2014-04-29 09:03:14 +00:00
|
|
|
column: firstTag.start.column
|
2012-07-05 06:37:09 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
while (tag = this._readTagBackward(iterator)) {
|
|
|
|
if (tag.selfClosing) {
|
|
|
|
if (!stack.length) {
|
|
|
|
tag.start.column += tag.tagName.length + 2;
|
|
|
|
tag.end.column -= 2;
|
|
|
|
return Range.fromPoints(tag.start, tag.end);
|
|
|
|
} else
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tag.closing) {
|
|
|
|
this._pop(stack, tag);
|
|
|
|
if (stack.length == 0) {
|
|
|
|
tag.start.column += tag.tagName.length + 2;
|
|
|
|
return Range.fromPoints(tag.start, end);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-04-29 09:03:14 +00:00
|
|
|
stack.push(tag);
|
2012-07-05 06:37:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(FoldMode.prototype);
|
|
|
|
|
|
|
|
});
|