mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-21 17:10:12 +01:00
This commit is contained in:
parent
db6521181e
commit
f85b5d6740
4 changed files with 43 additions and 10 deletions
|
|
@ -23,7 +23,7 @@ export const loadPlugins = (app: App) => {
|
||||||
const exportsObj: { [key: string]: any } = {};
|
const exportsObj: { [key: string]: any } = {};
|
||||||
const moduleObj = {exports: exportsObj};
|
const moduleObj = {exports: exportsObj};
|
||||||
try {
|
try {
|
||||||
runCode(item.js, "plugin:" + encodeURIComponent(item.id))(getObject, moduleObj, exportsObj);
|
runCode(item.js, "plugin:" + encodeURIComponent(item.name))(getObject, moduleObj, exportsObj);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(`eval plugin ${item.name} error:`, e);
|
console.error(`eval plugin ${item.name} error:`, e);
|
||||||
return;
|
return;
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
|
||||||
// 标签等元素中包含 ZWSP,需移除后拼接 https://github.com/siyuan-note/siyuan/issues/6466
|
// 标签等元素中包含 ZWSP,需移除后拼接 https://github.com/siyuan-note/siyuan/issues/6466
|
||||||
textElement.setAttribute("data-id", blockRefData.splice(0, 1)[0]);
|
textElement.setAttribute("data-id", blockRefData.splice(0, 1)[0]);
|
||||||
textElement.setAttribute("data-subtype", blockRefData.splice(0, 1)[0]);
|
textElement.setAttribute("data-subtype", blockRefData.splice(0, 1)[0]);
|
||||||
|
textElement.removeAttribute("data-href");
|
||||||
textElement.innerText = blockRefData.join("");
|
textElement.innerText = blockRefData.join("");
|
||||||
};
|
};
|
||||||
const setLink = (textOption: string) => {
|
const setLink = (textOption: string) => {
|
||||||
|
|
@ -192,6 +193,15 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
|
||||||
textElement.textContent = options[1];
|
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) {
|
if (textOption) {
|
||||||
switch (textOption.type) {
|
switch (textOption.type) {
|
||||||
|
|
@ -225,6 +235,9 @@ export const setFontStyle = (textElement: HTMLElement, textOption: ITextOption)
|
||||||
case "a":
|
case "a":
|
||||||
setLink(textOption.color);
|
setLink(textOption.color);
|
||||||
break;
|
break;
|
||||||
|
case "file-annotation-ref":
|
||||||
|
setFileAnnotation(textOption.color);
|
||||||
|
break;
|
||||||
case "inline-memo":
|
case "inline-memo":
|
||||||
textElement.removeAttribute("contenteditable");
|
textElement.removeAttribute("contenteditable");
|
||||||
textElement.removeAttribute("data-subtype");
|
textElement.removeAttribute("data-subtype");
|
||||||
|
|
|
||||||
|
|
@ -497,18 +497,26 @@ export class Toolbar {
|
||||||
return true;
|
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) => {
|
types.find((item, index) => {
|
||||||
if (item === "a") {
|
if (item === "a"||item === "file-annotation-ref") {
|
||||||
types.splice(index, 1);
|
types.splice(index, 1);
|
||||||
return true;
|
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) => {
|
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);
|
types.splice(index, 1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -256,11 +256,23 @@ export const paste = async (protyle: IProtyle, event: (ClipboardEvent | DragEven
|
||||||
} else if (textPlain.trim() !== "" && files && files.length === 0) {
|
} else if (textPlain.trim() !== "" && files && files.length === 0) {
|
||||||
if (range.toString() !== "") {
|
if (range.toString() !== "") {
|
||||||
if (isDynamicRef(textPlain)) {
|
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)) {
|
} 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)) {
|
} 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);
|
const textPlainDom = protyle.lute.Md2BlockDOM(textPlain);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue