Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/htmlmixe...
File: htmlmixed.js
// CodeMirror, copyright (c) by Marijn Haverbeke and others
[0] Fix | Delete
// Distributed under an MIT license: http://codemirror.net/LICENSE
[1] Fix | Delete
[2] Fix | Delete
(function(mod) {
[3] Fix | Delete
if (typeof exports == "object" && typeof module == "object") // CommonJS
[4] Fix | Delete
mod(require("../../lib/codemirror"), require("../xml/xml"), require("../javascript/javascript"), require("../css/css"));
[5] Fix | Delete
else if (typeof define == "function" && define.amd) // AMD
[6] Fix | Delete
define(["../../lib/codemirror", "../xml/xml", "../javascript/javascript", "../css/css"], mod);
[7] Fix | Delete
else // Plain browser env
[8] Fix | Delete
mod(CodeMirror);
[9] Fix | Delete
})(function(CodeMirror) {
[10] Fix | Delete
"use strict";
[11] Fix | Delete
[12] Fix | Delete
var defaultTags = {
[13] Fix | Delete
script: [
[14] Fix | Delete
["lang", /(javascript|babel)/i, "javascript"],
[15] Fix | Delete
["type", /^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^$/i, "javascript"],
[16] Fix | Delete
["type", /./, "text/plain"],
[17] Fix | Delete
[null, null, "javascript"]
[18] Fix | Delete
],
[19] Fix | Delete
style: [
[20] Fix | Delete
["lang", /^css$/i, "css"],
[21] Fix | Delete
["type", /^(text\/)?(x-)?(stylesheet|css)$/i, "css"],
[22] Fix | Delete
["type", /./, "text/plain"],
[23] Fix | Delete
[null, null, "css"]
[24] Fix | Delete
]
[25] Fix | Delete
};
[26] Fix | Delete
[27] Fix | Delete
function maybeBackup(stream, pat, style) {
[28] Fix | Delete
var cur = stream.current(), close = cur.search(pat);
[29] Fix | Delete
if (close > -1) {
[30] Fix | Delete
stream.backUp(cur.length - close);
[31] Fix | Delete
} else if (cur.match(/<\/?$/)) {
[32] Fix | Delete
stream.backUp(cur.length);
[33] Fix | Delete
if (!stream.match(pat, false)) stream.match(cur);
[34] Fix | Delete
}
[35] Fix | Delete
return style;
[36] Fix | Delete
}
[37] Fix | Delete
[38] Fix | Delete
var attrRegexpCache = {};
[39] Fix | Delete
function getAttrRegexp(attr) {
[40] Fix | Delete
var regexp = attrRegexpCache[attr];
[41] Fix | Delete
if (regexp) return regexp;
[42] Fix | Delete
return attrRegexpCache[attr] = new RegExp("\\s+" + attr + "\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*");
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
function getAttrValue(text, attr) {
[46] Fix | Delete
var match = text.match(getAttrRegexp(attr))
[47] Fix | Delete
return match ? /^\s*(.*?)\s*$/.exec(match[2])[1] : ""
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
function getTagRegexp(tagName, anchored) {
[51] Fix | Delete
return new RegExp((anchored ? "^" : "") + "<\/\s*" + tagName + "\s*>", "i");
[52] Fix | Delete
}
[53] Fix | Delete
[54] Fix | Delete
function addTags(from, to) {
[55] Fix | Delete
for (var tag in from) {
[56] Fix | Delete
var dest = to[tag] || (to[tag] = []);
[57] Fix | Delete
var source = from[tag];
[58] Fix | Delete
for (var i = source.length - 1; i >= 0; i--)
[59] Fix | Delete
dest.unshift(source[i])
[60] Fix | Delete
}
[61] Fix | Delete
}
[62] Fix | Delete
[63] Fix | Delete
function findMatchingMode(tagInfo, tagText) {
[64] Fix | Delete
for (var i = 0; i < tagInfo.length; i++) {
[65] Fix | Delete
var spec = tagInfo[i];
[66] Fix | Delete
if (!spec[0] || spec[1].test(getAttrValue(tagText, spec[0]))) return spec[2];
[67] Fix | Delete
}
[68] Fix | Delete
}
[69] Fix | Delete
[70] Fix | Delete
CodeMirror.defineMode("htmlmixed", function (config, parserConfig) {
[71] Fix | Delete
var htmlMode = CodeMirror.getMode(config, {
[72] Fix | Delete
name: "xml",
[73] Fix | Delete
htmlMode: true,
[74] Fix | Delete
multilineTagIndentFactor: parserConfig.multilineTagIndentFactor,
[75] Fix | Delete
multilineTagIndentPastTag: parserConfig.multilineTagIndentPastTag
[76] Fix | Delete
});
[77] Fix | Delete
[78] Fix | Delete
var tags = {};
[79] Fix | Delete
var configTags = parserConfig && parserConfig.tags, configScript = parserConfig && parserConfig.scriptTypes;
[80] Fix | Delete
addTags(defaultTags, tags);
[81] Fix | Delete
if (configTags) addTags(configTags, tags);
[82] Fix | Delete
if (configScript) for (var i = configScript.length - 1; i >= 0; i--)
[83] Fix | Delete
tags.script.unshift(["type", configScript[i].matches, configScript[i].mode])
[84] Fix | Delete
[85] Fix | Delete
function html(stream, state) {
[86] Fix | Delete
var style = htmlMode.token(stream, state.htmlState), tag = /\btag\b/.test(style), tagName
[87] Fix | Delete
if (tag && !/[<>\s\/]/.test(stream.current()) &&
[88] Fix | Delete
(tagName = state.htmlState.tagName && state.htmlState.tagName.toLowerCase()) &&
[89] Fix | Delete
tags.hasOwnProperty(tagName)) {
[90] Fix | Delete
state.inTag = tagName + " "
[91] Fix | Delete
} else if (state.inTag && tag && />$/.test(stream.current())) {
[92] Fix | Delete
var inTag = /^([\S]+) (.*)/.exec(state.inTag)
[93] Fix | Delete
state.inTag = null
[94] Fix | Delete
var modeSpec = stream.current() == ">" && findMatchingMode(tags[inTag[1]], inTag[2])
[95] Fix | Delete
var mode = CodeMirror.getMode(config, modeSpec)
[96] Fix | Delete
var endTagA = getTagRegexp(inTag[1], true), endTag = getTagRegexp(inTag[1], false);
[97] Fix | Delete
state.token = function (stream, state) {
[98] Fix | Delete
if (stream.match(endTagA, false)) {
[99] Fix | Delete
state.token = html;
[100] Fix | Delete
state.localState = state.localMode = null;
[101] Fix | Delete
return null;
[102] Fix | Delete
}
[103] Fix | Delete
return maybeBackup(stream, endTag, state.localMode.token(stream, state.localState));
[104] Fix | Delete
};
[105] Fix | Delete
state.localMode = mode;
[106] Fix | Delete
state.localState = CodeMirror.startState(mode, htmlMode.indent(state.htmlState, ""));
[107] Fix | Delete
} else if (state.inTag) {
[108] Fix | Delete
state.inTag += stream.current()
[109] Fix | Delete
if (stream.eol()) state.inTag += " "
[110] Fix | Delete
}
[111] Fix | Delete
return style;
[112] Fix | Delete
};
[113] Fix | Delete
[114] Fix | Delete
return {
[115] Fix | Delete
startState: function () {
[116] Fix | Delete
var state = CodeMirror.startState(htmlMode);
[117] Fix | Delete
return {token: html, inTag: null, localMode: null, localState: null, htmlState: state};
[118] Fix | Delete
},
[119] Fix | Delete
[120] Fix | Delete
copyState: function (state) {
[121] Fix | Delete
var local;
[122] Fix | Delete
if (state.localState) {
[123] Fix | Delete
local = CodeMirror.copyState(state.localMode, state.localState);
[124] Fix | Delete
}
[125] Fix | Delete
return {token: state.token, inTag: state.inTag,
[126] Fix | Delete
localMode: state.localMode, localState: local,
[127] Fix | Delete
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
[128] Fix | Delete
},
[129] Fix | Delete
[130] Fix | Delete
token: function (stream, state) {
[131] Fix | Delete
return state.token(stream, state);
[132] Fix | Delete
},
[133] Fix | Delete
[134] Fix | Delete
indent: function (state, textAfter) {
[135] Fix | Delete
if (!state.localMode || /^\s*<\//.test(textAfter))
[136] Fix | Delete
return htmlMode.indent(state.htmlState, textAfter);
[137] Fix | Delete
else if (state.localMode.indent)
[138] Fix | Delete
return state.localMode.indent(state.localState, textAfter);
[139] Fix | Delete
else
[140] Fix | Delete
return CodeMirror.Pass;
[141] Fix | Delete
},
[142] Fix | Delete
[143] Fix | Delete
innerMode: function (state) {
[144] Fix | Delete
return {state: state.localState || state.htmlState, mode: state.localMode || htmlMode};
[145] Fix | Delete
}
[146] Fix | Delete
};
[147] Fix | Delete
}, "xml", "javascript", "css");
[148] Fix | Delete
[149] Fix | Delete
CodeMirror.defineMIME("text/html", "htmlmixed");
[150] Fix | Delete
});
[151] Fix | Delete
[152] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function