Liyuan Li 5 years ago
parent
commit
180ee019e7
5 changed files with 17 additions and 15 deletions
  1. 4 4
      CHANGELOG.md
  2. 6 4
      src/ts/ir/index.ts
  3. 2 2
      src/ts/sv/html2md.ts
  4. 3 3
      src/ts/util/fixBrowserBehavior.ts
  5. 2 2
      src/ts/wysiwyg/index.ts

+ 4 - 4
CHANGELOG.md

@@ -49,14 +49,14 @@
 
 * [open issues](https://github.com/Vanessa219/vditor/issues)
 
-### v3.0.10 / 2020-04-0x
+### v3.0.11 / 2020-04-0x
 
+### v3.0.10 / 2020-04-04
+
+* [266](https://github.com/Vanessa219/vditor/issues/266) linkToImgUrl 图片重复上传 `修复缺陷`
 * [208](https://github.com/Vanessa219/vditor/issues/208) hr in Firefox `修复缺陷`
 * [274](https://github.com/Vanessa219/vditor/issues/274) Toc demo at Preview `文档相关`
 * [269](https://github.com/Vanessa219/vditor/issues/269) 分屏预览支持 list-style-type CSS `引入特性`
-
-### v3.0.9 / 2020-04-04
-
 * [265](https://github.com/Vanessa219/vditor/issues/265) ir 模式中 toc, 链接引用,脚注 `引入特性`
 * [271](https://github.com/Vanessa219/vditor/issues/271) options.toolbar支持自定义绑定class `引入特性`
 * [267](https://github.com/Vanessa219/vditor/issues/267) 设置 codeBlockPreview false, esc 后代码块消失 `修复缺陷`

+ 6 - 4
src/ts/ir/index.ts

@@ -119,26 +119,28 @@ class IR {
                                         setHeaders(vditor, xhr);
                                         xhr.onreadystatechange = () => {
                                             if (xhr.readyState === XMLHttpRequest.DONE) {
-                                                const responseJSON = JSON.parse(xhr.responseText);
                                                 if (xhr.status === 200) {
+                                                    const responseJSON = JSON.parse(xhr.responseText);
                                                     if (responseJSON.code !== 0) {
                                                         vditor.tip.show(responseJSON.msg);
                                                         return;
                                                     }
-                                                    // TODO
                                                     const original = responseJSON.data.originalURL;
                                                     const imgElement: HTMLImageElement =
                                                         this.element.querySelector(`img[src="${original}"]`);
                                                     imgElement.src = responseJSON.data.url;
+                                                    imgElement.previousElementSibling.previousElementSibling.innerHTML =
+                                                        responseJSON.data.url;
                                                     processAfterRender(vditor);
                                                 } else {
-                                                    vditor.tip.show(responseJSON.msg);
+                                                    vditor.tip.show(xhr.responseText);
                                                 }
                                             }
                                         };
                                         xhr.send(JSON.stringify({url: src}));
                                     }
-                                    return ["", Lute.WalkStop];
+                                    return [`<span class="vditor-ir__marker vditor-ir__marker--link">${src}</span>`,
+                                        Lute.WalkStop];
                                 },
                             },
                         },

+ 2 - 2
src/ts/sv/html2md.ts

@@ -31,8 +31,8 @@ export const html2md = (vditor: IVditor, textHTML: string, textPlain?: string) =
                         setHeaders(vditor, xhr);
                         xhr.onreadystatechange = () => {
                             if (xhr.readyState === XMLHttpRequest.DONE) {
-                                const responseJSON = JSON.parse(xhr.responseText);
                                 if (xhr.status === 200) {
+                                    const responseJSON = JSON.parse(xhr.responseText);
                                     if (responseJSON.code !== 0) {
                                         vditor.tip.show(responseJSON.msg);
                                         return;
@@ -41,7 +41,7 @@ export const html2md = (vditor: IVditor, textHTML: string, textPlain?: string) =
                                     setSelectionByInlineText(original, vditor.sv.element.childNodes);
                                     insertText(vditor, responseJSON.data.url, "", true);
                                 } else {
-                                    vditor.tip.show(responseJSON.msg);
+                                    vditor.tip.show(xhr.responseText);
                                 }
                             }
                         };

+ 3 - 3
src/ts/util/fixBrowserBehavior.ts

@@ -940,8 +940,8 @@ export const fixTask = (vditor: IVditor, range: Range, event: KeyboardEvent) =>
 export const fixDelete = (vditor: IVditor, range: Range, event: KeyboardEvent, pElement: HTMLElement | false) => {
     if (range.startContainer.nodeType !== 3) {
         // 光标位于 hr 前,hr 前有内容
-        const rangeElement = (range.startContainer as HTMLElement).children[range.startOffset]
-        if (rangeElement && rangeElement.tagName === 'HR') {
+        const rangeElement = (range.startContainer as HTMLElement).children[range.startOffset];
+        if (rangeElement && rangeElement.tagName === "HR") {
             range.selectNodeContents(rangeElement.previousElementSibling);
             range.collapse(false);
             event.preventDefault();
@@ -977,4 +977,4 @@ export const fixHR = (range: Range) => {
         (range.startContainer as HTMLElement).tagName === "HR") {
         range.setStartBefore(range.startContainer);
     }
-}
+};

+ 2 - 2
src/ts/wysiwyg/index.ts

@@ -184,8 +184,8 @@ class WYSIWYG {
                                         setHeaders(vditor, xhr);
                                         xhr.onreadystatechange = () => {
                                             if (xhr.readyState === XMLHttpRequest.DONE) {
-                                                const responseJSON = JSON.parse(xhr.responseText);
                                                 if (xhr.status === 200) {
+                                                    const responseJSON = JSON.parse(xhr.responseText);
                                                     if (responseJSON.code !== 0) {
                                                         vditor.tip.show(responseJSON.msg);
                                                         return;
@@ -196,7 +196,7 @@ class WYSIWYG {
                                                     imgElement.src = responseJSON.data.url;
                                                     afterRenderEvent(vditor);
                                                 } else {
-                                                    vditor.tip.show(responseJSON.msg);
+                                                    vditor.tip.show(xhr.responseText);
                                                 }
                                             }
                                         };