Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: fix https://github.com/siyuan-note/siyuan/issues/8186

Vanessaf85b5d6740ad
diff --git a/app/src/plugin/loader.ts b/app/src/plugin/loader.ts
index 3118bc889d..e0cf202fcf 100644
--- a/app/src/plugin/loader.ts
+++ b/app/src/plugin/loader.ts
@@ -23,7 +23,7 @@ export const loadPlugins = (app: App) => {
const exportsObj: { [key: string]: any } = {};
const moduleObj = {exports: exportsObj};
try {
- runCode(item.js, "plugin:" + encodeURIComponent(item.id))(getObject, moduleObj, exportsObj);
+ runCode(item.js, "plugin:" + encodeURIComponent(item.name))(getObject, moduleObj, exportsObj);
} catch (e) {
console.error(`eval plugin ${item.name} error:`, e);
return;
diff --git a/app/src/protyle/toolbar/Font.ts b/app/src/protyle/toolbar/Font.ts
index 5e67d5d4a3..7790d67842 100644
--- a/app/src/protyle/toolbar/Font.ts
+++ b/app/src/protyle/toolbar/Font.ts
@@ -181,6 +181,7 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
// 标签等元素中包含 ZWSP,需移除后拼接 https://github.com/siyuan-note/siyuan/issues/6466
textElement.setAttribute("data-id", blockRefData.splice(0, 1)[0]);
textElement.setAttribute("data-subtype", blockRefData.splice(0, 1)[0]);
+ textElement.removeAttribute("data-href");
textElement.innerText = blockRefData.join("");
};
const setLink = (textOption: string) => {
@@ -192,6 +193,15 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
textElement.textContent = options[1];
}
};
+ const setFileAnnotation = (textOption: string) => {
+ const options = textOption.split(Constants.ZWSP);
+ textElement.setAttribute("data-id", options[0]);
+ textElement.removeAttribute("data-href");
+ textElement.removeAttribute("data-subtype");
+ if (options[1]) {
+ textElement.textContent = options[1];
+ }
+ };
if (textOption) {
switch (textOption.type) {
@@ -225,6 +235,9 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
case "a":
setLink(textOption.color);
break;
+ case "file-annotation-ref":
+ setFileAnnotation(textOption.color);
+ break;
case "inline-memo":
textElement.removeAttribute("contenteditable");
textElement.removeAttribute("data-subtype");
diff --git a/app/src/protyle/toolbar/index.ts b/app/src/protyle/toolbar/index.ts
index f3fb30a49c..a2875b1b0a 100644
--- a/app/src/protyle/toolbar/index.ts
+++ b/app/src/protyle/toolbar/index.ts
@@ -497,18 +497,26 @@ export class Toolbar {
return true;
}
});
- } else if (type === "block-ref" && types.includes("a")) {
- // 虚拟引用和链接不能同时存在
+ } else if (type === "block-ref" && (types.includes("a") || types.includes("file-annotation-ref"))) {
+ // 虚拟引用和链接/标注不能同时存在
types.find((item, index) => {
- if (item === "a") {
+ if (item === "a"||item === "file-annotation-ref") {
types.splice(index, 1);
return true;
}
});
- } else if (type === "a" && types.includes("block-ref")) {
- // 链接和引用不能同时存在
+ } else if (type === "a" && (types.includes("block-ref")|| types.includes("file-annotation-ref"))) {
+ // 链接和引用/标注不能同时存在
types.find((item, index) => {
- if (item === "block-ref") {
+ if (item === "block-ref"||item === "file-annotation-ref") {
+ types.splice(index, 1);
+ return true;
+ }
+ });
+ } else if (type === "file-annotation-ref" && (types.includes("block-ref")|| types.includes("a"))) {
+ // 引用和链接/标注不能同时存在
+ types.find((item, index) => {
+ if (item === "block-ref"||item === "a") {
types.splice(index, 1);
return true;
}
diff --git a/app/src/protyle/util/paste.ts b/app/src/protyle/util/paste.ts
index 46031fb1e0..efef9faf3b 100644
--- a/app/src/protyle/util/paste.ts
+++ b/app/src/protyle/util/paste.ts
@@ -256,11 +256,23 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
} else if (textPlain.trim() !== "" && files && files.length === 0) {
if (range.toString() !== "") {
if (isDynamicRef(textPlain)) {
- textPlain = textPlain.replace(/'.*'\)\)$/, ` "${Lute.EscapeHTMLStr(range.toString())}"))`);
+ protyle.toolbar.setInlineMark(protyle, "block-ref", "range", {
+ type: "id",
+ color: `${textPlain.substring(2, 22 + 2)}${Constants.ZWSP}s${Constants.ZWSP}${Lute.EscapeHTMLStr(range.toString())}`
+ });
+ return;
} else if (isFileAnnotation(textPlain)) {
- textPlain = textPlain.replace(/".+">>$/, `"${Lute.EscapeHTMLStr(range.toString())}">>`);
+ protyle.toolbar.setInlineMark(protyle, "file-annotation-ref", "range", {
+ type: "file-annotation-ref",
+ color: textPlain.substring(2).replace(/ ".+">>$/, "") + Constants.ZWSP + Lute.EscapeHTMLStr(range.toString())
+ });
+ return;
} else if (protyle.lute.IsValidLinkDest(textPlain)) {
- textPlain = `[${range.toString()}](${textPlain})`;
+ protyle.toolbar.setInlineMark(protyle, "a", "range", {
+ type: "a",
+ color: textPlain + Constants.ZWSP + Lute.EscapeHTMLStr(range.toString())
+ });
+ return;
}
}
const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);