This commit is contained in:
parent
2710c7c2eb
commit
f64dd4543a
4 changed files with 24 additions and 18 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
2
app/src/types/protyle.d.ts
vendored
2
app/src/types/protyle.d.ts
vendored
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue