LaravelTest
129 строк · 5.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"), require("../markdown/markdown"), require("../../addon/mode/overlay"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../markdown/markdown", "../../addon/mode/overlay"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14var urlRE = /^((?:(?:aaas?|about|acap|adiumxtra|af[ps]|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|cap|chrome(?:-extension)?|cid|coap|com-eventbrite-attendee|content|crid|cvs|data|dav|dict|dlna-(?:playcontainer|playsingle)|dns|doi|dtn|dvb|ed2k|facetime|feed|file|finger|fish|ftp|geo|gg|git|gizmoproject|go|gopher|gtalk|h323|hcp|https?|iax|icap|icon|im|imap|info|ipn|ipp|irc[6s]?|iris(?:\.beep|\.lwz|\.xpc|\.xpcs)?|itms|jar|javascript|jms|keyparc|lastfm|ldaps?|magnet|mailto|maps|market|message|mid|mms|ms-help|msnim|msrps?|mtqp|mumble|mupdate|mvn|news|nfs|nih?|nntp|notes|oid|opaquelocktoken|palm|paparazzi|platform|pop|pres|proxy|psyc|query|res(?:ource)?|rmi|rsync|rtmp|rtsp|secondlife|service|session|sftp|sgn|shttp|sieve|sips?|skype|sm[bs]|snmp|soap\.beeps?|soldat|spotify|ssh|steam|svn|tag|teamspeak|tel(?:net)?|tftp|things|thismessage|tip|tn3270|tv|udp|unreal|urn|ut2004|vemmi|ventrilo|view-source|webcal|wss?|wtai|wyciwyg|xcon(?:-userid)?|xfire|xmlrpc\.beeps?|xmpp|xri|ymsgr|z39\.50[rs]?):(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i15
16CodeMirror.defineMode("gfm", function(config, modeConfig) {17var codeDepth = 0;18function blankLine(state) {19state.code = false;20return null;21}22var gfmOverlay = {23startState: function() {24return {25code: false,26codeBlock: false,27ateSpace: false28};29},30copyState: function(s) {31return {32code: s.code,33codeBlock: s.codeBlock,34ateSpace: s.ateSpace35};36},37token: function(stream, state) {38state.combineTokens = null;39
40// Hack to prevent formatting override inside code blocks (block and inline)41if (state.codeBlock) {42if (stream.match(/^```+/)) {43state.codeBlock = false;44return null;45}46stream.skipToEnd();47return null;48}49if (stream.sol()) {50state.code = false;51}52if (stream.sol() && stream.match(/^```+/)) {53stream.skipToEnd();54state.codeBlock = true;55return null;56}57// If this block is changed, it may need to be updated in Markdown mode58if (stream.peek() === '`') {59stream.next();60var before = stream.pos;61stream.eatWhile('`');62var difference = 1 + stream.pos - before;63if (!state.code) {64codeDepth = difference;65state.code = true;66} else {67if (difference === codeDepth) { // Must be exact68state.code = false;69}70}71return null;72} else if (state.code) {73stream.next();74return null;75}76// Check if space. If so, links can be formatted later on77if (stream.eatSpace()) {78state.ateSpace = true;79return null;80}81if (stream.sol() || state.ateSpace) {82state.ateSpace = false;83if (modeConfig.gitHubSpice !== false) {84if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?=.{0,6}\d)(?:[a-f0-9]{7,40}\b)/)) {85// User/Project@SHA86// User@SHA87// SHA88state.combineTokens = true;89return "link";90} else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {91// User/Project#Num92// User#Num93// #Num94state.combineTokens = true;95return "link";96}97}98}99if (stream.match(urlRE) &&100stream.string.slice(stream.start - 2, stream.start) != "](" &&101(stream.start == 0 || /\W/.test(stream.string.charAt(stream.start - 1)))) {102// URLs103// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls104// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine105// And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL106state.combineTokens = true;107return "link";108}109stream.next();110return null;111},112blankLine: blankLine113};114
115var markdownConfig = {116taskLists: true,117strikethrough: true,118emoji: true119};120for (var attr in modeConfig) {121markdownConfig[attr] = modeConfig[attr];122}123markdownConfig.name = "markdown";124return CodeMirror.overlayMode(CodeMirror.getMode(config, markdownConfig), gfmOverlay);125
126}, "markdown");127
128CodeMirror.defineMIME("text/x-gfm", "gfm");129});130