Skip to content

Commit 2651923

Browse files
author
Laszlo Moczo
committed
Optional prompt windows to Link and Image
Optional prompt windows to Link and Image
1 parent 99e4cba commit 2651923

File tree

7 files changed

+457
-305
lines changed

7 files changed

+457
-305
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ simplemde.value("This text will appear in the editor");
9292
- **underscoresBreakWords**: If set to `true`, let underscores be a delimiter for separating words. Defaults to `false`.
9393
- **placeholder**: Custom placeholder that should be displayed
9494
- **previewRender**: Custom function for parsing the plaintext Markdown and returning HTML. Used when user previews.
95+
- **promptURLs**: If set to `true`, a prompt window come if you insert link or image. Defaults to `false`.
96+
- **promptTexts**: An object of prompt text.
97+
-- image (Default: `The URL of image:`)
98+
-- link (Default: `URL for link:`)
9599
- **renderingConfig**: Adjust settings for parsing the Markdown during previewing (not editing).
96100
- **singleLineBreaks**: If set to `false`, disable parsing GFM single line breaks. Defaults to `true`.
97101
- **codeSyntaxHighlighting**: If set to `true`, will highlight using [highlight.js](https://github.com/isagalaev/highlight.js). Defaults to `false`. To use this feature you must include highlight.js on your page. For example, include the script and the CSS files like:<br>`<script src="https://cdn.jsdelivr.net/highlight.js/latest/highlight.min.js"></script>`<br>`<link rel="stylesheet" href="https://cdn.jsdelivr.net/highlight.js/latest/styles/github.min.css">`

debug/simplemde.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
171171
}
172172

173173
/* The fake, visible scrollbars. Used to force redraw during scrolling
174-
before actuall scrolling happens, thus preventing shaking and
174+
before actual scrolling happens, thus preventing shaking and
175175
flickering artifacts. */
176176
.CodeMirror-vscrollbar, .CodeMirror-hscrollbar, .CodeMirror-scrollbar-filler, .CodeMirror-gutter-filler {
177177
position: absolute;

debug/simplemde.debug.js

Lines changed: 211 additions & 147 deletions
Large diffs are not rendered by default.

debug/simplemde.js

Lines changed: 210 additions & 146 deletions
Large diffs are not rendered by default.

dist/simplemde.min.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/simplemde.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/js/simplemde.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,11 @@ function drawLink(editor) {
337337
var cm = editor.codemirror;
338338
var stat = getState(cm);
339339
var options = editor.options;
340-
_replaceSelection(cm, stat.link, options.insertTexts.link);
340+
var url = "http://";
341+
if(options.promptURLs) {
342+
url = prompt(options.promptTexts.link) || "http://";
343+
}
344+
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
341345
}
342346

343347
/**
@@ -347,7 +351,11 @@ function drawImage(editor) {
347351
var cm = editor.codemirror;
348352
var stat = getState(cm);
349353
var options = editor.options;
350-
_replaceSelection(cm, stat.image, options.insertTexts.image);
354+
var url = "http://";
355+
if(options.promptURLs) {
356+
url = prompt(options.promptTexts.image) || "http://";
357+
}
358+
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
351359
}
352360

353361
/**
@@ -491,7 +499,7 @@ function togglePreview(editor) {
491499
toggleSideBySide(editor);
492500
}
493501

494-
function _replaceSelection(cm, active, startEnd) {
502+
function _replaceSelection(cm, active, startEnd, url) {
495503
if(/editor-preview-active/.test(cm.getWrapperElement().lastChild.className))
496504
return;
497505

@@ -500,6 +508,9 @@ function _replaceSelection(cm, active, startEnd) {
500508
var end = startEnd[1];
501509
var startPoint = cm.getCursor("start");
502510
var endPoint = cm.getCursor("end");
511+
if(url) {
512+
end = end.replace("#url#", url);
513+
}
503514
if(active) {
504515
text = cm.getLine(startPoint.line);
505516
start = text.slice(0, startPoint.ch);
@@ -941,12 +952,17 @@ var toolbarBuiltInButtons = {
941952
};
942953

943954
var insertTexts = {
944-
link: ["[", "](http://)"],
945-
image: ["![](http://", ")"],
955+
link: ["[", "](#url#)"],
956+
image: ["![", "](#url#)"],
946957
table: ["", "\n\n| Column 1 | Column 2 | Column 3 |\n| -------- | -------- | -------- |\n| Text | Text | Text |\n\n"],
947958
horizontalRule: ["", "\n\n-----\n\n"]
948959
};
949960

961+
var promptTexts = {
962+
link: "URL for link:",
963+
image: "The URL of image:"
964+
};
965+
950966
var blockStyles = {
951967
"bold": "**",
952968
"italic": "*"
@@ -1045,6 +1061,10 @@ function SimpleMDE(options) {
10451061
options.insertTexts = extend({}, insertTexts, options.insertTexts || {});
10461062

10471063

1064+
// Merging the promptTexts, with the given options
1065+
options.promptTexts = extend({}, promptTexts, options.promptTexts || {});
1066+
1067+
10481068
// Merging the blockStyles, with the given options
10491069
options.blockStyles = extend({}, blockStyles, options.blockStyles || {});
10501070

0 commit comments

Comments
 (0)