LaravelTest
886 строк · 30.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("../meta"));7else if (typeof define == "function" && define.amd) // AMD8define(["../../lib/codemirror", "../xml/xml", "../meta"], mod);9else // Plain browser env10mod(CodeMirror);11})(function(CodeMirror) {12"use strict";13
14CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {15
16var htmlMode = CodeMirror.getMode(cmCfg, "text/html");17var htmlModeMissing = htmlMode.name == "null"18
19function getMode(name) {20if (CodeMirror.findModeByName) {21var found = CodeMirror.findModeByName(name);22if (found) name = found.mime || found.mimes[0];23}24var mode = CodeMirror.getMode(cmCfg, name);25return mode.name == "null" ? null : mode;26}27
28// Should characters that affect highlighting be highlighted separate?29// Does not include characters that will be output (such as `1.` and `-` for lists)30if (modeCfg.highlightFormatting === undefined)31modeCfg.highlightFormatting = false;32
33// Maximum number of nested blockquotes. Set to 0 for infinite nesting.34// Excess `>` will emit `error` token.35if (modeCfg.maxBlockquoteDepth === undefined)36modeCfg.maxBlockquoteDepth = 0;37
38// Turn on task lists? ("- [ ] " and "- [x] ")39if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;40
41// Turn on strikethrough syntax42if (modeCfg.strikethrough === undefined)43modeCfg.strikethrough = false;44
45if (modeCfg.emoji === undefined)46modeCfg.emoji = false;47
48if (modeCfg.fencedCodeBlockHighlighting === undefined)49modeCfg.fencedCodeBlockHighlighting = true;50
51if (modeCfg.fencedCodeBlockDefaultMode === undefined)52modeCfg.fencedCodeBlockDefaultMode = 'text/plain';53
54if (modeCfg.xml === undefined)55modeCfg.xml = true;56
57// Allow token types to be overridden by user-provided token types.58if (modeCfg.tokenTypeOverrides === undefined)59modeCfg.tokenTypeOverrides = {};60
61var tokenTypes = {62header: "header",63code: "comment",64quote: "quote",65list1: "variable-2",66list2: "variable-3",67list3: "keyword",68hr: "hr",69image: "image",70imageAltText: "image-alt-text",71imageMarker: "image-marker",72formatting: "formatting",73linkInline: "link",74linkEmail: "link",75linkText: "link",76linkHref: "string",77em: "em",78strong: "strong",79strikethrough: "strikethrough",80emoji: "builtin"81};82
83for (var tokenType in tokenTypes) {84if (tokenTypes.hasOwnProperty(tokenType) && modeCfg.tokenTypeOverrides[tokenType]) {85tokenTypes[tokenType] = modeCfg.tokenTypeOverrides[tokenType];86}87}88
89var hrRE = /^([*\-_])(?:\s*\1){2,}\s*$/90, listRE = /^(?:[*\-+]|^[0-9]+([.)]))\s+/91, taskListRE = /^\[(x| )\](?=\s)/i // Must follow listRE92, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/93, setextHeaderRE = /^ {0,3}(?:\={1,}|-{2,})\s*$/94, textRE = /^[^#!\[\]*_\\<>` "'(~:]+/95, fencedCodeRE = /^(~~~+|```+)[ \t]*([\w\/+#-]*)[^\n`]*$/96, linkDefRE = /^\s*\[[^\]]+?\]:.*$/ // naive link-definition97, punctuation = /[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/98, expandedTab = " " // CommonMark specifies tab as 4 spaces99
100function switchInline(stream, state, f) {101state.f = state.inline = f;102return f(stream, state);103}104
105function switchBlock(stream, state, f) {106state.f = state.block = f;107return f(stream, state);108}109
110function lineIsEmpty(line) {111return !line || !/\S/.test(line.string)112}113
114// Blocks115
116function blankLine(state) {117// Reset linkTitle state118state.linkTitle = false;119state.linkHref = false;120state.linkText = false;121// Reset EM state122state.em = false;123// Reset STRONG state124state.strong = false;125// Reset strikethrough state126state.strikethrough = false;127// Reset state.quote128state.quote = 0;129// Reset state.indentedCode130state.indentedCode = false;131if (state.f == htmlBlock) {132var exit = htmlModeMissing133if (!exit) {134var inner = CodeMirror.innerMode(htmlMode, state.htmlState)135exit = inner.mode.name == "xml" && inner.state.tagStart === null &&136(!inner.state.context && inner.state.tokenize.isInText)137}138if (exit) {139state.f = inlineNormal;140state.block = blockNormal;141state.htmlState = null;142}143}144// Reset state.trailingSpace145state.trailingSpace = 0;146state.trailingSpaceNewLine = false;147// Mark this line as blank148state.prevLine = state.thisLine149state.thisLine = {stream: null}150return null;151}152
153function blockNormal(stream, state) {154var firstTokenOnLine = stream.column() === state.indentation;155var prevLineLineIsEmpty = lineIsEmpty(state.prevLine.stream);156var prevLineIsIndentedCode = state.indentedCode;157var prevLineIsHr = state.prevLine.hr;158var prevLineIsList = state.list !== false;159var maxNonCodeIndentation = (state.listStack[state.listStack.length - 1] || 0) + 3;160
161state.indentedCode = false;162
163var lineIndentation = state.indentation;164// compute once per line (on first token)165if (state.indentationDiff === null) {166state.indentationDiff = state.indentation;167if (prevLineIsList) {168state.list = null;169// While this list item's marker's indentation is less than the deepest170// list item's content's indentation,pop the deepest list item171// indentation off the stack, and update block indentation state172while (lineIndentation < state.listStack[state.listStack.length - 1]) {173state.listStack.pop();174if (state.listStack.length) {175state.indentation = state.listStack[state.listStack.length - 1];176// less than the first list's indent -> the line is no longer a list177} else {178state.list = false;179}180}181if (state.list !== false) {182state.indentationDiff = lineIndentation - state.listStack[state.listStack.length - 1]183}184}185}186
187// not comprehensive (currently only for setext detection purposes)188var allowsInlineContinuation = (189!prevLineLineIsEmpty && !prevLineIsHr && !state.prevLine.header &&190(!prevLineIsList || !prevLineIsIndentedCode) &&191!state.prevLine.fencedCodeEnd192);193
194var isHr = (state.list === false || prevLineIsHr || prevLineLineIsEmpty) &&195state.indentation <= maxNonCodeIndentation && stream.match(hrRE);196
197var match = null;198if (state.indentationDiff >= 4 && (prevLineIsIndentedCode || state.prevLine.fencedCodeEnd ||199state.prevLine.header || prevLineLineIsEmpty)) {200stream.skipToEnd();201state.indentedCode = true;202return tokenTypes.code;203} else if (stream.eatSpace()) {204return null;205} else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(atxHeaderRE)) && match[1].length <= 6) {206state.quote = 0;207state.header = match[1].length;208state.thisLine.header = true;209if (modeCfg.highlightFormatting) state.formatting = "header";210state.f = state.inline;211return getType(state);212} else if (state.indentation <= maxNonCodeIndentation && stream.eat('>')) {213state.quote = firstTokenOnLine ? 1 : state.quote + 1;214if (modeCfg.highlightFormatting) state.formatting = "quote";215stream.eatSpace();216return getType(state);217} else if (!isHr && !state.setext && firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(listRE))) {218var listType = match[1] ? "ol" : "ul";219
220state.indentation = lineIndentation + stream.current().length;221state.list = true;222state.quote = 0;223
224// Add this list item's content's indentation to the stack225state.listStack.push(state.indentation);226// Reset inline styles which shouldn't propagate across list items227state.em = false;228state.strong = false;229state.code = false;230state.strikethrough = false;231
232if (modeCfg.taskLists && stream.match(taskListRE, false)) {233state.taskList = true;234}235state.f = state.inline;236if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];237return getType(state);238} else if (firstTokenOnLine && state.indentation <= maxNonCodeIndentation && (match = stream.match(fencedCodeRE, true))) {239state.quote = 0;240state.fencedEndRE = new RegExp(match[1] + "+ *$");241// try switching mode242state.localMode = modeCfg.fencedCodeBlockHighlighting && getMode(match[2] || modeCfg.fencedCodeBlockDefaultMode );243if (state.localMode) state.localState = CodeMirror.startState(state.localMode);244state.f = state.block = local;245if (modeCfg.highlightFormatting) state.formatting = "code-block";246state.code = -1247return getType(state);248// SETEXT has lowest block-scope precedence after HR, so check it after249// the others (code, blockquote, list...)250} else if (251// if setext set, indicates line after ---/===252state.setext || (253// line before ---/===254(!allowsInlineContinuation || !prevLineIsList) && !state.quote && state.list === false &&255!state.code && !isHr && !linkDefRE.test(stream.string) &&256(match = stream.lookAhead(1)) && (match = match.match(setextHeaderRE))257)258) {259if ( !state.setext ) {260state.header = match[0].charAt(0) == '=' ? 1 : 2;261state.setext = state.header;262} else {263state.header = state.setext;264// has no effect on type so we can reset it now265state.setext = 0;266stream.skipToEnd();267if (modeCfg.highlightFormatting) state.formatting = "header";268}269state.thisLine.header = true;270state.f = state.inline;271return getType(state);272} else if (isHr) {273stream.skipToEnd();274state.hr = true;275state.thisLine.hr = true;276return tokenTypes.hr;277} else if (stream.peek() === '[') {278return switchInline(stream, state, footnoteLink);279}280
281return switchInline(stream, state, state.inline);282}283
284function htmlBlock(stream, state) {285var style = htmlMode.token(stream, state.htmlState);286if (!htmlModeMissing) {287var inner = CodeMirror.innerMode(htmlMode, state.htmlState)288if ((inner.mode.name == "xml" && inner.state.tagStart === null &&289(!inner.state.context && inner.state.tokenize.isInText)) ||290(state.md_inside && stream.current().indexOf(">") > -1)) {291state.f = inlineNormal;292state.block = blockNormal;293state.htmlState = null;294}295}296return style;297}298
299function local(stream, state) {300var currListInd = state.listStack[state.listStack.length - 1] || 0;301var hasExitedList = state.indentation < currListInd;302var maxFencedEndInd = currListInd + 3;303if (state.fencedEndRE && state.indentation <= maxFencedEndInd && (hasExitedList || stream.match(state.fencedEndRE))) {304if (modeCfg.highlightFormatting) state.formatting = "code-block";305var returnType;306if (!hasExitedList) returnType = getType(state)307state.localMode = state.localState = null;308state.block = blockNormal;309state.f = inlineNormal;310state.fencedEndRE = null;311state.code = 0312state.thisLine.fencedCodeEnd = true;313if (hasExitedList) return switchBlock(stream, state, state.block);314return returnType;315} else if (state.localMode) {316return state.localMode.token(stream, state.localState);317} else {318stream.skipToEnd();319return tokenTypes.code;320}321}322
323// Inline324function getType(state) {325var styles = [];326
327if (state.formatting) {328styles.push(tokenTypes.formatting);329
330if (typeof state.formatting === "string") state.formatting = [state.formatting];331
332for (var i = 0; i < state.formatting.length; i++) {333styles.push(tokenTypes.formatting + "-" + state.formatting[i]);334
335if (state.formatting[i] === "header") {336styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.header);337}338
339// Add `formatting-quote` and `formatting-quote-#` for blockquotes340// Add `error` instead if the maximum blockquote nesting depth is passed341if (state.formatting[i] === "quote") {342if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {343styles.push(tokenTypes.formatting + "-" + state.formatting[i] + "-" + state.quote);344} else {345styles.push("error");346}347}348}349}350
351if (state.taskOpen) {352styles.push("meta");353return styles.length ? styles.join(' ') : null;354}355if (state.taskClosed) {356styles.push("property");357return styles.length ? styles.join(' ') : null;358}359
360if (state.linkHref) {361styles.push(tokenTypes.linkHref, "url");362} else { // Only apply inline styles to non-url text363if (state.strong) { styles.push(tokenTypes.strong); }364if (state.em) { styles.push(tokenTypes.em); }365if (state.strikethrough) { styles.push(tokenTypes.strikethrough); }366if (state.emoji) { styles.push(tokenTypes.emoji); }367if (state.linkText) { styles.push(tokenTypes.linkText); }368if (state.code) { styles.push(tokenTypes.code); }369if (state.image) { styles.push(tokenTypes.image); }370if (state.imageAltText) { styles.push(tokenTypes.imageAltText, "link"); }371if (state.imageMarker) { styles.push(tokenTypes.imageMarker); }372}373
374if (state.header) { styles.push(tokenTypes.header, tokenTypes.header + "-" + state.header); }375
376if (state.quote) {377styles.push(tokenTypes.quote);378
379// Add `quote-#` where the maximum for `#` is modeCfg.maxBlockquoteDepth380if (!modeCfg.maxBlockquoteDepth || modeCfg.maxBlockquoteDepth >= state.quote) {381styles.push(tokenTypes.quote + "-" + state.quote);382} else {383styles.push(tokenTypes.quote + "-" + modeCfg.maxBlockquoteDepth);384}385}386
387if (state.list !== false) {388var listMod = (state.listStack.length - 1) % 3;389if (!listMod) {390styles.push(tokenTypes.list1);391} else if (listMod === 1) {392styles.push(tokenTypes.list2);393} else {394styles.push(tokenTypes.list3);395}396}397
398if (state.trailingSpaceNewLine) {399styles.push("trailing-space-new-line");400} else if (state.trailingSpace) {401styles.push("trailing-space-" + (state.trailingSpace % 2 ? "a" : "b"));402}403
404return styles.length ? styles.join(' ') : null;405}406
407function handleText(stream, state) {408if (stream.match(textRE, true)) {409return getType(state);410}411return undefined;412}413
414function inlineNormal(stream, state) {415var style = state.text(stream, state);416if (typeof style !== 'undefined')417return style;418
419if (state.list) { // List marker (*, +, -, 1., etc)420state.list = null;421return getType(state);422}423
424if (state.taskList) {425var taskOpen = stream.match(taskListRE, true)[1] === " ";426if (taskOpen) state.taskOpen = true;427else state.taskClosed = true;428if (modeCfg.highlightFormatting) state.formatting = "task";429state.taskList = false;430return getType(state);431}432
433state.taskOpen = false;434state.taskClosed = false;435
436if (state.header && stream.match(/^#+$/, true)) {437if (modeCfg.highlightFormatting) state.formatting = "header";438return getType(state);439}440
441var ch = stream.next();442
443// Matches link titles present on next line444if (state.linkTitle) {445state.linkTitle = false;446var matchCh = ch;447if (ch === '(') {448matchCh = ')';449}450matchCh = (matchCh+'').replace(/([.?*+^\[\]\\(){}|-])/g, "\\$1");451var regex = '^\\s*(?:[^' + matchCh + '\\\\]+|\\\\\\\\|\\\\.)' + matchCh;452if (stream.match(new RegExp(regex), true)) {453return tokenTypes.linkHref;454}455}456
457// If this block is changed, it may need to be updated in GFM mode458if (ch === '`') {459var previousFormatting = state.formatting;460if (modeCfg.highlightFormatting) state.formatting = "code";461stream.eatWhile('`');462var count = stream.current().length463if (state.code == 0 && (!state.quote || count == 1)) {464state.code = count465return getType(state)466} else if (count == state.code) { // Must be exact467var t = getType(state)468state.code = 0469return t470} else {471state.formatting = previousFormatting472return getType(state)473}474} else if (state.code) {475return getType(state);476}477
478if (ch === '\\') {479stream.next();480if (modeCfg.highlightFormatting) {481var type = getType(state);482var formattingEscape = tokenTypes.formatting + "-escape";483return type ? type + " " + formattingEscape : formattingEscape;484}485}486
487if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {488state.imageMarker = true;489state.image = true;490if (modeCfg.highlightFormatting) state.formatting = "image";491return getType(state);492}493
494if (ch === '[' && state.imageMarker && stream.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/, false)) {495state.imageMarker = false;496state.imageAltText = true497if (modeCfg.highlightFormatting) state.formatting = "image";498return getType(state);499}500
501if (ch === ']' && state.imageAltText) {502if (modeCfg.highlightFormatting) state.formatting = "image";503var type = getType(state);504state.imageAltText = false;505state.image = false;506state.inline = state.f = linkHref;507return type;508}509
510if (ch === '[' && !state.image) {511if (state.linkText && stream.match(/^.*?\]/)) return getType(state)512state.linkText = true;513if (modeCfg.highlightFormatting) state.formatting = "link";514return getType(state);515}516
517if (ch === ']' && state.linkText) {518if (modeCfg.highlightFormatting) state.formatting = "link";519var type = getType(state);520state.linkText = false;521state.inline = state.f = stream.match(/\(.*?\)| ?\[.*?\]/, false) ? linkHref : inlineNormal522return type;523}524
525if (ch === '<' && stream.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/, false)) {526state.f = state.inline = linkInline;527if (modeCfg.highlightFormatting) state.formatting = "link";528var type = getType(state);529if (type){530type += " ";531} else {532type = "";533}534return type + tokenTypes.linkInline;535}536
537if (ch === '<' && stream.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/, false)) {538state.f = state.inline = linkInline;539if (modeCfg.highlightFormatting) state.formatting = "link";540var type = getType(state);541if (type){542type += " ";543} else {544type = "";545}546return type + tokenTypes.linkEmail;547}548
549if (modeCfg.xml && ch === '<' && stream.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i, false)) {550var end = stream.string.indexOf(">", stream.pos);551if (end != -1) {552var atts = stream.string.substring(stream.start, end);553if (/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(atts)) state.md_inside = true;554}555stream.backUp(1);556state.htmlState = CodeMirror.startState(htmlMode);557return switchBlock(stream, state, htmlBlock);558}559
560if (modeCfg.xml && ch === '<' && stream.match(/^\/\w*?>/)) {561state.md_inside = false;562return "tag";563} else if (ch === "*" || ch === "_") {564var len = 1, before = stream.pos == 1 ? " " : stream.string.charAt(stream.pos - 2)565while (len < 3 && stream.eat(ch)) len++566var after = stream.peek() || " "567// See http://spec.commonmark.org/0.27/#emphasis-and-strong-emphasis568var leftFlanking = !/\s/.test(after) && (!punctuation.test(after) || /\s/.test(before) || punctuation.test(before))569var rightFlanking = !/\s/.test(before) && (!punctuation.test(before) || /\s/.test(after) || punctuation.test(after))570var setEm = null, setStrong = null571if (len % 2) { // Em572if (!state.em && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))573setEm = true574else if (state.em == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))575setEm = false576}577if (len > 1) { // Strong578if (!state.strong && leftFlanking && (ch === "*" || !rightFlanking || punctuation.test(before)))579setStrong = true580else if (state.strong == ch && rightFlanking && (ch === "*" || !leftFlanking || punctuation.test(after)))581setStrong = false582}583if (setStrong != null || setEm != null) {584if (modeCfg.highlightFormatting) state.formatting = setEm == null ? "strong" : setStrong == null ? "em" : "strong em"585if (setEm === true) state.em = ch586if (setStrong === true) state.strong = ch587var t = getType(state)588if (setEm === false) state.em = false589if (setStrong === false) state.strong = false590return t591}592} else if (ch === ' ') {593if (stream.eat('*') || stream.eat('_')) { // Probably surrounded by spaces594if (stream.peek() === ' ') { // Surrounded by spaces, ignore595return getType(state);596} else { // Not surrounded by spaces, back up pointer597stream.backUp(1);598}599}600}601
602if (modeCfg.strikethrough) {603if (ch === '~' && stream.eatWhile(ch)) {604if (state.strikethrough) {// Remove strikethrough605if (modeCfg.highlightFormatting) state.formatting = "strikethrough";606var t = getType(state);607state.strikethrough = false;608return t;609} else if (stream.match(/^[^\s]/, false)) {// Add strikethrough610state.strikethrough = true;611if (modeCfg.highlightFormatting) state.formatting = "strikethrough";612return getType(state);613}614} else if (ch === ' ') {615if (stream.match('~~', true)) { // Probably surrounded by space616if (stream.peek() === ' ') { // Surrounded by spaces, ignore617return getType(state);618} else { // Not surrounded by spaces, back up pointer619stream.backUp(2);620}621}622}623}624
625if (modeCfg.emoji && ch === ":" && stream.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)) {626state.emoji = true;627if (modeCfg.highlightFormatting) state.formatting = "emoji";628var retType = getType(state);629state.emoji = false;630return retType;631}632
633if (ch === ' ') {634if (stream.match(/^ +$/, false)) {635state.trailingSpace++;636} else if (state.trailingSpace) {637state.trailingSpaceNewLine = true;638}639}640
641return getType(state);642}643
644function linkInline(stream, state) {645var ch = stream.next();646
647if (ch === ">") {648state.f = state.inline = inlineNormal;649if (modeCfg.highlightFormatting) state.formatting = "link";650var type = getType(state);651if (type){652type += " ";653} else {654type = "";655}656return type + tokenTypes.linkInline;657}658
659stream.match(/^[^>]+/, true);660
661return tokenTypes.linkInline;662}663
664function linkHref(stream, state) {665// Check if space, and return NULL if so (to avoid marking the space)666if(stream.eatSpace()){667return null;668}669var ch = stream.next();670if (ch === '(' || ch === '[') {671state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]");672if (modeCfg.highlightFormatting) state.formatting = "link-string";673state.linkHref = true;674return getType(state);675}676return 'error';677}678
679var linkRE = {680")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,681"]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/682}683
684function getLinkHrefInside(endChar) {685return function(stream, state) {686var ch = stream.next();687
688if (ch === endChar) {689state.f = state.inline = inlineNormal;690if (modeCfg.highlightFormatting) state.formatting = "link-string";691var returnState = getType(state);692state.linkHref = false;693return returnState;694}695
696stream.match(linkRE[endChar])697state.linkHref = true;698return getType(state);699};700}701
702function footnoteLink(stream, state) {703if (stream.match(/^([^\]\\]|\\.)*\]:/, false)) {704state.f = footnoteLinkInside;705stream.next(); // Consume [706if (modeCfg.highlightFormatting) state.formatting = "link";707state.linkText = true;708return getType(state);709}710return switchInline(stream, state, inlineNormal);711}712
713function footnoteLinkInside(stream, state) {714if (stream.match(']:', true)) {715state.f = state.inline = footnoteUrl;716if (modeCfg.highlightFormatting) state.formatting = "link";717var returnType = getType(state);718state.linkText = false;719return returnType;720}721
722stream.match(/^([^\]\\]|\\.)+/, true);723
724return tokenTypes.linkText;725}726
727function footnoteUrl(stream, state) {728// Check if space, and return NULL if so (to avoid marking the space)729if(stream.eatSpace()){730return null;731}732// Match URL733stream.match(/^[^\s]+/, true);734// Check for link title735if (stream.peek() === undefined) { // End of line, set flag to check next line736state.linkTitle = true;737} else { // More content on line, check if link title738stream.match(/^(?:\s+(?:"(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+'|\((?:[^)\\]|\\.)+\)))?/, true);739}740state.f = state.inline = inlineNormal;741return tokenTypes.linkHref + " url";742}743
744var mode = {745startState: function() {746return {747f: blockNormal,748
749prevLine: {stream: null},750thisLine: {stream: null},751
752block: blockNormal,753htmlState: null,754indentation: 0,755
756inline: inlineNormal,757text: handleText,758
759formatting: false,760linkText: false,761linkHref: false,762linkTitle: false,763code: 0,764em: false,765strong: false,766header: 0,767setext: 0,768hr: false,769taskList: false,770list: false,771listStack: [],772quote: 0,773trailingSpace: 0,774trailingSpaceNewLine: false,775strikethrough: false,776emoji: false,777fencedEndRE: null778};779},780
781copyState: function(s) {782return {783f: s.f,784
785prevLine: s.prevLine,786thisLine: s.thisLine,787
788block: s.block,789htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),790indentation: s.indentation,791
792localMode: s.localMode,793localState: s.localMode ? CodeMirror.copyState(s.localMode, s.localState) : null,794
795inline: s.inline,796text: s.text,797formatting: false,798linkText: s.linkText,799linkTitle: s.linkTitle,800linkHref: s.linkHref,801code: s.code,802em: s.em,803strong: s.strong,804strikethrough: s.strikethrough,805emoji: s.emoji,806header: s.header,807setext: s.setext,808hr: s.hr,809taskList: s.taskList,810list: s.list,811listStack: s.listStack.slice(0),812quote: s.quote,813indentedCode: s.indentedCode,814trailingSpace: s.trailingSpace,815trailingSpaceNewLine: s.trailingSpaceNewLine,816md_inside: s.md_inside,817fencedEndRE: s.fencedEndRE818};819},820
821token: function(stream, state) {822
823// Reset state.formatting824state.formatting = false;825
826if (stream != state.thisLine.stream) {827state.header = 0;828state.hr = false;829
830if (stream.match(/^\s*$/, true)) {831blankLine(state);832return null;833}834
835state.prevLine = state.thisLine836state.thisLine = {stream: stream}837
838// Reset state.taskList839state.taskList = false;840
841// Reset state.trailingSpace842state.trailingSpace = 0;843state.trailingSpaceNewLine = false;844
845if (!state.localState) {846state.f = state.block;847if (state.f != htmlBlock) {848var indentation = stream.match(/^\s*/, true)[0].replace(/\t/g, expandedTab).length;849state.indentation = indentation;850state.indentationDiff = null;851if (indentation > 0) return null;852}853}854}855return state.f(stream, state);856},857
858innerMode: function(state) {859if (state.block == htmlBlock) return {state: state.htmlState, mode: htmlMode};860if (state.localState) return {state: state.localState, mode: state.localMode};861return {state: state, mode: mode};862},863
864indent: function(state, textAfter, line) {865if (state.block == htmlBlock && htmlMode.indent) return htmlMode.indent(state.htmlState, textAfter, line)866if (state.localState && state.localMode.indent) return state.localMode.indent(state.localState, textAfter, line)867return CodeMirror.Pass868},869
870blankLine: blankLine,871
872getType: getType,873
874blockCommentStart: "<!--",875blockCommentEnd: "-->",876closeBrackets: "()[]{}''\"\"``",877fold: "markdown"878};879return mode;880}, "xml");881
882CodeMirror.defineMIME("text/markdown", "markdown");883
884CodeMirror.defineMIME("text/x-markdown", "markdown");885
886});887