mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-31 05:44:28 -06:00
URL encoding and escaping for JS prompt URLs
- URL encoding and escaping added for JS prompt entered URLs - added option escapeURLs (boolean)
This commit is contained in:
parent
5d0294f5f5
commit
33489ab616
@ -849,7 +849,10 @@ function drawLink(editor) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/[()<>]/.test(url)) url = escapeUrl(url);
|
if (options.escapeURLs) {
|
||||||
|
url = encodeURI(url);
|
||||||
|
if (/[()]/.test(url)) url = escapeURI(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
_replaceSelection(cm, stat.link, options.insertTexts.link, url);
|
||||||
}
|
}
|
||||||
@ -868,7 +871,10 @@ function drawImage(editor) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (/[()<>]/.test(url)) url = escapeUrl(url);
|
if (options.escapeURLs) {
|
||||||
|
url = encodeURI(url);
|
||||||
|
if (/[()]/.test(url)) url = escapeURI(url);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
_replaceSelection(cm, stat.image, options.insertTexts.image, url);
|
||||||
}
|
}
|
||||||
@ -877,12 +883,8 @@ function drawImage(editor) {
|
|||||||
* Escape URLs to prevent breaking up rendered Markdown links
|
* Escape URLs to prevent breaking up rendered Markdown links
|
||||||
* @param url {string} The url of the link or image
|
* @param url {string} The url of the link or image
|
||||||
*/
|
*/
|
||||||
function escapeUrl(url) {
|
function escapeURI(url) {
|
||||||
|
url = url.replace(/\(/g,'\\(').replace(/\)/g,'\\)');
|
||||||
url = url.replace(/\(/g,'\\(')
|
|
||||||
.replace(/\)/g,'\\)')
|
|
||||||
.replace(/</g,'\\<')
|
|
||||||
.replace(/>/g,'\\>');
|
|
||||||
|
|
||||||
return url;
|
return url;
|
||||||
}
|
}
|
||||||
|
1
types/easymde.d.ts
vendored
1
types/easymde.d.ts
vendored
@ -197,6 +197,7 @@ declare namespace EasyMDE {
|
|||||||
previewImagesInEditor?: boolean;
|
previewImagesInEditor?: boolean;
|
||||||
previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string;
|
previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string;
|
||||||
promptURLs?: boolean;
|
promptURLs?: boolean;
|
||||||
|
escapeURLs?: boolean;
|
||||||
renderingConfig?: RenderingOptions;
|
renderingConfig?: RenderingOptions;
|
||||||
shortcuts?: Shortcuts;
|
shortcuts?: Shortcuts;
|
||||||
showIcons?: ReadonlyArray<ToolbarButton>;
|
showIcons?: ReadonlyArray<ToolbarButton>;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user