Changed the _replaceSelection startEnd arg to be an array;

Create the replaceTexts var;
Extending the replaceText with the options (using the merging functions);
Use the replaceText option for the drawLink and drawImage functions
pull/151/head
Alex Canessa 9 years ago
parent fee8a87c06
commit 07196a532f

@ -260,27 +260,26 @@ function toggleOrderedList(editor) {
_toggleLine(cm, "ordered-list");
}
/**
* Action for drawing a link.
*/
function drawLink(editor) {
var cm = editor.codemirror;
var stat = getState(cm);
_replaceSelection(cm, stat.link, "[", "](http://)");
var options = editor.options;
_replaceSelection(cm, stat.link, options.replaceTexts.link);
}
/**
* Action for drawing an img.
*/
function drawImage(editor) {
var cm = editor.codemirror;
var stat = getState(cm);
_replaceSelection(cm, stat.image, "![](http://", ")");
var options = editor.options;
_replaceSelection(cm, stat.image, options.replaceTexts.image);
}
/**
* Action for drawing a horizontal rule.
*/
@ -399,11 +398,13 @@ function togglePreview(editor) {
toggleSideBySide(editor);
}
function _replaceSelection(cm, active, start, end) {
function _replaceSelection(cm, active, startEnd) {
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
return;
var text;
var start = startEnd[0];
var end = startEnd[1];
var startPoint = cm.getCursor("start");
var endPoint = cm.getCursor("end");
if(active) {
@ -789,6 +790,10 @@ var toolbarBuiltInButtons = {
}
};
var replaceTexts = {
link: ["[", "](http://)"],
image: ["![](http://", ")"]
};
/**
* Interface of SimpleMDE.
@ -861,6 +866,10 @@ function SimpleMDE(options) {
options.parsingConfig = options.parsingConfig || {};
// Merging the replaceTexts, with the given options
options.replaceTexts = extend({}, replaceTexts, options.replaceTexts || {});
// Update this options
this.options = options;

Loading…
Cancel
Save