mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-13 21:14:29 -06:00
Merge proposed PRs for CodeMirror
This commit is contained in:
parent
f77dbc6aab
commit
7f4491edee
@ -1,94 +0,0 @@
|
|||||||
// NOTE: This has been modified from the original version to add additional commands
|
|
||||||
|
|
||||||
|
|
||||||
(function(mod) {
|
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
|
||||||
mod(require("../../lib/codemirror"));
|
|
||||||
else if (typeof define == "function" && define.amd) // AMD
|
|
||||||
define(["../../lib/codemirror"], mod);
|
|
||||||
else // Plain browser env
|
|
||||||
mod(CodeMirror);
|
|
||||||
})(function(CodeMirror) {
|
|
||||||
"use strict";
|
|
||||||
|
|
||||||
var listRE = /^(\s*)(>[> ]*|[*+-]\s|(\d+)([.)]))(\s*)/,
|
|
||||||
emptyListRE = /^(\s*)(>[> ]*|[*+-]|(\d+)[.)])(\s*)$/,
|
|
||||||
unorderedListRE = /[*+-]\s/;
|
|
||||||
|
|
||||||
CodeMirror.commands.newlineAndIndentContinueMarkdownList = function(cm) {
|
|
||||||
if (cm.getOption("disableInput")) return CodeMirror.Pass;
|
|
||||||
var ranges = cm.listSelections(),
|
|
||||||
replacements = [];
|
|
||||||
for (var i = 0; i < ranges.length; i++) {
|
|
||||||
var pos = ranges[i].head;
|
|
||||||
var eolState = cm.getStateAfter(pos.line);
|
|
||||||
var inList = eolState.list !== false;
|
|
||||||
var inQuote = eolState.quote !== 0;
|
|
||||||
|
|
||||||
var line = cm.getLine(pos.line),
|
|
||||||
match = listRE.exec(line);
|
|
||||||
if (!ranges[i].empty() || (!inList && !inQuote) || !match) {
|
|
||||||
cm.execCommand("newlineAndIndent");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (emptyListRE.test(line)) {
|
|
||||||
cm.replaceRange("", {
|
|
||||||
line: pos.line,
|
|
||||||
ch: 0
|
|
||||||
}, {
|
|
||||||
line: pos.line,
|
|
||||||
ch: pos.ch + 1
|
|
||||||
});
|
|
||||||
replacements[i] = "\n";
|
|
||||||
} else {
|
|
||||||
var indent = match[1],
|
|
||||||
after = match[5];
|
|
||||||
var bullet = unorderedListRE.test(match[2]) || match[2].indexOf(">") >= 0 ? match[2] : (parseInt(match[3], 10) + 1) + match[4];
|
|
||||||
|
|
||||||
replacements[i] = "\n" + indent + bullet + after;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
cm.replaceSelections(replacements);
|
|
||||||
};
|
|
||||||
|
|
||||||
CodeMirror.commands.shiftTabAndIndentContinueMarkdownList = function(cm) {
|
|
||||||
var ranges = cm.listSelections();
|
|
||||||
var pos = ranges[0].head;
|
|
||||||
var eolState = cm.getStateAfter(pos.line);
|
|
||||||
var inList = eolState.list !== false;
|
|
||||||
|
|
||||||
if (inList) {
|
|
||||||
cm.execCommand('indentLess');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cm.options.indentWithTabs){
|
|
||||||
cm.execCommand('insertTab');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var spaces = Array(cm.options.tabSize + 1).join(" ");
|
|
||||||
cm.replaceSelection(spaces);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
CodeMirror.commands.tabAndIndentContinueMarkdownList = function(cm) {
|
|
||||||
var ranges = cm.listSelections();
|
|
||||||
var pos = ranges[0].head;
|
|
||||||
var eolState = cm.getStateAfter(pos.line);
|
|
||||||
var inList = eolState.list !== false;
|
|
||||||
|
|
||||||
if (inList) {
|
|
||||||
cm.execCommand('indentMore');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(cm.options.indentWithTabs){
|
|
||||||
cm.execCommand('insertTab');
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
var spaces = Array(cm.options.tabSize + 1).join(" ");
|
|
||||||
cm.replaceSelection(spaces);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
});
|
|
@ -1,6 +1,5 @@
|
|||||||
// NOTE: This has been modified from the original version to remove linking GitHub-only references, like references to issues using #X.
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
|
||||||
(function(mod) {
|
(function(mod) {
|
||||||
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
@ -12,9 +11,14 @@
|
|||||||
})(function(CodeMirror) {
|
})(function(CodeMirror) {
|
||||||
"use strict";
|
"use strict";
|
||||||
|
|
||||||
CodeMirror.defineMode("gfm", function(config, modeConfig) {
|
var urlRE = /^((?:coap|doi|javascript|aaa|aaas|about|acap|cap|cid|crid|data|dav|dict|dns|file|ftp|geo|go|gopher|h323|http|https|iax|icap|im|imap|info|ipp|iris|iris\.beep|iris\.xpc|iris\.xpcs|iris\.lwz|ldap|mailto|mid|msrp|msrps|mtqp|mupdate|news|nfs|ni|nih|nntp|opaquelocktoken|pop|pres|rtsp|service|session|shttp|sieve|sip|sips|sms|snmp|soap\.beep|soap\.beeps|tag|tel|telnet|tftp|thismessage|tn3270|tip|tv|urn|vemmi|ws|wss|xcon|xcon-userid|xmlrpc\.beep|xmlrpc\.beeps|xmpp|z39\.50r|z39\.50s|adiumxtra|afp|afs|aim|apt|attachment|aw|beshare|bitcoin|bolo|callto|chrome|chrome-extension|com-eventbrite-attendee|content|cvs|dlna-playsingle|dlna-playcontainer|dtn|dvb|ed2k|facetime|feed|finger|fish|gg|git|gizmoproject|gtalk|hcp|icon|ipn|irc|irc6|ircs|itms|jar|jms|keyparc|lastfm|ldaps|magnet|maps|market|message|mms|ms-help|msnim|mumble|mvn|notes|oid|palm|paparazzi|platform|proxy|psyc|query|res|resource|rmi|rsync|rtmp|secondlife|sftp|sgn|skype|smb|soldat|spotify|ssh|steam|svn|teamspeak|things|udp|unreal|ut2004|ventrilo|view-source|webcal|wtai|wyciwyg|xfire|xri|ymsgr:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]|\([^\s()<>]*\))+(?:\([^\s()<>]*\)|[^\s`*!()\[\]{};:'".,<>?«»“”‘’]))/i
|
||||||
var codeDepth = 0;
|
|
||||||
|
|
||||||
|
CodeMirror.defineMode("gfm", function(config, modeConfig) {
|
||||||
|
// Should GitHub spice be added (like linking #Num, SHA, etc.)
|
||||||
|
if (modeConfig.gitHubSpice === undefined)
|
||||||
|
modeConfig.gitHubSpice = true;
|
||||||
|
|
||||||
|
var codeDepth = 0;
|
||||||
function blankLine(state) {
|
function blankLine(state) {
|
||||||
state.code = false;
|
state.code = false;
|
||||||
return null;
|
return null;
|
||||||
@ -80,12 +84,28 @@
|
|||||||
}
|
}
|
||||||
if (stream.sol() || state.ateSpace) {
|
if (stream.sol() || state.ateSpace) {
|
||||||
state.ateSpace = false;
|
state.ateSpace = false;
|
||||||
|
if (modeConfig.gitHubSpice) {
|
||||||
|
if(stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+@)?(?:[a-f0-9]{7,40}\b)/)) {
|
||||||
|
// User/Project@SHA
|
||||||
|
// User@SHA
|
||||||
|
// SHA
|
||||||
|
state.combineTokens = true;
|
||||||
|
return "link";
|
||||||
|
} else if (stream.match(/^(?:[a-zA-Z0-9\-_]+\/)?(?:[a-zA-Z0-9\-_]+)?#[0-9]+\b/)) {
|
||||||
|
// User/Project#Num
|
||||||
|
// User#Num
|
||||||
|
// #Num
|
||||||
|
state.combineTokens = true;
|
||||||
|
return "link";
|
||||||
}
|
}
|
||||||
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) &&
|
}
|
||||||
|
}
|
||||||
|
if (stream.match(urlRE) &&
|
||||||
stream.string.slice(stream.start - 2, stream.start) != "](") {
|
stream.string.slice(stream.start - 2, stream.start) != "](") {
|
||||||
// URLs
|
// URLs
|
||||||
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
// Taken from http://daringfireball.net/2010/07/improved_regex_for_matching_urls
|
||||||
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
|
// And then (issue #1160) simplified to make it not crash the Chrome Regexp engine
|
||||||
|
// And then limited url schemes to the CommonMark list, so foo:bar isn't matched as a URL
|
||||||
state.combineTokens = true;
|
state.combineTokens = true;
|
||||||
return "link";
|
return "link";
|
||||||
}
|
}
|
||||||
|
53
src/js/codemirror/tablist.js
Normal file
53
src/js/codemirror/tablist.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// CodeMirror, copyright (c) by Marijn Haverbeke and others
|
||||||
|
// Distributed under an MIT license: http://codemirror.net/LICENSE
|
||||||
|
|
||||||
|
(function(mod) {
|
||||||
|
if (typeof exports == "object" && typeof module == "object") // CommonJS
|
||||||
|
mod(require("../../lib/codemirror"));
|
||||||
|
else if (typeof define == "function" && define.amd) // AMD
|
||||||
|
define(["../../lib/codemirror"], mod);
|
||||||
|
else // Plain browser env
|
||||||
|
mod(CodeMirror);
|
||||||
|
})(function(CodeMirror) {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
CodeMirror.commands.tabAndIndentMarkdownList = function(cm) {
|
||||||
|
var ranges = cm.listSelections();
|
||||||
|
var pos = ranges[0].head;
|
||||||
|
var eolState = cm.getStateAfter(pos.line);
|
||||||
|
var inList = eolState.list !== false;
|
||||||
|
|
||||||
|
if (inList) {
|
||||||
|
cm.execCommand('indentMore');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cm.options.indentWithTabs){
|
||||||
|
cm.execCommand('insertTab');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var spaces = Array(cm.options.tabSize + 1).join(" ");
|
||||||
|
cm.replaceSelection(spaces);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
CodeMirror.commands.shiftTabAndUnindentMarkdownList = function(cm) {
|
||||||
|
var ranges = cm.listSelections();
|
||||||
|
var pos = ranges[0].head;
|
||||||
|
var eolState = cm.getStateAfter(pos.line);
|
||||||
|
var inList = eolState.list !== false;
|
||||||
|
|
||||||
|
if (inList) {
|
||||||
|
cm.execCommand('indentLess');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(cm.options.indentWithTabs){
|
||||||
|
cm.execCommand('insertTab');
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var spaces = Array(cm.options.tabSize + 1).join(" ");
|
||||||
|
cm.replaceSelection(spaces);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user