vendor: 12,885 bytes, lines 1-401
1// CodeMirror, copyright (c) by Marijn Haverbeke and others 2// Distributed under an MIT license: http://codemirror.net/LICENSE 3 4(function(mod) { 5 if (typeof exports == "object" && typeof module == "object") // CommonJS 6 mod(require("../../lib/codemirror")); 7 else if (typeof define == "function" && define.amd) // AMD 8 define(["../../lib/codemirror"], mod); 9 else // Plain browser env 10 mod(CodeMirror); 11})(function(CodeMirror) { 12"use strict"; 13 14var htmlConfig = { 15 autoSelfClosers: {'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}, 19 implicitlyClosed: {'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}, 22 contextGrabbers: { 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 }, 42 doNotIndent: {"pre": true}, 43 allowUnquoted: true, 44 allowMissing: true, 45 caseFold: true 46} 47 48var xmlConfig = { 49 autoSelfClosers: {}, 50 implicitlyClosed: {}, 51 contextGrabbers: {}, 52 doNotIndent: {}, 53 allowUnquoted: false, 54 allowMissing: false, 55 allowMissingTagName: false, 56 caseFold: false 57} 58 59CodeMirror.defineMode("xml", function(editorConf, config_) { 60 var indentUnit = editorConf.indentUnit 61 var config = {} 62 var defaults = config_.htmlMode ? htmlConfig : xmlConfig 63 for (var prop in defaults) config[prop] = defaults[prop] 64 for (var prop in config_) config[prop] = config_[prop] 65 66 // Return variables for tokenizers 67 var type, setStyle; 68 69 function inText(stream, state) { 70 function chain(parser) { 71 state.tokenize = parser; 72 return parser(stream, state); 73 } 74 75 var ch = stream.next(); 76 if (ch == "<") { 77 if (stream.eat("!")) { 78 if (stream.eat("[")) { 79 if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>")); 80 else return null; 81 } else if (stream.match("--")) { 82 return chain(inBlock("comment", "-->")); 83 } else if (stream.match("DOCTYPE", true, true)) { 84 stream.eatWhile(/[\w\._\-]/); 85 return chain(doctype(1)); 86 } else { 87 return null; 88 } 89 } else if (stream.eat("?")) { 90 stream.eatWhile(/[\w\._\-]/); 91 state.tokenize = inBlock("meta", "?>"); 92 return "meta"; 93 } else { 94 type = stream.eat("/") ? "closeTag" : "openTag"; 95 state.tokenize = inTag; 96 return "tag bracket"; 97 } 98 } else if (ch == "&") { 99 var ok; 100 if (stream.eat("#")) { 101 if (stream.eat("x")) { 102 ok = stream.eatWhile(/[a-fA-F\d]/) && stream.eat(";"); 103 } else { 104 ok = stream.eatWhile(/[\d]/) && stream.eat(";"); 105 } 106 } else { 107 ok = stream.eatWhile(/[\w\.\-:]/) && stream.eat(";"); 108 } 109 return ok ? "atom" : "error"; 110 } else { 111 stream.eatWhile(/[^&<]/); 112 return null; 113 } 114 } 115 inText.isInText = true; 116 117 function inTag(stream, state) { 118 var ch = stream.next(); 119 if (ch == ">" || (ch == "/" && stream.eat(">"))) { 120 state.tokenize = inText; 121 type = ch == ">" ? "endTag" : "selfcloseTag"; 122 return "tag bracket"; 123 } else if (ch == "=") { 124 type = "equals"; 125 return null; 126 } else if (ch == "<") { 127 state.tokenize = inText; 128 state.state = baseState; 129 state.tagName = state.tagStart = null; 130 var next = state.tokenize(stream, state); 131 return next ? next + " tag error" : "tag error"; 132 } else if (/[\'\"]/.test(ch)) { 133 state.tokenize = inAttribute(ch); 134 state.stringStartCol = stream.column(); 135 return state.tokenize(stream, state); 136 } else { 137 stream.match(/^[^\s\u00a0=<>\"\']*[^\s\u00a0=<>\"\'\/]/); 138 return "word"; 139 } 140 } 141 142 function inAttribute(quote) { 143 var closure = function(stream, state) { 144 while (!stream.eol()) { 145 if (stream.next() == quote) { 146 state.tokenize = inTag; 147 break; 148 } 149 } 150 return "string"; 151 }; 152 closure.isInAttribute = true; 153 return closure; 154 } 155 156 function inBlock(style, terminator) { 157 return function(stream, state) { 158 while (!stream.eol()) { 159 if (stream.match(terminator)) { 160 state.tokenize = inText; 161 break; 162 } 163 stream.next(); 164 } 165 return style; 166 }; 167 } 168 function doctype(depth) { 169 return function(stream, state) { 170 var ch; 171 while ((ch = stream.next()) != null) { 172 if (ch == "<") { 173 state.tokenize = doctype(depth + 1); 174 return state.tokenize(stream, state); 175 } else if (ch == ">") { 176 if (depth == 1) { 177 state.tokenize = inText; 178 break; 179 } else { 180 state.tokenize = doctype(depth - 1); 181 return state.tokenize(stream, state); 182 } 183 } 184 } 185 return "meta"; 186 }; 187 } 188 189 function Context(state, tagName, startOfLine) { 190 this.prev = state.context; 191 this.tagName = tagName; 192 this.indent = state.indented; 193 this.startOfLine = startOfLine; 194 if (config.doNotIndent.hasOwnProperty(tagName) || (state.context && state.context.noIndent)) 195 this.noIndent = true; 196 } 197 function popContext(state) { 198 if (state.context) state.context = state.context.prev; 199 } 200 function maybePopContext(state, nextTagName) { 201 var parentTagName; 202 while (true) { 203 if (!state.context) { 204 return; 205 } 206 parentTagName = state.context.tagName; 207 if (!config.contextGrabbers.hasOwnProperty(parentTagName) || 208 !config.contextGrabbers[parentTagName].hasOwnProperty(nextTagName)) { 209 return; 210 } 211 popContext(state); 212 } 213 } 214 215 function baseState(type, stream, state) { 216 if (type == "openTag") { 217 state.tagStart = stream.column(); 218 return tagNameState; 219 } else if (type == "closeTag") { 220 return closeTagNameState; 221 } else { 222 return baseState; 223 } 224 } 225 function tagNameState(type, stream, state) { 226 if (type == "word") { 227 state.tagName = stream.current(); 228 setStyle = "tag"; 229 return attrState; 230 } else if (config.allowMissingTagName && type == "endTag") { 231 setStyle = "tag bracket"; 232 return attrState(type, stream, state); 233 } else { 234 setStyle = "error"; 235 return tagNameState; 236 } 237 } 238 function closeTagNameState(type, stream, state) { 239 if (type == "word") { 240 var tagName = stream.current(); 241 if (state.context && state.context.tagName != tagName && 242 config.implicitlyClosed.hasOwnProperty(state.context.tagName)) 243 popContext(state); 244 if ((state.context && state.context.tagName == tagName) || config.matchClosing === false) { 245 setStyle = "tag"; 246 return closeState; 247 } else { 248 setStyle = "tag error"; 249 return closeStateErr; 250 } 251 } else if (config.allowMissingTagName && type == "endTag") { 252 setStyle = "tag bracket"; 253 return closeState(type, stream, state); 254 } else { 255 setStyle = "error"; 256 return closeStateErr; 257 } 258 } 259 260 function closeState(type, _stream, state) { 261 if (type != "endTag") { 262 setStyle = "error"; 263 return closeState; 264 } 265 popContext(state); 266 return baseState; 267 } 268 function closeStateErr(type, stream, state) { 269 setStyle = "error"; 270 return closeState(type, stream, state); 271 } 272 273 function attrState(type, _stream, state) { 274 if (type == "word") { 275 setStyle = "attribute"; 276 return attrEqState; 277 } else if (type == "endTag" || type == "selfcloseTag") { 278 var tagName = state.tagName, tagStart = state.tagStart; 279 state.tagName = state.tagStart = null; 280 if (type == "selfcloseTag" || 281 config.autoSelfClosers.hasOwnProperty(tagName)) { 282 maybePopContext(state, tagName); 283 } else { 284 maybePopContext(state, tagName); 285 state.context = new Context(state, tagName, tagStart == state.indented); 286 } 287 return baseState; 288 } 289 setStyle = "error"; 290 return attrState; 291 } 292 function attrEqState(type, stream, state) { 293 if (type == "equals") return attrValueState; 294 if (!config.allowMissing) setStyle = "error"; 295 return attrState(type, stream, state); 296 } 297 function attrValueState(type, stream, state) { 298 if (type == "string") return attrContinuedState; 299 if (type == "word" && config.allowUnquoted) {setStyle = "string"; return attrState;} 300 setStyle = "error"; 301 return attrState(type, stream, state); 302 } 303 function attrContinuedState(type, stream, state) { 304 if (type == "string") return attrContinuedState; 305 return attrState(type, stream, state); 306 } 307 308 return { 309 startState: function(baseIndent) { 310 var state = {tokenize: inText, 311 state: baseState, 312 indented: baseIndent || 0, 313 tagName: null, tagStart: null, 314 context: null} 315 if (baseIndent != null) state.baseIndent = baseIndent 316 return state 317 }, 318 319 token: function(stream, state) { 320 if (!state.tagName && stream.sol()) 321 state.indented = stream.indentation(); 322 323 if (stream.eatSpace()) return null; 324 type = null; 325 var style = state.tokenize(stream, state); 326 if ((style || type) && style != "comment") { 327 setStyle = null; 328 state.state = state.state(type || style, stream, state); 329 if (setStyle) 330 style = setStyle == "error" ? style + " error" : setStyle; 331 } 332 return style; 333 }, 334 335 indent: function(state, textAfter, fullLine) { 336 var context = state.context; 337 // Indent multi-line strings (e.g. css). 338 if (state.tokenize.isInAttribute) { 339 if (state.tagStart == state.indented) 340 return state.stringStartCol + 1; 341 else 342 return state.indented + indentUnit; 343 } 344 if (context && context.noIndent) return CodeMirror.Pass; 345 if (state.tokenize != inTag && state.tokenize != inText) 346 return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0; 347 // Indent the starts of attribute names. 348 if (state.tagName) { 349 if (config.multilineTagIndentPastTag !== false) 350 return state.tagStart + state.tagName.length + 2; 351 else 352 return state.tagStart + indentUnit * (config.multilineTagIndentFactor || 1); 353 } 354 if (config.alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0; 355 var tagAfter = textAfter && /^<(\/)?([\w_:\.-]*)/.exec(textAfter); 356 if (tagAfter && tagAfter[1]) { // Closing tag spotted 357 while (context) { 358 if (context.tagName == tagAfter[2]) { 359 context = context.prev; 360 break; 361 } else if (config.implicitlyClosed.hasOwnProperty(context.tagName)) { 362 context = context.prev; 363 } else { 364 break; 365 } 366 } 367 } else if (tagAfter) { // Opening tag spotted 368 while (context) { 369 var grabbers = config.contextGrabbers[context.tagName]; 370 if (grabbers && grabbers.hasOwnProperty(tagAfter[2])) 371 context = context.prev; 372 else 373 break; 374 } 375 } 376 while (context && context.prev && !context.startOfLine) 377 context = context.prev; 378 if (context) return context.indent + indentUnit; 379 else return state.baseIndent || 0; 380 }, 381 382 electricInput: /<\/[\s\w:]+>$/, 383 blockCommentStart: "<!--", 384 blockCommentEnd: "-->", 385 386 configuration: config.htmlMode ? "html" : "xml", 387 helperType: config.htmlMode ? "html" : "xml", 388 389 skipAttribute: function(state) { 390 if (state.state == attrValueState) 391 state.state = attrState 392 } 393 }; 394}); 395 396CodeMirror.defineMIME("text/xml", "xml"); 397CodeMirror.defineMIME("application/xml", "xml"); 398if (!CodeMirror.mimeModes.hasOwnProperty("text/html")) 399 CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true}); 400 401});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.