|
|
|
@ -39,8 +39,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
if (modeCfg.underscoresBreakWords === undefined)
|
|
|
|
|
modeCfg.underscoresBreakWords = true;
|
|
|
|
|
|
|
|
|
|
// Turn on fenced code blocks? ("```" to start/end)
|
|
|
|
|
if (modeCfg.fencedCodeBlocks === undefined) modeCfg.fencedCodeBlocks = false;
|
|
|
|
|
// Use `fencedCodeBlocks` to configure fenced code blocks. false to
|
|
|
|
|
// disable, string to specify a precise regexp that the fence should
|
|
|
|
|
// match, and true to allow three or more backticks or tildes (as
|
|
|
|
|
// per CommonMark).
|
|
|
|
|
|
|
|
|
|
// Turn on task lists? ("- [ ] " and "- [x] ")
|
|
|
|
|
if (modeCfg.taskLists === undefined) modeCfg.taskLists = false;
|
|
|
|
@ -74,7 +76,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
, taskListRE = /^\[(x| )\](?=\s)/ // Must follow ulRE or olRE
|
|
|
|
|
, atxHeaderRE = modeCfg.allowAtxHeaderWithoutSpace ? /^(#+)/ : /^(#+)(?: |$)/
|
|
|
|
|
, setextHeaderRE = /^ *(?:\={1,}|-{1,})\s*$/
|
|
|
|
|
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/;
|
|
|
|
|
, textRE = /^[^#!\[\]*_\\<>` "'(~]+/
|
|
|
|
|
, fencedCodeRE = new RegExp("^(" + (modeCfg.fencedCodeBlocks === true ? "~~~+|```+" : modeCfg.fencedCodeBlocks) +
|
|
|
|
|
")[ \\t]*([\\w+#]*)");
|
|
|
|
|
|
|
|
|
|
function switchInline(stream, state, f) {
|
|
|
|
|
state.f = state.inline = f;
|
|
|
|
@ -86,6 +90,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
return f(stream, state);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function lineIsEmpty(line) {
|
|
|
|
|
return !line || !/\S/.test(line.string)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Blocks
|
|
|
|
|
|
|
|
|
@ -110,7 +117,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
state.trailingSpace = 0;
|
|
|
|
|
state.trailingSpaceNewLine = false;
|
|
|
|
|
// Mark this line as blank
|
|
|
|
|
state.thisLineHasContent = false;
|
|
|
|
|
state.prevLine = state.thisLine
|
|
|
|
|
state.thisLine = null
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -141,7 +149,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
var match = null;
|
|
|
|
|
if (state.indentationDiff >= 4) {
|
|
|
|
|
stream.skipToEnd();
|
|
|
|
|
if (prevLineIsIndentedCode || !state.prevLineHasContent) {
|
|
|
|
|
if (prevLineIsIndentedCode || lineIsEmpty(state.prevLine)) {
|
|
|
|
|
state.indentation -= 4;
|
|
|
|
|
state.indentedCode = true;
|
|
|
|
|
return code;
|
|
|
|
@ -155,7 +163,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
|
|
|
|
state.f = state.inline;
|
|
|
|
|
return getType(state);
|
|
|
|
|
} else if (state.prevLineHasContent && !state.quote && !prevLineIsList && !prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
|
|
|
|
|
} else if (!lineIsEmpty(state.prevLine) && !state.quote && !prevLineIsList &&
|
|
|
|
|
!prevLineIsIndentedCode && (match = stream.match(setextHeaderRE))) {
|
|
|
|
|
state.header = match[0].charAt(0) == '=' ? 1 : 2;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "header";
|
|
|
|
|
state.f = state.inline;
|
|
|
|
@ -170,7 +179,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
} else if (stream.match(hrRE, true)) {
|
|
|
|
|
state.hr = true;
|
|
|
|
|
return hr;
|
|
|
|
|
} else if ((!state.prevLineHasContent || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
|
|
|
|
|
} else if ((lineIsEmpty(state.prevLine) || prevLineIsList) && (stream.match(ulRE, false) || stream.match(olRE, false))) {
|
|
|
|
|
var listType = null;
|
|
|
|
|
if (stream.match(ulRE, true)) {
|
|
|
|
|
listType = 'ul';
|
|
|
|
@ -187,9 +196,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
state.f = state.inline;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = ["list", "list-" + listType];
|
|
|
|
|
return getType(state);
|
|
|
|
|
} else if (modeCfg.fencedCodeBlocks && stream.match(/^```[ \t]*([\w+#]*)/, true)) {
|
|
|
|
|
} else if (modeCfg.fencedCodeBlocks && (match = stream.match(fencedCodeRE, true))) {
|
|
|
|
|
state.fencedChars = match[1]
|
|
|
|
|
// try switching mode
|
|
|
|
|
state.localMode = getMode(RegExp.$1);
|
|
|
|
|
state.localMode = getMode(match[2]);
|
|
|
|
|
if (state.localMode) state.localState = state.localMode.startState();
|
|
|
|
|
state.f = state.block = local;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
|
|
|
@ -213,7 +223,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function local(stream, state) {
|
|
|
|
|
if (stream.sol() && stream.match("```", false)) {
|
|
|
|
|
if (stream.sol() && state.fencedChars && stream.match(state.fencedChars, false)) {
|
|
|
|
|
state.localMode = state.localState = null;
|
|
|
|
|
state.f = state.block = leavingLocal;
|
|
|
|
|
return null;
|
|
|
|
@ -226,9 +236,10 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function leavingLocal(stream, state) {
|
|
|
|
|
stream.match("```");
|
|
|
|
|
stream.match(state.fencedChars);
|
|
|
|
|
state.block = blockNormal;
|
|
|
|
|
state.f = inlineNormal;
|
|
|
|
|
state.fencedChars = null;
|
|
|
|
|
if (modeCfg.highlightFormatting) state.formatting = "code-block";
|
|
|
|
|
state.code = true;
|
|
|
|
|
var returnType = getType(state);
|
|
|
|
@ -656,8 +667,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
return {
|
|
|
|
|
f: blockNormal,
|
|
|
|
|
|
|
|
|
|
prevLineHasContent: false,
|
|
|
|
|
thisLineHasContent: false,
|
|
|
|
|
prevLine: null,
|
|
|
|
|
thisLine: null,
|
|
|
|
|
|
|
|
|
|
block: blockNormal,
|
|
|
|
|
htmlState: null,
|
|
|
|
@ -680,7 +691,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
quote: 0,
|
|
|
|
|
trailingSpace: 0,
|
|
|
|
|
trailingSpaceNewLine: false,
|
|
|
|
|
strikethrough: false
|
|
|
|
|
strikethrough: false,
|
|
|
|
|
fencedChars: null
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -688,8 +700,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
return {
|
|
|
|
|
f: s.f,
|
|
|
|
|
|
|
|
|
|
prevLineHasContent: s.prevLineHasContent,
|
|
|
|
|
thisLineHasContent: s.thisLineHasContent,
|
|
|
|
|
prevLine: s.prevLine,
|
|
|
|
|
thisLine: s.this,
|
|
|
|
|
|
|
|
|
|
block: s.block,
|
|
|
|
|
htmlState: s.htmlState && CodeMirror.copyState(htmlMode, s.htmlState),
|
|
|
|
@ -715,7 +727,8 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
indentedCode: s.indentedCode,
|
|
|
|
|
trailingSpace: s.trailingSpace,
|
|
|
|
|
trailingSpaceNewLine: s.trailingSpaceNewLine,
|
|
|
|
|
md_inside: s.md_inside
|
|
|
|
|
md_inside: s.md_inside,
|
|
|
|
|
fencedChars: s.fencedChars
|
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -724,22 +737,22 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
|
|
|
|
|
// Reset state.formatting
|
|
|
|
|
state.formatting = false;
|
|
|
|
|
|
|
|
|
|
if (stream.sol()) {
|
|
|
|
|
var forceBlankLine = !!state.header || state.hr;
|
|
|
|
|
if (stream != state.thisLine) {
|
|
|
|
|
var forceBlankLine = state.header || state.hr;
|
|
|
|
|
|
|
|
|
|
// Reset state.header and state.hr
|
|
|
|
|
state.header = 0;
|
|
|
|
|
state.hr = false;
|
|
|
|
|
|
|
|
|
|
if (stream.match(/^\s*$/, true) || forceBlankLine) {
|
|
|
|
|
state.prevLineHasContent = false;
|
|
|
|
|
blankLine(state);
|
|
|
|
|
return forceBlankLine ? this.token(stream, state) : null;
|
|
|
|
|
} else {
|
|
|
|
|
state.prevLineHasContent = state.thisLineHasContent;
|
|
|
|
|
state.thisLineHasContent = true;
|
|
|
|
|
if (!forceBlankLine) return null
|
|
|
|
|
state.prevLine = null
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
state.prevLine = state.thisLine
|
|
|
|
|
state.thisLine = stream
|
|
|
|
|
|
|
|
|
|
// Reset state.taskList
|
|
|
|
|
state.taskList = false;
|
|
|
|
|
|
|
|
|
|