mirror of
https://github.com/sparksuite/simplemde-markdown-editor.git
synced 2024-06-13 11:22:30 +02:00
Add parsingConfig option, TODO document
This commit is contained in:
parent
7f4491edee
commit
5ff5766ea6
51
src/js/codemirror/continuelist.js
Normal file
51
src/js/codemirror/continuelist.js
Normal file
|
@ -0,0 +1,51 @@
|
|||
// 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";
|
||||
|
||||
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);
|
||||
};
|
||||
});
|
|
@ -761,6 +761,9 @@ function SimpleMDE(options) {
|
|||
}
|
||||
}
|
||||
|
||||
// Set default options for parsing config
|
||||
options.parsingConfig = options.parsingConfig || {};
|
||||
|
||||
// Update this options
|
||||
this.options = options;
|
||||
|
||||
|
@ -824,8 +827,8 @@ SimpleMDE.prototype.render = function(el) {
|
|||
}
|
||||
|
||||
keyMaps["Enter"] = "newlineAndIndentContinueMarkdownList";
|
||||
keyMaps["Tab"] = "tabAndIndentContinueMarkdownList";
|
||||
keyMaps["Shift-Tab"] = "shiftTabAndIndentContinueMarkdownList";
|
||||
keyMaps["Tab"] = "tabAndIndentMarkdownList";
|
||||
keyMaps["Shift-Tab"] = "shiftTabAndUnindentMarkdownList";
|
||||
keyMaps["F11"] = function(cm) {
|
||||
toggleFullScreen(self);
|
||||
};
|
||||
|
@ -836,18 +839,21 @@ SimpleMDE.prototype.render = function(el) {
|
|||
if(cm.getOption("fullScreen")) cm.setOption("fullScreen", false);
|
||||
};
|
||||
|
||||
var mode = "spell-checker";
|
||||
var backdrop = "gfm";
|
||||
|
||||
if(options.spellChecker === false) {
|
||||
mode = "gfm";
|
||||
backdrop = undefined;
|
||||
var mode, backdrop;
|
||||
if(options.spellChecker !== false) {
|
||||
mode = "spell-checker";
|
||||
backdrop = options.parsingConfig;
|
||||
backdrop.name = "gfm";
|
||||
backdrop.gitHubSpice = false;
|
||||
} else {
|
||||
mode = options.parsingConfig;
|
||||
mode.name = "gfm";
|
||||
mode.gitHubSpice = false;
|
||||
}
|
||||
|
||||
this.codemirror = CodeMirror.fromTextArea(el, {
|
||||
mode: mode,
|
||||
backdrop: backdrop,
|
||||
theme: 'paper',
|
||||
tabSize: (options.tabSize != undefined) ? options.tabSize : 2,
|
||||
indentUnit: (options.tabSize != undefined) ? options.tabSize : 2,
|
||||
indentWithTabs: (options.indentWithTabs === false) ? false : true,
|
||||
|
|
Loading…
Reference in a new issue