// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: http://codemirror.net/LICENSE
if (typeof exports == "object" && typeof module == "object") // CommonJS
mod(require("../../lib/codemirror"));
else if (typeof define == "function" && define.amd) // AMD
define(["../../lib/codemirror"], mod);
else // Plain browser env
})(function(CodeMirror) {
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,
'track': true, 'wbr': true, 'menuitem': true},
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,
'dd': {'dd': true, 'dt': true},
'dt': {'dd': true, 'dt': true},
'option': {'option': true, 'optgroup': true},
'optgroup': {'optgroup': true},
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,
'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},
'rp': {'rp': true, 'rt': true},
'rt': {'rp': true, 'rt': true},
'tbody': {'tbody': true, 'tfoot': true},
'td': {'td': true, 'th': true},
'tfoot': {'tbody': true},
'th': {'td': true, 'th': true},
'thead': {'tbody': true, 'tfoot': true},
doNotIndent: {"pre": true},
CodeMirror.defineMode("xml", function(editorConf, config_) {
var indentUnit = editorConf.indentUnit
var defaults = config_.htmlMode ? htmlConfig : xmlConfig
for (var prop in defaults) config[prop] = defaults[prop]
for (var prop in config_) config[prop] = config_[prop]
// Return variables for tokenizers
function inText(stream, state) {
return parser(stream, state);
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
} else if (stream.match("--")) {
return chain(inBlock("comment", "-->"));
} else if (stream.match("DOCTYPE", true, true)) {
stream.eatWhile(/[\w\._\-]/);
return chain(doctype(1));
} else if (stream.eat("?")) {
stream.eatWhile(/[\w\._\-]/);
state.tokenize = inBlock("meta", "?>");
type = stream.eat("/") ? "closeTag" : "openTag";
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");
ok = stream.eatWhile(/[\d]/) && stream.eat(";");
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");
return ok ? "atom" : "error";
stream.eatWhile(/[^&<]/);
function inTag(stream, state) {
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
type = ch == ">" ? "endTag" : "selfcloseTag";
state.tagName = state.tagStart = null;
var next = state.tokenize(stream, state);
return next ? next + " tag error" : "tag error";
} else if (/[\'\"]/.test(ch)) {
state.tokenize = inAttribute(ch);
state.stringStartCol = stream.column();
return state.tokenize(stream, state);
stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);
function inAttribute(quote) {
var closure = function(stream, state) {
if (stream.next() == quote) {
closure.isInAttribute = true;
function inBlock(style, terminator) {
return function(stream, state) {
if (stream.match(terminator)) {
function doctype(depth) {
return function(stream, state) {
while ((ch = stream.next()) != null) {
state.tokenize = doctype(depth + 1);
return state.tokenize(stream, state);
state.tokenize = doctype(depth - 1);
return state.tokenize(stream, state);
function Context(state, tagName, startOfLine) {
this.prev = state.context;
this.indent = state.indented;
this.startOfLine = startOfLine;
if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))
function popContext(state) {
if (state.context) state.context = state.context.prev;
function maybePopContext(state, nextTagName) {
parentTagName = state.context.tagName;
if (!config.contextGrabbers.hasOwnProperty(parentTagName) ||
!config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) {
function baseState(type, stream, state) {
state.tagStart = stream.column();
} else if (type == "closeTag") {
return closeTagNameState;
function tagNameState(type, stream, state) {
state.tagName = stream.current();
function closeTagNameState(type, stream, state) {
var tagName = stream.current();
if (state.context && state.context.tagName != tagName &&
config.implicitlyClosed.hasOwnProperty(state.context.tagName))
if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {
function closeState(type, _stream, state) {
function closeStateErr(type, stream, state) {
return closeState(type, stream, state);
function attrState(type, _stream, state) {
} else if (type == "endTag" || type == "selfcloseTag") {
var tagName = state.tagName, tagStart = state.tagStart;
state.tagName = state.tagStart = null;
if (type == "selfcloseTag" ||
config.autoSelfClosers.hasOwnProperty(tagName)) {
maybePopContext(state, tagName);
maybePopContext(state, tagName);
state.context = new Context(state, tagName, tagStart == state.indented);
function attrEqState(type, stream, state) {
if (type == "equals") return attrValueState;
if (!config.allowMissing) setStyle = "error";
return attrState(type, stream, state);
function attrValueState(type, stream, state) {
if (type == "string") return attrContinuedState;
if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}
return attrState(type, stream, state);
function attrContinuedState(type, stream, state) {
if (type == "string") return attrContinuedState;
return attrState(type, stream, state);
startState: function(baseIndent) {
var state = {tokenize: inText,
indented: baseIndent || 0,
tagName: null, tagStart: null,
if (baseIndent != null) state.baseIndent = baseIndent
token: function(stream, state) {
if (!state.tagName && stream.sol())
state.indented = stream.indentation();
if (stream.eatSpace()) return null;
var style = state.tokenize(stream, state);
if ((style || type) && style != "comment") {
state.state = state.state(type || style, stream, state);
style = setStyle == "error" ? style + " error" : setStyle;
indent: function(state, textAfter, fullLine) {
var context = state.context;
// Indent multi-line strings (e.g. css).
if (state.tokenize.isInAttribute) {
if (state.tagStart == state.indented)
return state.stringStartCol + 1;
return state.indented + indentUnit;
if (context && context.noIndent) return CodeMirror.Pass;
if (state.tokenize != inTag && state.tokenize != inText)
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
// Indent the starts of attribute names.
if (config.multilineTagIndentPastTag !== false)
return state.tagStart + state.tagName.length + 2;
return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);
if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);
if (tagAfter && tagAfter[1]) { // Closing tag spotted
if (context.tagName == tagAfter[2]) {
} else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) {
} else if (tagAfter) { // Opening tag spotted
var grabbers = config.contextGrabbers[context.tagName];
if (grabbers && grabbers.hasOwnProperty(tagAfter[2]))
while (context && context.prev && !context.startOfLine)
if (context) return context.indent + indentUnit;
else return state.baseIndent || 0;
electricInput: /<\/[\s\w:]+>$/,
blockCommentStart: "<!--",
configuration: config.htmlMode ? "html" : "xml",
helperType: config.htmlMode ? "html" : "xml",
skipAttribute: function(state) {
if (state.state == attrValueState)
CodeMirror.defineMIME("text/xml", "xml");
CodeMirror.defineMIME("application/xml", "xml");
if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});