Skip to content

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

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

Vanessa999081b57333
diff --git a/app/src/plugin/customBlockRender.ts b/app/src/plugin/customBlockRender.ts
new file mode 100644
index 0000000000..0ae1149220
--- /dev/null
+++ b/app/src/plugin/customBlockRender.ts
@@ -0,0 +1,32 @@
+import {App} from "../index";
+
+export const customBlockRender = (app: App, element: Element) => {
+ // TODO
+ let abcElements: Element[] = [];
+ if (element.getAttribute("data-subtype") === "abc") {
+ // 编辑器内代码块编辑渲染
+ abcElements = [element];
+ } else {
+ abcElements = Array.from(element.querySelectorAll('[data-subtype="abc"]'));
+ }
+ if (abcElements.length === 0) {
+ return;
+ }
+ if (abcElements.length > 0) {
+ abcElements.forEach((e: HTMLDivElement) => {
+ if (e.getAttribute("data-render") === "true") {
+ return;
+ }
+ if (!e.firstElementChild.classList.contains("protyle-icons")) {
+ e.insertAdjacentHTML("afterbegin", '<div class="protyle-icons"><span class="protyle-icon protyle-icon--first protyle-action__edit"><svg><use xlink:href="#iconEdit"></use></svg></span><span class="protyle-icon protyle-action__menu protyle-icon--last"><svg><use xlink:href="#iconMore"></use></svg></span></div>');
+ }
+ if (e.childElementCount < 4) {
+ e.lastElementChild.insertAdjacentHTML("beforebegin", `<span style="position: absolute">${Constants.ZWSP}</span>`);
+ }
+ const renderElement = e.firstElementChild.nextElementSibling as HTMLElement;
+
+ renderElement.setAttribute("contenteditable", "false");
+ e.setAttribute("data-render", "true");
+ });
+ }
+};
diff --git a/app/src/plugin/index.ts b/app/src/plugin/index.ts
index 48380d45b7..cbf2fe2f09 100644
--- a/app/src/plugin/index.ts
+++ b/app/src/plugin/index.ts
@@ -17,6 +17,15 @@ export class Plugin {
public eventBus: EventBus;
public data: any = {};
public name: string;
+ // TODO
+ public customBlockRenders: {
+ [key: string]: {
+ icon: string,
+ action: "edit" | "more"[],
+ genCursor: boolean,
+ render: (options: { app: App, element: Element }) => void
+ }
+ } = {};
public topBarIcons: Element[] = [];
public setting: Setting;
public statusBarIcons: Element[] = [];