1 CodeMirror.defineMode("gfm", function(config) {
3 function blankLine(state) {
8 startState: function() {
15 copyState: function(s) {
18 codeBlock: s.codeBlock,
22 token: function(stream, state) {
23 // Hack to prevent formatting override inside code blocks (block and inline)
24 if (state.codeBlock) {
25 if (stream.match(/^```/)) {
26 state.codeBlock = false;
35 if (stream.sol() && stream.match(/^```/)) {
37 state.codeBlock = true;
40 // If this block is changed, it may need to be updated in Markdown mode
41 if (stream.peek() === '`') {
43 var before = stream.pos;
45 var difference = 1 + stream.pos - before;
47 codeDepth = difference;
50 if (difference === codeDepth) { // Must be exact
55 } else if (state.code) {
59 // Check if space. If so, links can be formatted later on
60 if (stream.eatSpace()) {
61 state.ateSpace = true;
64 if (stream.sol() || state.ateSpace) {
65 state.ateSpace = false;
66 if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
71 } else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
78 if (stream.match(/^((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/i)) {
80 // Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
81 // And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
89 CodeMirror.defineMIME("gfmBase", {
91 underscoresBreakWords: false,
93 fencedCodeBlocks: true
95 return CodeMirror.overlayMode(CodeMirror.getMode(config, "gfmBase"), gfmOverlay);