Skip to content

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

:art: Centralize built-in custom attribute names https://github.com/siyuan-note/siyuan/issues/20216

Daniel778fbcd734ad
diff --git a/app/src/constants.ts b/app/src/constants.ts
index d30d445430..f8a06b07f3 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -91,6 +91,10 @@ export abstract class Constants {
public static readonly CUSTOM_SY_LIST_MINDMAP_DATA: string = "custom-sy-list-mindmap-data";
public static readonly CUSTOM_SY_TITLE_EMPTY: string = "custom-sy-title-empty";
public static readonly CUSTOM_SY_CODE_TAB_SPACES: string = "custom-sy-code-tab-spaces";
+ public static readonly CUSTOM_SY_TABLE_RICH: string = "custom-sy-table-rich";
+ public static readonly CUSTOM_SY_TABLE_HEADER_ROW: string = "custom-sy-table-header-row";
+ public static readonly CUSTOM_SY_TABLE_HEADER_COLUMN: string = "custom-sy-table-header-column";
+ public static readonly CUSTOM_SY_AV_STATIC_TEXT: string = "custom-sy-av-s-text-";
// 临时标记 DOM 属性以辅助完成其功能
public static readonly ATTRIBUTE_EDITING = "data-editing";
diff --git a/app/src/protyle/hint/extend.ts b/app/src/protyle/hint/extend.ts
index 9ec13a1039..5f674fad4a 100644
--- a/app/src/protyle/hint/extend.ts
+++ b/app/src/protyle/hint/extend.ts
@@ -648,7 +648,7 @@ export const hintRef = (key: string, protyle: IProtyle, source: THintSource): IH
} else if (source === "av") {
let refText = name;
if (nodeElement) {
- refText = escapeHtml(item.ial["custom-sy-av-s-text-" + nodeElement.getAttribute("data-av-id")] || "") || refText;
+ refText = escapeHtml(item.ial[Constants.CUSTOM_SY_AV_STATIC_TEXT + nodeElement.getAttribute("data-av-id")] || "") || refText;
}
value = `<span data-type="block-ref" data-id="${item.id}" data-subtype="s">${refText}</span>`;
}
diff --git a/app/src/protyle/hint/index.ts b/app/src/protyle/hint/index.ts
index 3990917f42..009f48f94e 100644
--- a/app/src/protyle/hint/index.ts
+++ b/app/src/protyle/hint/index.ts
@@ -709,7 +709,7 @@ export class Hint {
// av 搜索时需要获取值 https://github.com/siyuan-note/siyuan/issues/12020
let refText = item.name ? stripSearchMark(escapeSearchHighlight(item.name)) : item.refText.replace(new RegExp(Constants.ZWSP, "g"), "");
if (nodeElement) {
- refText = escapeHtml(item.ial["custom-sy-av-s-text-" + nodeElement.getAttribute("data-av-id")] || "") || refText;
+ refText = escapeHtml(item.ial[Constants.CUSTOM_SY_AV_STATIC_TEXT + nodeElement.getAttribute("data-av-id")] || "") || refText;
}
blockRefHTML = `<span data-type="block-ref" data-id="${item.id}" data-subtype="s">${refText}</span>`;
} else {
diff --git a/app/src/protyle/util/clear.ts b/app/src/protyle/util/clear.ts
index 29f7dda163..b48de9eb3a 100644
--- a/app/src/protyle/util/clear.ts
+++ b/app/src/protyle/util/clear.ts
@@ -50,7 +50,7 @@ export const clearBlockElement = (element: Element, keepRefcount = false) => {
element.querySelector(".protyle-attr--av")?.remove();
element.removeAttribute("custom-avs");
element.getAttributeNames().forEach(attr => {
- if (attr.startsWith("custom-sy-av-s-text-")) {
+ if (attr.startsWith(Constants.CUSTOM_SY_AV_STATIC_TEXT)) {
element.removeAttribute(attr);
}
});
diff --git a/app/src/protyle/util/headingNumber.test.ts b/app/src/protyle/util/headingNumber.test.ts
index 027d25a203..6528064528 100644
--- a/app/src/protyle/util/headingNumber.test.ts
+++ b/app/src/protyle/util/headingNumber.test.ts
@@ -1,6 +1,8 @@
import {describe, it} from "node:test";
import * as assert from "node:assert/strict";
-import {
+Object.assign(globalThis, {SIYUAN_VERSION: "test", NODE_ENV: "test"});
+
+const {
buildHeadingNumberStyles,
headingNumberNeedsLeadingTrim,
headingNumberNeedsSpacing,
@@ -10,7 +12,7 @@ import {
renderHeadingNumberElements,
resolveHeadingNumberEnabled,
transactionsMayChangeRootHeadingNumberSetting
-} from "./headingNumberCore";
+} = require("./headingNumberCore") as typeof import("./headingNumberCore");
class TestElement {
private attributes = new Map<string, string>();
diff --git a/app/src/protyle/util/headingNumberCore.ts b/app/src/protyle/util/headingNumberCore.ts
index b69b5628b4..24f9f10350 100644
--- a/app/src/protyle/util/headingNumberCore.ts
+++ b/app/src/protyle/util/headingNumberCore.ts
@@ -1,3 +1,5 @@
+import {Constants} from "../../constants";
+
const HEADING_SELECTOR = '[data-node-id][data-type="NodeHeading"]';
const HEADING_NUMBER_CLASS = "protyle-heading-number";
const HEADING_NUMBER_ACTIVE_CLASS = "protyle-heading-number--active";
@@ -9,7 +11,6 @@ const HEADING_NUMBER_TRIM_START_PREFIXES = ["("];
const NUMBERED_HEADING_SELECTOR = `${HEADING_SELECTOR}[data-heading-number], ` +
`${HEADING_SELECTOR} > [contenteditable][data-heading-number]`;
const HEADING_CONTAINER_TYPES = new Set(["NodeDocument", "NodeList", "NodeListItem", "NodeSuperBlock"]);
-const CUSTOM_HEADING_NUMBER_ATTRIBUTE = "custom-sy-heading-number";
let headingNumberMeasurements = new WeakMap<Element, {key: string, offset: string}>();
export interface IHeadingNumberStyle {
@@ -238,8 +239,8 @@ const operationChangesHeadingNumberSetting = (operation: IOperation) => {
if (operation.action !== "updateAttrs" || !operation.data || typeof operation.data !== "object") {
return false;
}
- const oldValue = operation.data.old?.[CUSTOM_HEADING_NUMBER_ATTRIBUTE];
- const newValue = operation.data.new?.[CUSTOM_HEADING_NUMBER_ATTRIBUTE];
+ const oldValue = operation.data.old?.[Constants.CUSTOM_SY_HEADING_NUMBER];
+ const newValue = operation.data.new?.[Constants.CUSTOM_SY_HEADING_NUMBER];
return oldValue !== newValue;
};
diff --git a/app/src/protyle/util/onGet.ts b/app/src/protyle/util/onGet.ts
index effe9bf264..fbd7682f1c 100644
--- a/app/src/protyle/util/onGet.ts
+++ b/app/src/protyle/util/onGet.ts
@@ -438,7 +438,7 @@ const setHTML = (options: {
protyle.breadcrumb.element.nextElementSibling.textContent = "";
}
if (protyle.element.hasAttribute("disabled-forever")) {
- if (protyle.wysiwyg.element.getAttribute("custom-sy-readonly") !== "true") {
+ if (protyle.wysiwyg.element.getAttribute(Constants.CUSTOM_SY_READONLY) !== "true") {
protyle.disabled = false;
}
protyle.element.removeAttribute("disabled-forever");
diff --git a/app/src/protyle/util/table.ts b/app/src/protyle/util/table.ts
index bca136c793..90d6314abe 100644
--- a/app/src/protyle/util/table.ts
+++ b/app/src/protyle/util/table.ts
@@ -1,4 +1,5 @@
import {escapeHtmlTextAndAttr} from "../../util/escape";
+import {Constants} from "../../constants";
import {openInputDialog} from "../../dialog/inputDialog";
import {updateTransaction} from "../wysiwyg/transaction";
import {
@@ -53,12 +54,12 @@ export const getOrCreateTableBody = (tableElement: HTMLTableElement) => {
};
export const isTableHeaderEnabled = (nodeElement: Element, type: "row" | "column") => {
- return type === "row" ? nodeElement.getAttribute("custom-sy-table-header-row") !== "false" :
- nodeElement.getAttribute("custom-sy-table-header-column") === "true";
+ return type === "row" ? nodeElement.getAttribute(Constants.CUSTOM_SY_TABLE_HEADER_ROW) !== "false" :
+ nodeElement.getAttribute(Constants.CUSTOM_SY_TABLE_HEADER_COLUMN) === "true";
};
const setTableHeaderEnabled = (nodeElement: Element, type: "row" | "column", enabled: boolean) => {
- const attribute = `custom-sy-table-header-${type}`;
+ const attribute = type === "row" ? Constants.CUSTOM_SY_TABLE_HEADER_ROW : Constants.CUSTOM_SY_TABLE_HEADER_COLUMN;
if (type === "row") {
if (enabled) {
nodeElement.removeAttribute(attribute);
@@ -74,7 +75,7 @@ const setTableHeaderEnabled = (nodeElement: Element, type: "row" | "column", ena
export const toggleTableHeader = (protyle: IProtyle, nodeElement: Element, type: "row" | "column") => {
const html = nodeElement.outerHTML;
- const attribute = `custom-sy-table-header-${type}`;
+ const attribute = type === "row" ? Constants.CUSTOM_SY_TABLE_HEADER_ROW : Constants.CUSTOM_SY_TABLE_HEADER_COLUMN;
if (isTableHeaderEnabled(nodeElement, type)) {
if (type === "row") {
nodeElement.setAttribute(attribute, "false");
diff --git a/app/src/protyle/util/tableCellRich.ts b/app/src/protyle/util/tableCellRich.ts
index 2348c69ad1..f2583836ae 100644
--- a/app/src/protyle/util/tableCellRich.ts
+++ b/app/src/protyle/util/tableCellRich.ts
@@ -1,5 +1,6 @@
import {getAVRichTextBlockDOM, getAVRichTextLute, sanitizeAVRichTextBlockDOM, serializeAVRichTextBlockDOM} from "../render/av/richText";
-import {decodeTableCellRich, encodeTableCellRich, TABLE_CELL_RICH_ATTRIBUTE, TABLE_RICH_ATTRIBUTE} from "./tableCellRichValue";
+import {decodeTableCellRich, encodeTableCellRich, TABLE_CELL_RICH_ATTRIBUTE} from "./tableCellRichValue";
+import {Constants} from "../../constants";
import {restoreInlineElementBoundaries} from "./inlineElementBoundary";
import {getTextWithoutSemanticMarkers} from "./inlineElementMarker";
import {getTableVirtualizationHTML, TABLE_VIRTUAL_ID} from "./tableVirtualizationDOM";
@@ -138,7 +139,7 @@ export const updateTableCellEditingValue = (cell: Element, value: {blockDOM: str
if (cell.hasAttribute(TABLE_CELL_RICH_ATTRIBUTE) || inline === null) {
cell.removeAttribute(TABLE_CELL_INLINE_ATTRIBUTE);
cell.setAttribute(TABLE_CELL_RICH_ATTRIBUTE, encodeTableCellRich(value.markdown));
- cell.closest('[data-type="NodeTable"]')?.setAttribute(TABLE_RICH_ATTRIBUTE, "1");
+ cell.closest('[data-type="NodeTable"]')?.setAttribute(Constants.CUSTOM_SY_TABLE_RICH, "1");
} else {
cell.setAttribute(TABLE_CELL_INLINE_ATTRIBUTE, inline);
}
@@ -187,7 +188,7 @@ export const renderTableCellRich = (cell: Element) => {
`<table><thead><tr><th ${TABLE_CELL_RICH_ATTRIBUTE}="${encoded}"></th></tr></thead></table></div></div>`);
cell.innerHTML = template.content.querySelector("th").innerHTML;
cell.setAttribute("contenteditable", "false");
- cell.closest('[data-type="NodeTable"]')?.setAttribute(TABLE_RICH_ATTRIBUTE, "1");
+ cell.closest('[data-type="NodeTable"]')?.setAttribute(Constants.CUSTOM_SY_TABLE_RICH, "1");
};
export const setTableCellRich = (cell: Element, content: string) => {
@@ -259,18 +260,18 @@ export const getTableBlockHTML = (table: Element) => {
};
export const retainTableCellRichMetadata = (html: string, changedHTML: string) => {
- if (!changedHTML.includes(TABLE_RICH_ATTRIBUTE)) {
+ if (!changedHTML.includes(Constants.CUSTOM_SY_TABLE_RICH)) {
return html;
}
const changed = document.createElement("template");
changed.innerHTML = changedHTML;
const original = document.createElement("template");
original.innerHTML = html;
- changed.content.querySelectorAll(`[data-type="NodeTable"][${TABLE_RICH_ATTRIBUTE}="1"]`).forEach(table => {
+ changed.content.querySelectorAll(`[data-type="NodeTable"][${Constants.CUSTOM_SY_TABLE_RICH}="1"]`).forEach(table => {
const id = table.getAttribute("data-node-id");
original.content.querySelectorAll('[data-type="NodeTable"]').forEach(previous => {
if (previous.getAttribute("data-node-id") === id) {
- previous.setAttribute(TABLE_RICH_ATTRIBUTE, "1");
+ previous.setAttribute(Constants.CUSTOM_SY_TABLE_RICH, "1");
}
});
});
diff --git a/app/src/protyle/util/tableCellRichValue.ts b/app/src/protyle/util/tableCellRichValue.ts
index 28c8519e75..dc70b60288 100644
--- a/app/src/protyle/util/tableCellRichValue.ts
+++ b/app/src/protyle/util/tableCellRichValue.ts
@@ -1,5 +1,4 @@
export const TABLE_CELL_RICH_ATTRIBUTE = "data-sy-table-cell-rich";
-export const TABLE_RICH_ATTRIBUTE = "custom-sy-table-rich";
export interface TableCellRich {
spec: 1;
diff --git a/app/src/protyle/util/transactionContract.test.ts b/app/src/protyle/util/transactionContract.test.ts
index 2541a011da..fd570f26d3 100644
--- a/app/src/protyle/util/transactionContract.test.ts
+++ b/app/src/protyle/util/transactionContract.test.ts
@@ -2,7 +2,9 @@ import {strict as assert} from "node:assert";
import test from "node:test";
import type {Transaction} from "../../types/api";
import {getEditorTransaction} from "./transactionContract";
-import {operationsMayChangeHeadingNumbers, operationsMayChangeOutline} from "./headingNumberCore";
+Object.assign(globalThis, {SIYUAN_VERSION: "test", NODE_ENV: "test"});
+
+const {operationsMayChangeHeadingNumbers, operationsMayChangeOutline} = require("./headingNumberCore") as typeof import("./headingNumberCore");
test("block reference swaps retain affected roots and invalidate the outline", () => {
const response: Transaction = JSON.parse(`{"doOperations":[{
diff --git a/app/src/protyle/wysiwyg/transaction.ts b/app/src/protyle/wysiwyg/transaction.ts
index e59adb986d..bef6c5fdf7 100644
--- a/app/src/protyle/wysiwyg/transaction.ts
+++ b/app/src/protyle/wysiwyg/transaction.ts
@@ -1443,7 +1443,7 @@ export const onTransaction = (protyle: IProtyle, operations: IOperation[], isUnd
item.querySelector(".protyle-attr--av")?.remove();
item.removeAttribute("custom-avs");
item.getAttributeNames().forEach(attr => {
- if (attr.startsWith("custom-sy-av-s-text-")) {
+ if (attr.startsWith(Constants.CUSTOM_SY_AV_STATIC_TEXT)) {
item.removeAttribute(attr);
}
});
diff --git a/kernel/av/value.go b/kernel/av/value.go
index 673662e53f..6c08ca4718 100644
--- a/kernel/av/value.go
+++ b/kernel/av/value.go
@@ -40,6 +40,8 @@ import (
"golang.org/x/text/message"
)
+const codeTabSpacesAttr = "custom-sy-code-tab-spaces"
+
type Value struct {
ID string `json:"id,omitempty"`
KeyID string `json:"keyID,omitempty"` // 字段 ID
@@ -1345,7 +1347,7 @@ func isAllowedValueTextRichBlockIAL(node *ast.Node, codeSettings bool) bool {
("true" != attr[1] && "false" != attr[1]) || node.Previous.IALAttr(attr[0]) != attr[1] {
return false
}
- case "custom-sy-code-tab-spaces":
+ case codeTabSpacesAttr:
if !codeSettings || nil == node.Previous || ast.NodeCodeBlock != node.Previous.Type ||
node.Previous.IALAttr(attr[0]) != attr[1] {
return false
@@ -1442,7 +1444,7 @@ func valueTextRichBlockDOM2Kramdown(luteEngine *lute.Lute, blockDOM string) stri
}
if ast.NodeParagraph == node.Type && !singleEmptyParagraph && "" == strings.TrimSpace(strings.ReplaceAll(node.Content(), "\u200b", "")) ||
ast.NodeCodeBlock == node.Type && ("" != node.IALAttr("linewrap") || "" != node.IALAttr("ligatures") ||
- "" != node.IALAttr("linenumber") || "" != node.IALAttr("custom-sy-code-tab-spaces")) {
+ "" != node.IALAttr("linenumber") || "" != node.IALAttr(codeTabSpacesAttr)) {
preserveBlockIDs = true
return ast.WalkStop
}
diff --git a/kernel/model/block.go b/kernel/model/block.go
index 1e8b81f09d..0a6fd6d2da 100644
--- a/kernel/model/block.go
+++ b/kernel/model/block.go
@@ -868,7 +868,7 @@ func swapBlockRefNodes(refNode, defNode *ast.Node, defID string, includeChildren
if includeChildren {
headingMode = "0"
}
- embed.SetIALAttr("custom-heading-mode", headingMode)
+ embed.SetIALAttr(embedHeadingModeAttr, headingMode)
}
embed.AppendChild(&ast.Node{Type: ast.NodeBlockQueryEmbedScript, Tokens: []byte("select * from blocks where id='" + defID + "'")})
originalRefNode.InsertBefore(embed)
@@ -1578,7 +1578,7 @@ func compareBlockKramdownIALAttrNames(a, b string) int {
}
func isSystemManagedBlockKramdownIALAttr(name string) bool {
- return "custom-avs" == name || "custom-heading-mode" == name || embedHeadingLevelAttr == name || "custom-reminder-wechat" == name ||
+ return av.NodeAttrNameAvs == name || embedHeadingModeAttr == name || embedHeadingLevelAttr == name || reminderWechatAttr == name ||
strings.HasPrefix(name, "custom-riff-") || strings.HasPrefix(name, "custom-sy-")
}
diff --git a/kernel/model/blockial.go b/kernel/model/blockial.go
index f54e24174d..7765c56067 100644
--- a/kernel/model/blockial.go
+++ b/kernel/model/blockial.go
@@ -112,7 +112,7 @@ func SetBlockReminder(id, timed string) (err error) {
return
}
- attrName := "custom-reminder-wechat"
+ attrName := reminderWechatAttr
if "0" == timed {
delete(attrs, attrName)
old := node.IALAttr(attrName)
diff --git a/kernel/model/custom_attributes.go b/kernel/model/custom_attributes.go
new file mode 100644
index 0000000000..e9ba66bf2b
--- /dev/null
+++ b/kernel/model/custom_attributes.go
@@ -0,0 +1,6 @@
+package model
+
+const (
+ readonlyAttr = "custom-sy-readonly"
+ reminderWechatAttr = "custom-reminder-wechat"
+)
diff --git a/kernel/model/document_stat.go b/kernel/model/document_stat.go
index 72c4ad303b..45a3316b3a 100644
--- a/kernel/model/document_stat.go
+++ b/kernel/model/document_stat.go
@@ -306,7 +306,7 @@ func documentStatHeadingMode(embed *ast.Node) (ret int) {
if nil == embed {
return
}
- if customMode := embed.IALAttr("custom-heading-mode"); "" != customMode {
+ if customMode := embed.IALAttr(embedHeadingModeAttr); "" != customMode {
if mode, err := strconv.Atoi(customMode); nil == err && 0 <= mode && mode <= 2 {
ret = mode
}
diff --git a/kernel/model/embed_heading.go b/kernel/model/embed_heading.go
index f5acc9d065..45eb768cdb 100644
--- a/kernel/model/embed_heading.go
+++ b/kernel/model/embed_heading.go
@@ -23,7 +23,10 @@ import (
"github.com/siyuan-note/siyuan/kernel/treenode"
)
-const embedHeadingLevelAttr = "custom-heading-level"
+const (
+ embedHeadingLevelAttr = "custom-heading-level"
+ embedHeadingModeAttr = "custom-heading-mode"
+)
func explicitEmbedHeadingLevel(embed *ast.Node, targetID string) int {
if targetID == "" || treenode.GetEmbedBlockRef(embed) != targetID {
diff --git a/kernel/model/export_js_embed.go b/kernel/model/export_js_embed.go
index cbeb79ae10..27c3fd1b8b 100644
--- a/kernel/model/export_js_embed.go
+++ b/kernel/model/export_js_embed.go
@@ -32,7 +32,7 @@ func preserveExportJSEmbeds(tree *parse.Tree) {
`" data-content="` + html.EscapeString(html.EscapeString(content)) + `" data-notebook="` + html.EscapeString(tree.Box) +
`" data-root-id="` + html.EscapeString(tree.ID) +
`" data-query-notebook="` + html.EscapeString(queryNotebook) +
- `" custom-heading-mode="` + html.EscapeString(node.IALAttr("custom-heading-mode")) + `"></div>`
+ `" ` + embedHeadingModeAttr + `="` + html.EscapeString(node.IALAttr(embedHeadingModeAttr)) + `"></div>`
replacement := &ast.Node{Type: ast.NodeHTMLBlock, ID: node.ID, Tokens: []byte(placeholder), KramdownIAL: node.KramdownIAL}
replacement.SetIALAttr("data-export-js-embed", "true")
originals = append(originals, node)
diff --git a/kernel/model/list_mindmap_migration.go b/kernel/model/list_mindmap_migration.go
index 8e89fdf2ea..8358f7c23d 100644
--- a/kernel/model/list_mindmap_migration.go
+++ b/kernel/model/list_mindmap_migration.go
@@ -141,7 +141,7 @@ func MigrateLegacyMindmaps(id string) (tx *Transaction, visible map[string]strin
if err != nil {
return nil, nil, err
}
- if tree.ID != id || tree.Root.IALAttr("custom-sy-readonly") == "true" {
+ if tree.ID != id || tree.Root.IALAttr(readonlyAttr) == "true" {
return nil, nil, errors.New("mind map migration requires an editable document")
}
engine := util.NewLute()
@@ -150,7 +150,7 @@ func MigrateLegacyMindmaps(id string) (tx *Transaction, visible map[string]strin
if !entering {
return ast.WalkContinue
}
- if n.IALAttr("custom-sy-readonly") == "true" {
+ if n.IALAttr(readonlyAttr) == "true" {
return ast.WalkSkipChildren
}
if isLegacyMindmap(n) && n.IALAttr(legacyMindmapCodeAttr) != "1" {
diff --git a/kernel/model/render.go b/kernel/model/render.go
index 35150ed22e..644eb678f7 100644
--- a/kernel/model/render.go
+++ b/kernel/model/render.go
@@ -396,7 +396,7 @@ func resolveEmbedR(n *ast.Node, blockEmbedMode int, luteEngine *lute.Lute, resol
// 从嵌入块的 IAL 属性中解析 custom-heading-mode,使用全局配置作为默认值
blockHeadingMode := Conf.Editor.HeadingEmbedMode
- if customHeadingMode := n.IALAttr("custom-heading-mode"); "" != customHeadingMode {
+ if customHeadingMode := n.IALAttr(embedHeadingModeAttr); "" != customHeadingMode {
if mode, err := strconv.Atoi(customHeadingMode); nil == err && (mode == 0 || mode == 1 || mode == 2) {
blockHeadingMode = mode
}
diff --git a/kernel/model/transaction_list_conversion.go b/kernel/model/transaction_list_conversion.go
index d6b90237ba..664970ba42 100644
--- a/kernel/model/transaction_list_conversion.go
+++ b/kernel/model/transaction_list_conversion.go
@@ -83,7 +83,7 @@ func (tx *Transaction) doConvertList(op *Operation) *TxErr {
return fail(errors.New("invalid list conversion block"))
}
for parent := node; parent != nil; parent = parent.Parent {
- if parent.IALAttr("custom-sy-readonly") == "true" || parent.Type == ast.NodeMindmapItem {
+ if parent.IALAttr(readonlyAttr) == "true" || parent.Type == ast.NodeMindmapItem {
return fail(errors.New("list conversion requires editable blocks"))
}
}
@@ -218,7 +218,7 @@ func convertListNodes(selected []*ast.Node, options apicontract.TransactionListC
}
readonly := false
ast.Walk(item, func(n *ast.Node, entering bool) ast.WalkStatus {
- if entering && n.IALAttr("custom-sy-readonly") == "true" {
+ if entering && n.IALAttr(readonlyAttr) == "true" {
readonly = true
}
return ast.WalkContinue
diff --git a/kernel/sql/block_ref_query.go b/kernel/sql/block_ref_query.go
index 14ed784801..790c8604db 100644
--- a/kernel/sql/block_ref_query.go
+++ b/kernel/sql/block_ref_query.go
@@ -26,6 +26,7 @@ import (
"github.com/88250/lute/parse"
"github.com/emirpasic/gods/sets/hashset"
"github.com/siyuan-note/logging"
+ "github.com/siyuan-note/siyuan/kernel/av"
"github.com/siyuan-note/siyuan/kernel/search"
)
@@ -228,7 +229,8 @@ func QueryBoundBlockAVIDsInBox(blockIDs, rootIDs []string, boxID string) (ret ma
for _, id := range batch {
args = append(args, id)
}
- rows, queryErr := queryForBox(boxID, "SELECT id, ial FROM blocks WHERE "+column+" IN ("+placeholders+") AND instr(ial, 'custom-avs=') > 0", args...)
+ args = append(args, av.NodeAttrNameAvs+"=")
+ rows, queryErr := queryForBox(boxID, "SELECT id, ial FROM blocks WHERE "+column+" IN ("+placeholders+") AND instr(ial, ?) > 0", args...)
if nil != queryErr {
return queryErr
}
@@ -244,7 +246,7 @@ func QueryBoundBlockAVIDsInBox(blockIDs, rootIDs []string, boxID string) (ret ma
ialContent = strings.TrimPrefix(ialContent, "{:")
ialContent = strings.TrimSuffix(ialContent, "}")
for _, kv := range parse.Tokens2IAL([]byte(ialContent)) {
- if 2 > len(kv) || "custom-avs" != kv[0] {
+ if 2 > len(kv) || av.NodeAttrNameAvs != kv[0] {
continue
}
for avID := range strings.SplitSeq(kv[1], ",") {