Manual patch CodeMirror for some minor issues

This commit is contained in:
Cheng-Han, Wu 2016-02-02 13:56:30 -06:00
parent 44ac1b295c
commit 740fde75d3
2 changed files with 28 additions and 32 deletions

File diff suppressed because one or more lines are too long

View file

@ -55,8 +55,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (modeCfg.tokenTypeOverrides === undefined) if (modeCfg.tokenTypeOverrides === undefined)
modeCfg.tokenTypeOverrides = {}; modeCfg.tokenTypeOverrides = {};
var codeDepth = 0;
var tokenTypes = { var tokenTypes = {
header: "header", header: "header",
code: "comment", code: "comment",
@ -215,7 +213,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (state.localMode) state.localState = state.localMode.startState(); if (state.localMode) state.localState = state.localMode.startState();
state.f = state.block = local; state.f = state.block = local;
if (modeCfg.highlightFormatting) state.formatting = "code-block"; if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = true; state.code = -1
return getType(state); return getType(state);
} }
@ -253,9 +251,9 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
state.f = inlineNormal; state.f = inlineNormal;
state.fencedChars = null; state.fencedChars = null;
if (modeCfg.highlightFormatting) state.formatting = "code-block"; if (modeCfg.highlightFormatting) state.formatting = "code-block";
state.code = true; state.code = 1
var returnType = getType(state); var returnType = getType(state);
state.code = false; state.code = 0
return returnType; return returnType;
} }
@ -378,15 +376,6 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
var ch = stream.next(); var ch = stream.next();
if (ch === '\\') {
stream.next();
if (modeCfg.highlightFormatting) {
var type = getType(state);
var formattingEscape = tokenTypes.formatting + "-escape";
return type ? type + " " + formattingEscape : formattingEscape;
}
}
// Matches link titles present on next line // Matches link titles present on next line
if (state.linkTitle) { if (state.linkTitle) {
state.linkTitle = false; state.linkTitle = false;
@ -405,26 +394,32 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
if (ch === '`') { if (ch === '`') {
var previousFormatting = state.formatting; var previousFormatting = state.formatting;
if (modeCfg.highlightFormatting) state.formatting = "code"; if (modeCfg.highlightFormatting) state.formatting = "code";
var t = getType(state);
var before = stream.pos;
stream.eatWhile('`'); stream.eatWhile('`');
var difference = 1 + stream.pos - before; var count = stream.current().length
if (!state.code) { if (state.code == 0) {
codeDepth = difference; state.code = count
state.code = true; return getType(state)
return getType(state); } else if (count == state.code) { // Must be exact
var t = getType(state)
state.code = 0
return t
} else { } else {
if (difference === codeDepth) { // Must be exact state.formatting = previousFormatting
state.code = false; return getType(state)
return t;
}
state.formatting = previousFormatting;
return getType(state);
} }
} else if (state.code) { } else if (state.code) {
return getType(state); return getType(state);
} }
if (ch === '\\') {
stream.next();
if (modeCfg.highlightFormatting) {
var type = getType(state);
var formattingEscape = tokenTypes.formatting + "-escape";
return type ? type + " " + formattingEscape : formattingEscape;
}
}
if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) { if (ch === '!' && stream.match(/\[[^\]]*\] ?(?:\(|\[)/, false)) {
stream.match(/\[[^\]]*\]/); stream.match(/\[[^\]]*\]/);
state.inline = state.f = linkHref; state.inline = state.f = linkHref;
@ -692,6 +687,7 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
linkText: false, linkText: false,
linkHref: false, linkHref: false,
linkTitle: false, linkTitle: false,
code: 0,
em: false, em: false,
strong: false, strong: false,
header: 0, header: 0,
@ -800,4 +796,4 @@ CodeMirror.defineMode("markdown", function(cmCfg, modeCfg) {
CodeMirror.defineMIME("text/x-markdown", "markdown"); CodeMirror.defineMIME("text/x-markdown", "markdown");
}); });