LaravelTest
153 строки · 5.6 Кб
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"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var defaultTags = {15script: [16["lang", /(javascript|babel)/i, "javascript"],17["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i, "javascript"],18["type", /./, "text/plain"],19[null, null, "javascript"]20],21style: [22["lang", /^css$/i, "css"],23["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"],24["type", /./, "text/plain"],25[null, null, "css"]26]27};28
29function maybeBackup(stream, pat, style) {30var cur = stream.current(), close = cur.search(pat);31if (close > -1) {32stream.backUp(cur.length - close);33} else if (cur.match(/<\/?$/)) {34stream.backUp(cur.length);35if (!stream.match(pat, false)) stream.match(cur);36}37return style;38}39
40var attrRegexpCache = {};41function getAttrRegexp(attr) {42var regexp = attrRegexpCache[attr];43if (regexp) return regexp;44return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");45}46
47function getAttrValue(text, attr) {48var match = text.match(getAttrRegexp(attr))49return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : ""50}51
52function getTagRegexp(tagName, anchored) {53return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");54}55
56function addTags(from, to) {57for (var tag in from) {58var dest = to[tag] || (to[tag] = []);59var source = from[tag];60for (var i = source.length - 1; i >= 0; i--)61dest.unshift(source[i])62}63}64
65function findMatchingMode(tagInfo, tagText) {66for (var i = 0; i < tagInfo.length; i++) {67var spec = tagInfo[i];68if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];69}70}71
72CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {73var htmlMode = CodeMirror.getMode(config, {74name: "xml",75htmlMode: true,76multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,77multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag,78allowMissingTagName: parserConfig.allowMissingTagName,79});80
81var tags = {};82var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes;83addTags(defaultTags, tags);84if (configTags) addTags(configTags, tags);85if (configScript) for (var i = configScript.length - 1; i >= 0; i--)86tags.script.unshift(["type", configScript[i].matches, configScript[i].mode])87
88function html(stream, state) {89var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName90if (tag && !/[<>\s\/]/.test(stream.current()) &&91(tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) &&92tags.hasOwnProperty(tagName)) {93state.inTag = tagName + " "94} else if (state.inTag && tag && />$/.test(stream.current())) {95var inTag = /^([\S]+) (.*)/.exec(state.inTag)96state.inTag = null97var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2])98var mode = CodeMirror.getMode(config, modeSpec)99var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false);100state.token = function (stream, state) {101if (stream.match(endTagA, false)) {102state.token = html;103state.localState = state.localMode = null;104return null;105}106return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));107};108state.localMode = mode;109state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, "", ""));110} else if (state.inTag) {111state.inTag += stream.current()112if (stream.eol()) state.inTag += " "113}114return style;115};116
117return {118startState: function () {119var state = CodeMirror.startState(htmlMode);120return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};121},122
123copyState: function (state) {124var local;125if (state.localState) {126local = CodeMirror.copyState(state.localMode, state.localState);127}128return {token: state.token, inTag: state.inTag,129localMode: state.localMode, localState: local,130htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};131},132
133token: function (stream, state) {134return state.token(stream, state);135},136
137indent: function (state, textAfter, line) {138if (!state.localMode || /^\s*<\//.test(textAfter))139return htmlMode.indent(state.htmlState, textAfter, line);140else if (state.localMode.indent)141return state.localMode.indent(state.localState, textAfter, line);142else143return CodeMirror.Pass;144},145
146innerMode: function (state) {147return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};148}149};150}, "xml", "javascript", "css");151
152CodeMirror.defineMIME("text/html", "htmlmixed");153});154