Browse Source

:sparkles: fix https://github.com/Vanessa219/vditor/issues/1186

Vanessa 1 year ago
parent
commit
ad182bdd92
5 changed files with 12 additions and 1 deletions
  1. 2 0
      CHANGELOG.md
  2. 1 0
      README.md
  3. 1 0
      README_en_US.md
  4. 5 1
      src/ts/util/fixBrowserBehavior.ts
  5. 3 0
      types/index.d.ts

+ 2 - 0
CHANGELOG.md

@@ -2,6 +2,7 @@
 
 ### 升级
 * 3.9
+  * 添加 options.upload.renderLinkDest
   * 添加 options.preview.math.mathJaxOptions
   * 添加 hljs.langs
   * 添加 option.keydown
@@ -17,6 +18,7 @@
 
 ### v3.10.6 / 2024-08
 
+* [添加 `upload.renderLinkDest` 用于扩展粘贴时图片链接的处理](https://github.com/Vanessa219/vditor/issues/1186) `引入特性`
 * [图标配置为 `material` 时,列表反向缩进与缩进的图标错误](https://github.com/Vanessa219/vditor/issues/1656) `修复缺陷`
 * [提供非混淆版本的产物代码](https://github.com/Vanessa219/vditor/issues/1653) `开发重构`
 

+ 1 - 0
README.md

@@ -484,6 +484,7 @@ if (xhr.status === 200) {
 | extraData: { [key: string]: string \| Blob } | 为 FormData 添加额外的参数 | - |
 | multiple | 上传文件是否为多个 | true |
 | fieldName | 上传字段名称 | 'file[]' |
+| renderLinkDest?(vditor: IVditor, node: ILuteNode, entering: boolean): [string, number] | 处理剪贴板中的图片地址 | '' |
 
 #### options.resize
 

+ 1 - 0
README_en_US.md

@@ -437,6 +437,7 @@ xhr.send(JSON.stringify({url: src})); // src is the address of the image outside
 | extraData | Append data to FormData { [key: string]: string | Blob } | - |
 | multiple | Allow multiple file uploads | true |
 | fieldName | The key of field name | file[] |
+| renderLinkDest?(vditor: IVditor, node: ILuteNode, entering: boolean): [string, number] | Process the image address in the clipboard | '' |
 
 #### options.resize
 

+ 5 - 1
src/ts/util/fixBrowserBehavior.ts

@@ -1290,6 +1290,10 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
             return ["", Lute.WalkContinue];
         }
 
+        if (vditor.options.upload.renderLinkDest) {
+            return vditor.options.upload.renderLinkDest(vditor, node, entering);
+        }
+
         const src = node.TokensStr();
         if (node.__internal_object__.Parent.Type === 34 && src && src.indexOf("file://") === -1 &&
             vditor.options.upload.linkToImgUrl) {
@@ -1448,7 +1452,7 @@ export const paste = async (vditor: IVditor, event: (ClipboardEvent | DragEvent)
             }
         } else if (textPlain.trim() !== "" && files.length === 0) {
             const range = getEditorRange(vditor);
-            if (range.toString() !== ""  && vditor.lute.IsValidLinkDest(textPlain)) {
+            if (range.toString() !== "" && vditor.lute.IsValidLinkDest(textPlain)) {
                 textPlain = `[${range.toString()}](${textPlain})`;
             }
             if (vditor.currentMode === "ir") {

+ 3 - 0
types/index.d.ts

@@ -350,6 +350,8 @@ interface IUpload {
     max?: number;
     /** 剪切板中包含图片地址时,使用此 url 重新上传 */
     linkToImgUrl?: string;
+    /** 剪切板中包含图片地址时,使用此方法进行自定义 */
+    renderLinkDest?(vditor: IVditor, node: ILuteNode, entering: boolean): [string, number];
     /** CORS 上传验证,头为 X-Upload-Token */
     token?: string;
     /** 文件上传类型,同 [input accept](https://www.w3schools.com/tags/att_input_accept.asp) */
@@ -503,6 +505,7 @@ interface IPreview {
     /** @link https://ld246.com/article/1549638745630#options-preview-actions  */
     actions?: Array<IPreviewAction | IPreviewActionCustom>;
     render?: IPreviewRender
+
     /** 预览回调 */
     parse?(element: HTMLElement): void;