LaravelTest
417 строк · 13.0 Кб
1// CodeMirror, copyright (c) by Marijn Haverbeke and others
2// Distributed under an MIT license: https://codemirror.net/LICENSE
3
4(function(mod) {5if (typeof exports == "object" && typeof module == "object") // CommonJS6mod(require("../../lib/codemirror"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var htmlConfig = {15autoSelfClosers: {'area': true, 'base': true, 'br': true, 'col': true, 'command': true,16'embed': true, 'frame': true, 'hr': true, 'img': true, 'input': true,17'keygen': true, 'link': true, 'meta': true, 'param': true, 'source': true,18'track': true, 'wbr': true, 'menuitem': true},19implicitlyClosed: {'dd': true, 'li': true, 'optgroup': true, 'option': true, 'p': true,20'rp': true, 'rt': true, 'tbody': true, 'td': true, 'tfoot': true,21'th': true, 'tr': true},22contextGrabbers: {23'dd': {'dd': true, 'dt': true},24'dt': {'dd': true, 'dt': true},25'li': {'li': true},26'option': {'option': true, 'optgroup': true},27'optgroup': {'optgroup': true},28'p': {'address': true, 'article': true, 'aside': true, 'blockquote': true, 'dir': true,29'div': true, 'dl': true, 'fieldset': true, 'footer': true, 'form': true,30'h1': true, 'h2': true, 'h3': true, 'h4': true, 'h5': true, 'h6': true,31'header': true, 'hgroup': true, 'hr': true, 'menu': true, 'nav': true, 'ol': true,32'p': true, 'pre': true, 'section': true, 'table': true, 'ul': true},33'rp': {'rp': true, 'rt': true},34'rt': {'rp': true, 'rt': true},35'tbody': {'tbody': true, 'tfoot': true},36'td': {'td': true, 'th': true},37'tfoot': {'tbody': true},38'th': {'td': true, 'th': true},39'thead': {'tbody': true, 'tfoot': true},40'tr': {'tr': true}41},42doNotIndent: {"pre": true},43allowUnquoted: true,44allowMissing: true,45caseFold: true46}
47
48var xmlConfig = {49autoSelfClosers: {},50implicitlyClosed: {},51contextGrabbers: {},52doNotIndent: {},53allowUnquoted: false,54allowMissing: false,55allowMissingTagName: false,56caseFold: false57}
58
59CodeMirror.defineMode("xml", function(editorConf, config_) {60var indentUnit = editorConf.indentUnit61var config = {}62var defaults = config_.htmlMode ? htmlConfig : xmlConfig63for (var prop in defaults) config[prop] = defaults[prop]64for (var prop in config_) config[prop] = config_[prop]65
66// Return variables for tokenizers67var type, setStyle;68
69function inText(stream, state) {70function chain(parser) {71state.tokenize = parser;72return parser(stream, state);73}74
75var ch = stream.next();76if (ch == "<") {77if (stream.eat("!")) {78if (stream.eat("[")) {79if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));80else return null;81} else if (stream.match("--")) {82return chain(inBlock("comment", "-->"));83} else if (stream.match("DOCTYPE", true, true)) {84stream.eatWhile(/[\w\._\-]/);85return chain(doctype(1));86} else {87return null;88}89} else if (stream.eat("?")) {90stream.eatWhile(/[\w\._\-]/);91state.tokenize = inBlock("meta", "?>");92return "meta";93} else {94type = stream.eat("/") ? "closeTag" : "openTag";95state.tokenize = inTag;96return "tag bracket";97}98} else if (ch == "&") {99var ok;100if (stream.eat("#")) {101if (stream.eat("x")) {102ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";");103} else {104ok = stream.eatWhile(/[\d]/) && stream.eat(";");105}106} else {107ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";");108}109return ok ? "atom" : "error";110} else {111stream.eatWhile(/[^&<]/);112return null;113}114}115inText.isInText = true;116
117function inTag(stream, state) {118var ch = stream.next();119if (ch == ">" || (ch == "/" && stream.eat(">"))) {120state.tokenize = inText;121type = ch == ">" ? "endTag" : "selfcloseTag";122return "tag bracket";123} else if (ch == "=") {124type = "equals";125return null;126} else if (ch == "<") {127state.tokenize = inText;128state.state = baseState;129state.tagName = state.tagStart = null;130var next = state.tokenize(stream, state);131return next ? next + " tag error" : "tag error";132} else if (/[\'\"]/.test(ch)) {133state.tokenize = inAttribute(ch);134state.stringStartCol = stream.column();135return state.tokenize(stream, state);136} else {137stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/);138return "word";139}140}141
142function inAttribute(quote) {143var closure = function(stream, state) {144while (!stream.eol()) {145if (stream.next() == quote) {146state.tokenize = inTag;147break;148}149}150return "string";151};152closure.isInAttribute = true;153return closure;154}155
156function inBlock(style, terminator) {157return function(stream, state) {158while (!stream.eol()) {159if (stream.match(terminator)) {160state.tokenize = inText;161break;162}163stream.next();164}165return style;166}167}168
169function doctype(depth) {170return function(stream, state) {171var ch;172while ((ch = stream.next()) != null) {173if (ch == "<") {174state.tokenize = doctype(depth + 1);175return state.tokenize(stream, state);176} else if (ch == ">") {177if (depth == 1) {178state.tokenize = inText;179break;180} else {181state.tokenize = doctype(depth - 1);182return state.tokenize(stream, state);183}184}185}186return "meta";187};188}189
190function lower(tagName) {191return tagName && tagName.toLowerCase();192}193
194function Context(state, tagName, startOfLine) {195this.prev = state.context;196this.tagName = tagName || "";197this.indent = state.indented;198this.startOfLine = startOfLine;199if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent))200this.noIndent = true;201}202function popContext(state) {203if (state.context) state.context = state.context.prev;204}205function maybePopContext(state, nextTagName) {206var parentTagName;207while (true) {208if (!state.context) {209return;210}211parentTagName = state.context.tagName;212if (!config.contextGrabbers.hasOwnProperty(lower(parentTagName)) ||213!config.contextGrabbers[lower(parentTagName)].hasOwnProperty(lower(nextTagName))) {214return;215}216popContext(state);217}218}219
220function baseState(type, stream, state) {221if (type == "openTag") {222state.tagStart = stream.column();223return tagNameState;224} else if (type == "closeTag") {225return closeTagNameState;226} else {227return baseState;228}229}230function tagNameState(type, stream, state) {231if (type == "word") {232state.tagName = stream.current();233setStyle = "tag";234return attrState;235} else if (config.allowMissingTagName && type == "endTag") {236setStyle = "tag bracket";237return attrState(type, stream, state);238} else {239setStyle = "error";240return tagNameState;241}242}243function closeTagNameState(type, stream, state) {244if (type == "word") {245var tagName = stream.current();246if (state.context && state.context.tagName != tagName &&247config.implicitlyClosed.hasOwnProperty(lower(state.context.tagName)))248popContext(state);249if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) {250setStyle = "tag";251return closeState;252} else {253setStyle = "tag error";254return closeStateErr;255}256} else if (config.allowMissingTagName && type == "endTag") {257setStyle = "tag bracket";258return closeState(type, stream, state);259} else {260setStyle = "error";261return closeStateErr;262}263}264
265function closeState(type, _stream, state) {266if (type != "endTag") {267setStyle = "error";268return closeState;269}270popContext(state);271return baseState;272}273function closeStateErr(type, stream, state) {274setStyle = "error";275return closeState(type, stream, state);276}277
278function attrState(type, _stream, state) {279if (type == "word") {280setStyle = "attribute";281return attrEqState;282} else if (type == "endTag" || type == "selfcloseTag") {283var tagName = state.tagName, tagStart = state.tagStart;284state.tagName = state.tagStart = null;285if (type == "selfcloseTag" ||286config.autoSelfClosers.hasOwnProperty(lower(tagName))) {287maybePopContext(state, tagName);288} else {289maybePopContext(state, tagName);290state.context = new Context(state, tagName, tagStart == state.indented);291}292return baseState;293}294setStyle = "error";295return attrState;296}297function attrEqState(type, stream, state) {298if (type == "equals") return attrValueState;299if (!config.allowMissing) setStyle = "error";300return attrState(type, stream, state);301}302function attrValueState(type, stream, state) {303if (type == "string") return attrContinuedState;304if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;}305setStyle = "error";306return attrState(type, stream, state);307}308function attrContinuedState(type, stream, state) {309if (type == "string") return attrContinuedState;310return attrState(type, stream, state);311}312
313return {314startState: function(baseIndent) {315var state = {tokenize: inText,316state: baseState,317indented: baseIndent || 0,318tagName: null, tagStart: null,319context: null}320if (baseIndent != null) state.baseIndent = baseIndent321return state322},323
324token: function(stream, state) {325if (!state.tagName && stream.sol())326state.indented = stream.indentation();327
328if (stream.eatSpace()) return null;329type = null;330var style = state.tokenize(stream, state);331if ((style || type) && style != "comment") {332setStyle = null;333state.state = state.state(type || style, stream, state);334if (setStyle)335style = setStyle == "error" ? style + " error" : setStyle;336}337return style;338},339
340indent: function(state, textAfter, fullLine) {341var context = state.context;342// Indent multi-line strings (e.g. css).343if (state.tokenize.isInAttribute) {344if (state.tagStart == state.indented)345return state.stringStartCol + 1;346else347return state.indented + indentUnit;348}349if (context && context.noIndent) return CodeMirror.Pass;350if (state.tokenize != inTag && state.tokenize != inText)351return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;352// Indent the starts of attribute names.353if (state.tagName) {354if (config.multilineTagIndentPastTag !== false)355return state.tagStart + state.tagName.length + 2;356else357return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1);358}359if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;360var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter);361if (tagAfter && tagAfter[1]) { // Closing tag spotted362while (context) {363if (context.tagName == tagAfter[2]) {364context = context.prev;365break;366} else if (config.implicitlyClosed.hasOwnProperty(lower(context.tagName))) {367context = context.prev;368} else {369break;370}371}372} else if (tagAfter) { // Opening tag spotted373while (context) {374var grabbers = config.contextGrabbers[lower(context.tagName)];375if (grabbers && grabbers.hasOwnProperty(lower(tagAfter[2])))376context = context.prev;377else378break;379}380}381while (context && context.prev && !context.startOfLine)382context = context.prev;383if (context) return context.indent + indentUnit;384else return state.baseIndent || 0;385},386
387electricInput: /<\/[\s\w:]+>$/,388blockCommentStart: "<!--",389blockCommentEnd: "-->",390
391configuration: config.htmlMode ? "html" : "xml",392helperType: config.htmlMode ? "html" : "xml",393
394skipAttribute: function(state) {395if (state.state == attrValueState)396state.state = attrState397},398
399xmlCurrentTag: function(state) {400return state.tagName ? {name: state.tagName, close: state.type == "closeTag"} : null401},402
403xmlCurrentContext: function(state) {404var context = []405for (var cx = state.context; cx; cx = cx.prev)406context.push(cx.tagName)407return context.reverse()408}409};410});411
412CodeMirror.defineMIME("text/xml", "xml");413CodeMirror.defineMIME("application/xml", "xml");414if (!CodeMirror.mimeModes.hasOwnProperty("text/html"))415CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});416
417});418