Skip to content

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

:bug: Preserve empty tab titles during mind map conversion https://github.com/siyuan-note/siyuan/issues/20585

Danielf3517d703c04
diff --git a/app/src/protyle/render/listMindmap/model.test.ts b/app/src/protyle/render/listMindmap/model.test.ts
index c7fda15c88..6098047415 100644
--- a/app/src/protyle/render/listMindmap/model.test.ts
+++ b/app/src/protyle/render/listMindmap/model.test.ts
@@ -816,6 +816,26 @@ const browserCases = async (sourceCode: string, css: string, taskSource: string,
directMindmap.textContent.includes("Beta"));
check.equal(lute.BlockDOM2Md(directMindmap.outerHTML).includes("Nested"), true);
check.equal(convertedTabs.outerHTML, tabsBefore, "direct conversion preserves the undo source");
+ // 空标题与首段正文分别保留,持久化后的往返转换也不能将正文提升为标题。
+ for (const title of ["", "**Title**"]) {
+ for (const conversion of ["Tabs2Mindmap", "Tabs2UL", "Tabs2OL", "Tabs2TL"] as const) {
+ const original = reset(`::: tabs\n@tab ${title}\n\nFirst paragraph\n\nSecond paragraph\n\n:::\n`);
+ const originalHTML = original.outerHTML;
+ const bodyIDs = ids(original);
+ const converted = api.convertTabsList(original, conversion, lute);
+ const persisted = document.createElement("div");
+ persisted.innerHTML = lute.SpinBlockDOM(converted.outerHTML);
+ const restored = api.convertTabsList(api.listMindmapConversionSource(persisted.firstElementChild), "List2Tabs", lute);
+ const titleBlock = restored.querySelector('.tab-item-info > [tabs-title="true"]');
+ check.equal(titleBlock.textContent.replace(/\u200b/g, ""), title ? "Title" : "", `${conversion} preserves the title`);
+ check.equal(!!titleBlock.querySelector('[data-type="strong"]'), !!title);
+ const body = restored.querySelector(".tab-item-content") as HTMLElement;
+ check.deepEqual(ids(body), bodyIDs.slice(1), `${conversion} preserves body block IDs`);
+ check.deepEqual(Array.from(body.querySelectorAll(':scope > [data-type="NodeParagraph"]'))
+ .map(block => block.textContent.replace(/\u200b/g, "")), ["First paragraph", "Second paragraph"]);
+ check.equal(original.outerHTML, originalHTML, "conversion preserves the undo source");
+ }
+ }
check.equal(typedList.outerHTML, typedBefore);
check.equal(cleaned.includes("Derived editor"), false);
check.equal(cleaned.includes("data-mindmap-view-rendered"), false);
diff --git a/app/src/protyle/wysiwyg/tabsList.ts b/app/src/protyle/wysiwyg/tabsList.ts
index c6b915c3ff..09e14ffdb4 100644
--- a/app/src/protyle/wysiwyg/tabsList.ts
+++ b/app/src/protyle/wysiwyg/tabsList.ts
@@ -140,7 +140,7 @@ export const convertTabsList = (source: Element, type: TTabsListConversion, lute
titleBlock.removeAttribute("tabs-title");
titleBlock.querySelector(".tab-item-title").classList.remove("tab-item-title", "callout-title");
blocks.unshift(titleBlock);
- } else if (title?.innerHTML) {
+ } else if (title) {
const titleBlock = newParagraph(lute);
titleBlock.querySelector("[contenteditable]").innerHTML = title.innerHTML;
titleBlock.querySelectorAll("wbr").forEach(caret => caret.remove());
diff --git a/docs/TAB-BLOCK.md b/docs/TAB-BLOCK.md
index d353689369..713902c53b 100644
--- a/docs/TAB-BLOCK.md
+++ b/docs/TAB-BLOCK.md
@@ -34,7 +34,7 @@ Right-clicking a task list icon opens the complete list item block menu. The blo
List-to-tabs conversion affects only the current level. Each direct list item's first paragraph becomes its title, retaining the complete text, inline formatting, references, links, ID and attributes without duplicating it in the body. If the first block is not a paragraph, the title is empty and that block stays in the body. Nested lists and tabs are not flattened. Conversion selects the first tab.
-Converting back places a separate title paragraph first, removes `tabs-title` and appends the body. A nonempty string title creates a new paragraph. Identical title and body text is not deduplicated. A list item containing only a title receives a body placeholder on conversion to tabs. By contrast, conversion back omits only a `tabs-placeholder` paragraph that is still empty and has no inline elements, user attributes or reference count.
+Converting back places a separate title paragraph first, removes `tabs-title` and appends the body. A string title creates a new paragraph, including an empty title, so converting back to tabs preserves the title and body separately. Identical title and body text is not deduplicated. A list item containing only a title receives a body placeholder on conversion to tabs. By contrast, conversion back omits only a `tabs-placeholder` paragraph that is still empty and has no inline elements, user attributes or reference count.
Task-list conversion preserves incomplete, complete and custom states. Converting to a task list restores the current `tabs-task`; items without that attribute become incomplete. Conversion to an ordinary list removes the task attribute. Ordered lists restart at 1. Layout and selection are not retained as backups for reverse conversion.