فهرست منبع

:art: https://github.com/siyuan-note/siyuan/issues/11124

Vanessa 1 سال پیش
والد
کامیت
f64dd4543a
4فایلهای تغییر یافته به همراه24 افزوده شده و 18 حذف شده
  1. 1 1
      app/src/menus/protyle.ts
  2. 7 7
      app/src/protyle/toolbar/Link.ts
  3. 15 9
      app/src/protyle/util/paste.ts
  4. 1 1
      app/src/types/protyle.d.ts

+ 1 - 1
app/src/menus/protyle.ts

@@ -1294,7 +1294,7 @@ export const linkMenu = (protyle: IProtyle, linkElement: HTMLElement, focusText
     });
     const popoverElement = hasTopClosestByClassName(protyle.element, "block__popover", true);
     window.siyuan.menus.menu.element.setAttribute("data-from", popoverElement ? popoverElement.dataset.level + "popover" : "app");
-    if (focusText || protyle.lute.IsValidLinkDest(linkAddress)) {
+    if (focusText || protyle.lute.GetLinkDest(linkAddress)) {
         inputElements[1].select();
     } else {
         inputElements[0].select();

+ 7 - 7
app/src/protyle/toolbar/Link.ts

@@ -31,16 +31,16 @@ export class Link extends ToolbarItem {
             try {
                 const clipText = await readText();
                 // 选中链接时需忽略剪切板内容 https://ld246.com/article/1643035329737
-                if (protyle.lute.IsValidLinkDest(rangeString)) {
-                    dataHref = rangeString;
-                } else if (protyle.lute.IsValidLinkDest(clipText)) {
-                    dataHref = clipText;
-                } else {
+                dataHref = protyle.lute.GetLinkDest(rangeString);
+                if (!dataHref) {
+                    dataHref = protyle.lute.GetLinkDest(clipText);
+                }
+                if (!dataHref) {
                     // 360
                     const lastSpace = clipText.lastIndexOf(" ");
                     if (lastSpace > -1) {
-                        if (protyle.lute.IsValidLinkDest(clipText.substring(lastSpace))) {
-                            dataHref = clipText.substring(lastSpace);
+                        dataHref = protyle.lute.GetLinkDest(clipText.substring(lastSpace));
+                        if (dataHref) {
                             dataText = clipText.substring(0, lastSpace);
                         }
                     }

+ 15 - 9
app/src/protyle/util/paste.ts

@@ -43,7 +43,7 @@ export const getTextStar = (blockElement: HTMLElement) => {
         } else if (blockElement.classList.contains("render-node")) {
             // 需在嵌入块后,代码块前
             refText += blockElement.dataset.subtype || Lute.UnEscapeHTMLStr(blockElement.getAttribute("data-content"));
-        }  else if (["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) {
+        } else if (["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(dataType)) {
             Array.from(blockElement.querySelectorAll("[data-node-id]")).find((item: HTMLElement) => {
                 if (!["NodeBlockquote", "NodeList", "NodeSuperBlock", "NodeListItem"].includes(item.getAttribute("data-type"))) {
                     refText = getTextStar(blockElement.querySelector("[data-node-id]"));
@@ -190,8 +190,11 @@ export const pasteText = (protyle: IProtyle, textPlain: string, nodeElement: Ele
             textPlain = textPlain.replace(/'.+'\)\)$/, ` "${range.toString()}"))`);
         } else if (isFileAnnotation(textPlain)) {
             textPlain = textPlain.replace(/".+">>$/, `"${range.toString()}">>`);
-        } else if (protyle.lute.IsValidLinkDest(textPlain)) {
-            textPlain = `[${range.toString()}](${textPlain})`;
+        } else {
+            const linkDest = protyle.lute.GetLinkDest(textPlain)
+            if (linkDest) {
+                textPlain = `[${range.toString()}](${linkDest})`;
+            }
         }
     }
     insertHTML(protyle.lute.Md2BlockDOM(textPlain), protyle);
@@ -443,13 +446,16 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
                         color: firstLine.substring(2).replace(/ ".+">>$/, "")
                     });
                     return;
-                } else if (protyle.lute.IsValidLinkDest(textPlain)) {
+                } else {
                     // https://github.com/siyuan-note/siyuan/issues/8475
-                    protyle.toolbar.setInlineMark(protyle, "a", "range", {
-                        type: "a",
-                        color: textPlain
-                    });
-                    return;
+                    const linkDest = protyle.lute.GetLinkDest(textPlain)
+                    if (linkDest) {
+                        protyle.toolbar.setInlineMark(protyle, "a", "range", {
+                            type: "a",
+                            color: linkDest
+                        });
+                        return;
+                    }
                 }
             }
             const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);

+ 1 - 1
app/src/types/protyle.d.ts

@@ -240,7 +240,7 @@ declare class Lute {
 
     public MarkdownStr(name: string, md: string): string;
 
-    public IsValidLinkDest(text: string): boolean;
+    public GetLinkDest(text: string): string;
 
     public BlockDOM2InlineBlockDOM(html: string): string;