Differential D134 Diff 321 branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/xml/xml.js
Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/ckeditor/ckfinder/plugins/fileeditor/codemirror/mode/xml/xml.js
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | LF |
CodeMirror.defineMode("xml", function(config, parserConfig) { | CodeMirror.defineMode("xml", function(config, parserConfig) { | ||||
var indentUnit = config.indentUnit; | var indentUnit = config.indentUnit; | ||||
var Kludges = parserConfig.htmlMode ? { | var Kludges = parserConfig.htmlMode ? { | ||||
autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true, | autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true, | ||||
'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true, | 'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true, | ||||
'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true, | 'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true, | ||||
'track': true, 'wbr': true}, | 'track': true, 'wbr': true}, | ||||
implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true, | implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true, | ||||
'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true, | 'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true, | ||||
'th': true, 'tr': true}, | 'th': true, 'tr': true}, | ||||
contextGrabbers: { | contextGrabbers: { | ||||
'dd': {'dd': true, 'dt': true}, | 'dd': {'dd': true, 'dt': true}, | ||||
'dt': {'dd': true, 'dt': true}, | 'dt': {'dd': true, 'dt': true}, | ||||
'li': {'li': true}, | 'li': {'li': true}, | ||||
'option': {'option': true, 'optgroup': true}, | 'option': {'option': true, 'optgroup': true}, | ||||
'optgroup': {'optgroup': true}, | 'optgroup': {'optgroup': true}, | ||||
'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true, | 'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true, | ||||
'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true, | 'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true, | ||||
'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': 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, | 'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true, | ||||
'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true}, | 'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true}, | ||||
'rp': {'rp': true, 'rt': true}, | 'rp': {'rp': true, 'rt': true}, | ||||
'rt': {'rp': true, 'rt': true}, | 'rt': {'rp': true, 'rt': true}, | ||||
'tbody': {'tbody': true, 'tfoot': true}, | 'tbody': {'tbody': true, 'tfoot': true}, | ||||
'td': {'td': true, 'th': true}, | 'td': {'td': true, 'th': true}, | ||||
'tfoot': {'tbody': true}, | 'tfoot': {'tbody': true}, | ||||
'th': {'td': true, 'th': true}, | 'th': {'td': true, 'th': true}, | ||||
'thead': {'tbody': true, 'tfoot': true}, | 'thead': {'tbody': true, 'tfoot': true}, | ||||
'tr': {'tr': true} | 'tr': {'tr': true} | ||||
}, | }, | ||||
doNotIndent: {"pre": true}, | doNotIndent: {"pre": true}, | ||||
allowUnquoted: true, | allowUnquoted: true, | ||||
allowMissing: false | allowMissing: false | ||||
} : { | } : { | ||||
autoSelfClosers: {}, | autoSelfClosers: {}, | ||||
implicitlyClosed: {}, | implicitlyClosed: {}, | ||||
contextGrabbers: {}, | contextGrabbers: {}, | ||||
doNotIndent: {}, | doNotIndent: {}, | ||||
allowUnquoted: false, | allowUnquoted: false, | ||||
allowMissing: false | allowMissing: false | ||||
}; | }; | ||||
var alignCDATA = parserConfig.alignCDATA; | var alignCDATA = parserConfig.alignCDATA; | ||||
// Return variables for tokenizers | // Return variables for tokenizers | ||||
var tagName, type; | var tagName, type; | ||||
function inText(stream, state) { | function inText(stream, state) { | ||||
function chain(parser) { | function chain(parser) { | ||||
state.tokenize = parser; | state.tokenize = parser; | ||||
return parser(stream, state); | return parser(stream, state); | ||||
} | } | ||||
var ch = stream.next(); | var ch = stream.next(); | ||||
if (ch == "<") { | if (ch == "<") { | ||||
if (stream.eat("!")) { | if (stream.eat("!")) { | ||||
if (stream.eat("[")) { | if (stream.eat("[")) { | ||||
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>")); | if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>")); | ||||
else return null; | else return null; | ||||
} | } | ||||
else if (stream.match("--")) return chain(inBlock("comment", "-->")); | else if (stream.match("--")) return chain(inBlock("comment", "-->")); | ||||
else if (stream.match("DOCTYPE", true, true)) { | else if (stream.match("DOCTYPE", true, true)) { | ||||
stream.eatWhile(/[\w\._\-]/); | stream.eatWhile(/[\w\._\-]/); | ||||
return chain(doctype(1)); | return chain(doctype(1)); | ||||
} | } | ||||
else return null; | else return null; | ||||
} | } | ||||
else if (stream.eat("?")) { | else if (stream.eat("?")) { | ||||
stream.eatWhile(/[\w\._\-]/); | stream.eatWhile(/[\w\._\-]/); | ||||
state.tokenize = inBlock("meta", "?>"); | state.tokenize = inBlock("meta", "?>"); | ||||
return "meta"; | return "meta"; | ||||
} | } | ||||
else { | else { | ||||
type = stream.eat("/") ? "closeTag" : "openTag"; | type = stream.eat("/") ? "closeTag" : "openTag"; | ||||
stream.eatSpace(); | stream.eatSpace(); | ||||
tagName = ""; | tagName = ""; | ||||
var c; | var c; | ||||
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c; | while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c; | ||||
state.tokenize = inTag; | state.tokenize = inTag; | ||||
return "tag"; | return "tag"; | ||||
} | } | ||||
} | } | ||||
else if (ch == "&") { | else if (ch == "&") { | ||||
var ok; | var ok; | ||||
if (stream.eat("#")) { | if (stream.eat("#")) { | ||||
if (stream.eat("x")) { | if (stream.eat("x")) { | ||||
ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); | ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); | ||||
} else { | } else { | ||||
ok = stream.eatWhile(/[\d]/) && stream.eat(";"); | ok = stream.eatWhile(/[\d]/) && stream.eat(";"); | ||||
} | } | ||||
} else { | } else { | ||||
ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";"); | ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";"); | ||||
} | } | ||||
return ok ? "atom" : "error"; | return ok ? "atom" : "error"; | ||||
} | } | ||||
else { | else { | ||||
stream.eatWhile(/[^&<]/); | stream.eatWhile(/[^&<]/); | ||||
return null; | return null; | ||||
} | } | ||||
} | } | ||||
function inTag(stream, state) { | function inTag(stream, state) { | ||||
var ch = stream.next(); | var ch = stream.next(); | ||||
if (ch == ">" || (ch == "/" && stream.eat(">"))) { | if (ch == ">" || (ch == "/" && stream.eat(">"))) { | ||||
state.tokenize = inText; | state.tokenize = inText; | ||||
type = ch == ">" ? "endTag" : "selfcloseTag"; | type = ch == ">" ? "endTag" : "selfcloseTag"; | ||||
return "tag"; | return "tag"; | ||||
} | } | ||||
else if (ch == "=") { | else if (ch == "=") { | ||||
type = "equals"; | type = "equals"; | ||||
return null; | return null; | ||||
} | } | ||||
else if (/[\'\"]/.test(ch)) { | else if (/[\'\"]/.test(ch)) { | ||||
state.tokenize = inAttribute(ch); | state.tokenize = inAttribute(ch); | ||||
return state.tokenize(stream, state); | return state.tokenize(stream, state); | ||||
} | } | ||||
else { | else { | ||||
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/); | stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/); | ||||
return "word"; | return "word"; | ||||
} | } | ||||
} | } | ||||
function inAttribute(quote) { | function inAttribute(quote) { | ||||
return function(stream, state) { | return function(stream, state) { | ||||
while (!stream.eol()) { | while (!stream.eol()) { | ||||
if (stream.next() == quote) { | if (stream.next() == quote) { | ||||
state.tokenize = inTag; | state.tokenize = inTag; | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
return "string"; | return "string"; | ||||
}; | }; | ||||
} | } | ||||
function inBlock(style, terminator) { | function inBlock(style, terminator) { | ||||
return function(stream, state) { | return function(stream, state) { | ||||
while (!stream.eol()) { | while (!stream.eol()) { | ||||
if (stream.match(terminator)) { | if (stream.match(terminator)) { | ||||
state.tokenize = inText; | state.tokenize = inText; | ||||
break; | break; | ||||
} | } | ||||
stream.next(); | stream.next(); | ||||
} | } | ||||
return style; | return style; | ||||
}; | }; | ||||
} | } | ||||
function doctype(depth) { | function doctype(depth) { | ||||
return function(stream, state) { | return function(stream, state) { | ||||
var ch; | var ch; | ||||
while ((ch = stream.next()) != null) { | while ((ch = stream.next()) != null) { | ||||
if (ch == "<") { | if (ch == "<") { | ||||
state.tokenize = doctype(depth + 1); | state.tokenize = doctype(depth + 1); | ||||
return state.tokenize(stream, state); | return state.tokenize(stream, state); | ||||
} else if (ch == ">") { | } else if (ch == ">") { | ||||
if (depth == 1) { | if (depth == 1) { | ||||
state.tokenize = inText; | state.tokenize = inText; | ||||
break; | break; | ||||
} else { | } else { | ||||
state.tokenize = doctype(depth - 1); | state.tokenize = doctype(depth - 1); | ||||
return state.tokenize(stream, state); | return state.tokenize(stream, state); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
return "meta"; | return "meta"; | ||||
}; | }; | ||||
} | } | ||||
var curState, setStyle; | var curState, setStyle; | ||||
function pass() { | function pass() { | ||||
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]); | for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]); | ||||
} | } | ||||
function cont() { | function cont() { | ||||
pass.apply(null, arguments); | pass.apply(null, arguments); | ||||
return true; | return true; | ||||
} | } | ||||
function pushContext(tagName, startOfLine) { | function pushContext(tagName, startOfLine) { | ||||
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent); | var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent); | ||||
curState.context = { | curState.context = { | ||||
prev: curState.context, | prev: curState.context, | ||||
tagName: tagName, | tagName: tagName, | ||||
indent: curState.indented, | indent: curState.indented, | ||||
startOfLine: startOfLine, | startOfLine: startOfLine, | ||||
noIndent: noIndent | noIndent: noIndent | ||||
}; | }; | ||||
} | } | ||||
function popContext() { | function popContext() { | ||||
if (curState.context) curState.context = curState.context.prev; | if (curState.context) curState.context = curState.context.prev; | ||||
} | } | ||||
function element(type) { | function element(type) { | ||||
if (type == "openTag") { | if (type == "openTag") { | ||||
curState.tagName = tagName; | curState.tagName = tagName; | ||||
return cont(attributes, endtag(curState.startOfLine)); | return cont(attributes, endtag(curState.startOfLine)); | ||||
} else if (type == "closeTag") { | } else if (type == "closeTag") { | ||||
var err = false; | var err = false; | ||||
if (curState.context) { | if (curState.context) { | ||||
if (curState.context.tagName != tagName) { | if (curState.context.tagName != tagName) { | ||||
if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) { | if (Kludges.implicitlyClosed.hasOwnProperty(curState.context.tagName.toLowerCase())) { | ||||
popContext(); | popContext(); | ||||
} | } | ||||
err = !curState.context || curState.context.tagName != tagName; | err = !curState.context || curState.context.tagName != tagName; | ||||
} | } | ||||
} else { | } else { | ||||
err = true; | err = true; | ||||
} | } | ||||
if (err) setStyle = "error"; | if (err) setStyle = "error"; | ||||
return cont(endclosetag(err)); | return cont(endclosetag(err)); | ||||
} | } | ||||
return cont(); | return cont(); | ||||
} | } | ||||
function endtag(startOfLine) { | function endtag(startOfLine) { | ||||
return function(type) { | return function(type) { | ||||
if (type == "selfcloseTag" || | if (type == "selfcloseTag" || | ||||
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) { | (type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase()))) { | ||||
maybePopContext(curState.tagName.toLowerCase()); | maybePopContext(curState.tagName.toLowerCase()); | ||||
return cont(); | return cont(); | ||||
} | } | ||||
if (type == "endTag") { | if (type == "endTag") { | ||||
maybePopContext(curState.tagName.toLowerCase()); | maybePopContext(curState.tagName.toLowerCase()); | ||||
pushContext(curState.tagName, startOfLine); | pushContext(curState.tagName, startOfLine); | ||||
return cont(); | return cont(); | ||||
} | } | ||||
return cont(); | return cont(); | ||||
}; | }; | ||||
} | } | ||||
function endclosetag(err) { | function endclosetag(err) { | ||||
return function(type) { | return function(type) { | ||||
if (err) setStyle = "error"; | if (err) setStyle = "error"; | ||||
if (type == "endTag") { popContext(); return cont(); } | if (type == "endTag") { popContext(); return cont(); } | ||||
setStyle = "error"; | setStyle = "error"; | ||||
return cont(arguments.callee); | return cont(arguments.callee); | ||||
} | } | ||||
} | } | ||||
function maybePopContext(nextTagName) { | function maybePopContext(nextTagName) { | ||||
var parentTagName; | var parentTagName; | ||||
while (true) { | while (true) { | ||||
if (!curState.context) { | if (!curState.context) { | ||||
return; | return; | ||||
} | } | ||||
parentTagName = curState.context.tagName.toLowerCase(); | parentTagName = curState.context.tagName.toLowerCase(); | ||||
if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) || | if (!Kludges.contextGrabbers.hasOwnProperty(parentTagName) || | ||||
!Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { | !Kludges.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { | ||||
return; | return; | ||||
} | } | ||||
popContext(); | popContext(); | ||||
} | } | ||||
} | } | ||||
function attributes(type) { | function attributes(type) { | ||||
if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);} | if (type == "word") {setStyle = "attribute"; return cont(attribute, attributes);} | ||||
if (type == "endTag" || type == "selfcloseTag") return pass(); | if (type == "endTag" || type == "selfcloseTag") return pass(); | ||||
setStyle = "error"; | setStyle = "error"; | ||||
return cont(attributes); | return cont(attributes); | ||||
} | } | ||||
function attribute(type) { | function attribute(type) { | ||||
if (type == "equals") return cont(attvalue, attributes); | if (type == "equals") return cont(attvalue, attributes); | ||||
if (!Kludges.allowMissing) setStyle = "error"; | if (!Kludges.allowMissing) setStyle = "error"; | ||||
return (type == "endTag" || type == "selfcloseTag") ? pass() : cont(); | return (type == "endTag" || type == "selfcloseTag") ? pass() : cont(); | ||||
} | } | ||||
function attvalue(type) { | function attvalue(type) { | ||||
if (type == "string") return cont(attvaluemaybe); | if (type == "string") return cont(attvaluemaybe); | ||||
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();} | if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();} | ||||
setStyle = "error"; | setStyle = "error"; | ||||
return (type == "endTag" || type == "selfCloseTag") ? pass() : cont(); | return (type == "endTag" || type == "selfCloseTag") ? pass() : cont(); | ||||
} | } | ||||
function attvaluemaybe(type) { | function attvaluemaybe(type) { | ||||
if (type == "string") return cont(attvaluemaybe); | if (type == "string") return cont(attvaluemaybe); | ||||
else return pass(); | else return pass(); | ||||
} | } | ||||
return { | return { | ||||
startState: function() { | startState: function() { | ||||
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null}; | return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null}; | ||||
}, | }, | ||||
token: function(stream, state) { | token: function(stream, state) { | ||||
if (stream.sol()) { | if (stream.sol()) { | ||||
state.startOfLine = true; | state.startOfLine = true; | ||||
state.indented = stream.indentation(); | state.indented = stream.indentation(); | ||||
} | } | ||||
if (stream.eatSpace()) return null; | if (stream.eatSpace()) return null; | ||||
setStyle = type = tagName = null; | setStyle = type = tagName = null; | ||||
var style = state.tokenize(stream, state); | var style = state.tokenize(stream, state); | ||||
state.type = type; | state.type = type; | ||||
if ((style || type) && style != "comment") { | if ((style || type) && style != "comment") { | ||||
curState = state; | curState = state; | ||||
while (true) { | while (true) { | ||||
var comb = state.cc.pop() || element; | var comb = state.cc.pop() || element; | ||||
if (comb(type || style)) break; | if (comb(type || style)) break; | ||||
} | } | ||||
} | } | ||||
state.startOfLine = false; | state.startOfLine = false; | ||||
return setStyle || style; | return setStyle || style; | ||||
}, | }, | ||||
indent: function(state, textAfter, fullLine) { | indent: function(state, textAfter, fullLine) { | ||||
var context = state.context; | var context = state.context; | ||||
if ((state.tokenize != inTag && state.tokenize != inText) || | if ((state.tokenize != inTag && state.tokenize != inText) || | ||||
context && context.noIndent) | context && context.noIndent) | ||||
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; | return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; | ||||
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; | if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; | ||||
if (context && /^<\//.test(textAfter)) | if (context && /^<\//.test(textAfter)) | ||||
context = context.prev; | context = context.prev; | ||||
while (context && !context.startOfLine) | while (context && !context.startOfLine) | ||||
context = context.prev; | context = context.prev; | ||||
if (context) return context.indent + indentUnit; | if (context) return context.indent + indentUnit; | ||||
else return 0; | else return 0; | ||||
}, | }, | ||||
compareStates: function(a, b) { | compareStates: function(a, b) { | ||||
if (a.indented != b.indented || a.tokenize != b.tokenize) return false; | if (a.indented != b.indented || a.tokenize != b.tokenize) return false; | ||||
for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) { | for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) { | ||||
if (!ca || !cb) return ca == cb; | if (!ca || !cb) return ca == cb; | ||||
if (ca.tagName != cb.tagName) return false; | if (ca.tagName != cb.tagName) return false; | ||||
} | } | ||||
}, | }, | ||||
electricChars: "/" | electricChars: "/" | ||||
}; | }; | ||||
}); | }); | ||||
CodeMirror.defineMIME("application/xml", "xml"); | CodeMirror.defineMIME("application/xml", "xml"); | ||||
if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) | if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) | ||||
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); | CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); |