2
0
mirror of https://github.com/Ionaru/easy-markdown-editor synced 2025-08-12 03:32:44 -06:00

added option to readme, imagesPreviewHandler to types and defensive check that the handler provided by the user returns a string

This commit is contained in:
Diego Garcia Weber 2022-03-01 20:47:30 -05:00
parent d8fa00e460
commit ed196be5a0
3 changed files with 8 additions and 1 deletions

View File

@ -144,6 +144,7 @@ easyMDE.value('New input for **EasyMDE**');
- **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`. - **indentWithTabs**: If set to `false`, indent using spaces instead of tabs. Defaults to `true`.
- **initialValue**: If set, will customize the initial value of the editor. - **initialValue**: If set, will customize the initial value of the editor.
- **previewImagesInEditor**: - EasyMDE will show preview of images, `false` by default, preview for images will appear only for images on separate lines. - **previewImagesInEditor**: - EasyMDE will show preview of images, `false` by default, preview for images will appear only for images on separate lines.
- **imagesPreviewHandler**: - A custom function for handling the preview of images. Takes the parsed string from the image markdown `![](string)` as argument and returns a string that serves as the `src` attribute of the `<img>` tag in the preview (for ex. as base64). Enables dynamic previewing of images in the frontend without having to upload them to a server.
- **insertTexts**: Customize how certain buttons that insert text behave. Takes an array with two elements. The first element will be the text inserted before the cursor or highlight, and the second element will be inserted after. For example, this is the default link value: `["[", "](http://)"]`. - **insertTexts**: Customize how certain buttons that insert text behave. Takes an array with two elements. The first element will be the text inserted before the cursor or highlight, and the second element will be inserted after. For example, this is the default link value: `["[", "](http://)"]`.
- horizontalRule - horizontalRule
- image - image

View File

@ -2207,8 +2207,13 @@ EasyMDE.prototype.render = function (el) {
if (srcAttr && srcAttr.length >= 2) { if (srcAttr && srcAttr.length >= 2) {
var keySrc = srcAttr[1]; var keySrc = srcAttr[1];
if (options.imagesPreviewHandler) { if (options.imagesPreviewHandler) {
keySrc = options.imagesPreviewHandler(keySrc); var newSrc = options.imagesPreviewHandler(srcAttr[1]);
// defensive check making sure the handler provided by the user returns a string
if (typeof newSrc === 'string') {
keySrc = newSrc;
}
} }
if (!window.EMDEimagesCache[keySrc]) { if (!window.EMDEimagesCache[keySrc]) {

1
types/easymde.d.ts vendored
View File

@ -195,6 +195,7 @@ declare namespace EasyMDE {
placeholder?: string; placeholder?: string;
previewClass?: string | ReadonlyArray<string>; previewClass?: string | ReadonlyArray<string>;
previewImagesInEditor?: boolean; previewImagesInEditor?: boolean;
imagesPreviewHandler?: ((src: string) => string),
previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string; previewRender?: (markdownPlaintext: string, previewElement: HTMLElement) => string;
promptURLs?: boolean; promptURLs?: boolean;
renderingConfig?: RenderingOptions; renderingConfig?: RenderingOptions;