|
|
|
@ -844,13 +844,11 @@ function drawLink(editor) {
|
|
|
|
|
var options = editor.options;
|
|
|
|
|
var url = 'https://';
|
|
|
|
|
if (options.promptURLs) {
|
|
|
|
|
url = prompt(options.promptTexts.link, 'https://');
|
|
|
|
|
url = prompt(options.promptTexts.link, url);
|
|
|
|
|
if (!url) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url = encodeURI(url);
|
|
|
|
|
if (/[()]/.test(url)) url = escapePromptURL(url);
|
|
|
|
|
url = escapePromptURL(url);
|
|
|
|
|
}
|
|
|
|
|
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
|
|
|
|
}
|
|
|
|
@ -864,25 +862,21 @@ function drawImage(editor) {
|
|
|
|
|
var options = editor.options;
|
|
|
|
|
var url = 'https://';
|
|
|
|
|
if (options.promptURLs) {
|
|
|
|
|
url = prompt(options.promptTexts.image, 'https://');
|
|
|
|
|
url = prompt(options.promptTexts.image, url);
|
|
|
|
|
if (!url) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
url = encodeURI(url);
|
|
|
|
|
if (/[()]/.test(url)) url = escapePromptURL(url);
|
|
|
|
|
url = escapePromptURL(url);
|
|
|
|
|
}
|
|
|
|
|
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Escape URLs to prevent breaking up rendered Markdown links
|
|
|
|
|
* Encode and escape URLs to prevent breaking up rendered Markdown links.
|
|
|
|
|
* @param url {string} The url of the link or image
|
|
|
|
|
*/
|
|
|
|
|
function escapePromptURL(url) {
|
|
|
|
|
url = url.replace(/\(/g,'\\(').replace(/\)/g,'\\)');
|
|
|
|
|
|
|
|
|
|
return url;
|
|
|
|
|
return encodeURI(url).replace(/([\\()])/g, '\\$1');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|