diff --git a/app/src/menus/protyle.ts b/app/src/menus/protyle.ts index 388c78603..2887b5210 100644 --- a/app/src/menus/protyle.ts +++ b/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(); diff --git a/app/src/protyle/toolbar/Link.ts b/app/src/protyle/toolbar/Link.ts index 93ae0ee88..47b6019e8 100644 --- a/app/src/protyle/toolbar/Link.ts +++ b/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); } } diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts index eb00d9e97..bc2307fc0 100644 --- a/app/src/protyle/util/paste.ts +++ b/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); diff --git a/app/src/types/protyle.d.ts b/app/src/types/protyle.d.ts index 89a736e9a..28e3e90ae 100644 --- a/app/src/types/protyle.d.ts +++ b/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;