From fb70833bc52aedffa3ed0764a31b706dd1fb3250 Mon Sep 17 00:00:00 2001 From: Cheng-Han, Wu Date: Wed, 1 Jun 2016 14:37:28 +0800 Subject: Update CodeMirror to version 5.15.3 --- public/vendor/codemirror/mode/markdown/markdown.js | 30 ++++++++-------------- public/vendor/codemirror/mode/markdown/test.js | 3 +++ 2 files changed, 13 insertions(+), 20 deletions(-) (limited to 'public/vendor/codemirror/mode/markdown') diff --git a/public/vendor/codemirror/mode/markdown/markdown.js b/public/vendor/codemirror/mode/markdown/markdown.js index 8bd3cc7a..37329c23 100644 --- a/public/vendor/codemirror/mode/markdown/markdown.js +++ b/public/vendor/codemirror/mode/markdown/markdown.js @@ -218,7 +218,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { state.fencedChars = match[1] // try switching mode state.localMode = getMode(match[2]); - if (state.localMode) state.localState = state.localMode.startState(); + if (state.localMode) state.localState = CodeMirror.startState(state.localMode); state.f = state.block = local; if (modeCfg.highlightFormatting) state.formatting = "code-block"; state.code = -1 @@ -437,13 +437,13 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return tokenTypes.image; } - if (ch === '[' && stream.match(/.*\](\(.*\)| ?\[.*\])/, false)) { + if (ch === '[' && stream.match(/[^\]]*\](\(.*\)| ?\[.*?\])/, false)) { state.linkText = true; if (modeCfg.highlightFormatting) state.formatting = "link"; return getType(state); } - if (ch === ']' && state.linkText && stream.match(/\(.*\)| ?\[.*\]/, false)) { + if (ch === ']' && state.linkText && stream.match(/\(.*?\)| ?\[.*?\]/, false)) { if (modeCfg.highlightFormatting) state.formatting = "link"; var type = getType(state); state.linkText = false; @@ -596,7 +596,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { } var ch = stream.next(); if (ch === '(' || ch === '[') { - state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]"); + state.f = state.inline = getLinkHrefInside(ch === "(" ? ")" : "]", 0); if (modeCfg.highlightFormatting) state.formatting = "link-string"; state.linkHref = true; return getType(state); @@ -604,6 +604,11 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return 'error'; } + var linkRE = { + ")": /^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/, + "]": /^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\\]]|\\.)*\])*?(?=\])/ + } + function getLinkHrefInside(endChar) { return function(stream, state) { var ch = stream.next(); @@ -616,10 +621,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return returnState; } - if (stream.match(inlineRE(endChar), true)) { - stream.backUp(1); - } - + stream.match(linkRE[endChar]) state.linkHref = true; return getType(state); }; @@ -667,18 +669,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) { return tokenTypes.linkHref + " url"; } - var savedInlineRE = []; - function inlineRE(endChar) { - if (!savedInlineRE[endChar]) { - // Escape endChar for RegExp (taken from http://stackoverflow.com/a/494122/526741) - endChar = (endChar+'').replace(/([.?*+^$[\]\\(){}|-])/g, "\\$1"); - // Match any non-endChar, escaped character, as well as the closing - // endChar. - savedInlineRE[endChar] = new RegExp('^(?:[^\\\\]|\\\\.)*?(' + endChar + ')'); - } - return savedInlineRE[endChar]; - } - var mode = { startState: function() { return { diff --git a/public/vendor/codemirror/mode/markdown/test.js b/public/vendor/codemirror/mode/markdown/test.js index e2b3a815..e76eae90 100644 --- a/public/vendor/codemirror/mode/markdown/test.js +++ b/public/vendor/codemirror/mode/markdown/test.js @@ -782,6 +782,9 @@ MT("emStrongMixed", "[em *foo][em&strong __bar_hello** world]"); + MT("linkWithNestedParens", + "[link [[foo]]][string&url (bar(baz))]") + // These characters should be escaped: // \ backslash // ` backtick -- cgit v1.2.3