LaravelTest
129 строк · 3.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"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var rfc2822 = [15"From", "Sender", "Reply-To", "To", "Cc", "Bcc", "Message-ID",16"In-Reply-To", "References", "Resent-From", "Resent-Sender", "Resent-To",17"Resent-Cc", "Resent-Bcc", "Resent-Message-ID", "Return-Path", "Received"18];19var rfc2822NoEmail = [20"Date", "Subject", "Comments", "Keywords", "Resent-Date"21];22
23CodeMirror.registerHelper("hintWords", "mbox", rfc2822.concat(rfc2822NoEmail));24
25var whitespace = /^[ \t]/;26var separator = /^From /; // See RFC 415527var rfc2822Header = new RegExp("^(" + rfc2822.join("|") + "): ");28var rfc2822HeaderNoEmail = new RegExp("^(" + rfc2822NoEmail.join("|") + "): ");29var header = /^[^:]+:/; // Optional fields defined in RFC 282230var email = /^[^ ]+@[^ ]+/;31var untilEmail = /^.*?(?=[^ ]+?@[^ ]+)/;32var bracketedEmail = /^<.*?>/;33var untilBracketedEmail = /^.*?(?=<.*>)/;34
35function styleForHeader(header) {36if (header === "Subject") return "header";37return "string";38}
39
40function readToken(stream, state) {41if (stream.sol()) {42// From last line43state.inSeparator = false;44if (state.inHeader && stream.match(whitespace)) {45// Header folding46return null;47} else {48state.inHeader = false;49state.header = null;50}51
52if (stream.match(separator)) {53state.inHeaders = true;54state.inSeparator = true;55return "atom";56}57
58var match;59var emailPermitted = false;60if ((match = stream.match(rfc2822HeaderNoEmail)) ||61(emailPermitted = true) && (match = stream.match(rfc2822Header))) {62state.inHeaders = true;63state.inHeader = true;64state.emailPermitted = emailPermitted;65state.header = match[1];66return "atom";67}68
69// Use vim's heuristics: recognize custom headers only if the line is in a70// block of legitimate headers.71if (state.inHeaders && (match = stream.match(header))) {72state.inHeader = true;73state.emailPermitted = true;74state.header = match[1];75return "atom";76}77
78state.inHeaders = false;79stream.skipToEnd();80return null;81}82
83if (state.inSeparator) {84if (stream.match(email)) return "link";85if (stream.match(untilEmail)) return "atom";86stream.skipToEnd();87return "atom";88}89
90if (state.inHeader) {91var style = styleForHeader(state.header);92
93if (state.emailPermitted) {94if (stream.match(bracketedEmail)) return style + " link";95if (stream.match(untilBracketedEmail)) return style;96}97stream.skipToEnd();98return style;99}100
101stream.skipToEnd();102return null;103};104
105CodeMirror.defineMode("mbox", function() {106return {107startState: function() {108return {109// Is in a mbox separator110inSeparator: false,111// Is in a mail header112inHeader: false,113// If bracketed email is permitted. Only applicable when inHeader114emailPermitted: false,115// Name of current header116header: null,117// Is in a region of mail headers118inHeaders: false119};120},121token: readToken,122blankLine: function(state) {123state.inHeaders = state.inSeparator = state.inHeader = false;124}125};126});127
128CodeMirror.defineMIME("application/mbox", "mbox");129});130