An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:memo: Update bilingual tab block documentation https://github.com/siyuan-note/siyuan/issues/17642
Danielf9104db75468
diff --git a/docs/SY-FORMAT.md b/docs/SY-FORMAT.mdindex c88cd50462..19dcef94fe 100644--- a/docs/SY-FORMAT.md+++ b/docs/SY-FORMAT.md@@ -344,7 +344,7 @@ Documents containing either node require at least `Spec: "3"`; documents using tThe internal Markdown syntax uses `::: tabs` to open a group and `@tab <inline title>` to start each item; `@tab:active <inline title>` identifies the selected item. The opening fence requires at least three colons and whitespace (spaces or tabs) before `tabs`; canonical output uses one space. Items have no closing marker; the group closes with a standalone fence containing the same number of colons as its opening fence. Outer fences must be longer than nested fences. Indentation is optional, and canonical output computes fence lengths from nesting depth without adding indentation to tab bodies. Old `:::tabs` and `:::tab` syntax is not recognized; existing `.sy` tab nodes retain the same structure.-An item's IAL appears immediately after its title marker, with no intervening blank line; a blank line separates that metadata from its body. The group's IAL follows its closing fence, and body-block IALs follow their respective blocks. On import, the first valid `@tab:active` marker sets `tabs-active-id`, taking precedence over the group's IAL. Without an active marker, a valid `tabs-active-id` is preserved; a missing or invalid value falls back to the first item. Each nested group has its own selection. Code-block markers are literal; use `\@tab` or `\@tab:active` for literal markers at the start of a body line. Standard Markdown exports title paragraphs followed by every item's body; HTML can enhance the full content into interactive tabs, while print, PDF and Word show all items. See [Tabs design](TABS.md) for the full contract.+An item's IAL appears immediately after its title marker, with no intervening blank line; a blank line separates that metadata from its body. The group's IAL follows its closing fence, and body-block IALs follow their respective blocks. On import, the first valid `@tab:active` marker sets `tabs-active-id`, taking precedence over the group's IAL. Without an active marker, a valid `tabs-active-id` is preserved; a missing or invalid value falls back to the first item. Each nested group has its own selection. Code-block markers are literal; use `\@tab` or `\@tab:active` for literal markers at the start of a body line. Standard Markdown exports title paragraphs followed by every item's body; HTML can enhance the full content into interactive tabs, while print, PDF and Word show all items. See [Tab Block](TAB-BLOCK.md) for the full contract.### 5.10 Code block (four-part structure; fenced only)diff --git a/docs/SY-FORMAT.zh-CN.md b/docs/SY-FORMAT.zh-CN.mdindex 5f16c98779..316dcbef55 100644--- a/docs/SY-FORMAT.zh-CN.md+++ b/docs/SY-FORMAT.zh-CN.md@@ -342,7 +342,7 @@ NodeList NodeList内部 Markdown 使用 `::: tabs` 开始一组页签,`@tab <行级标题>` 开始一个页签项,`@tab:active <行级标题>` 标识选中项。开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。页签项没有单独的结束标记;整组以独占一行、与开始围栏冒号数量相同的结束围栏闭合。外层围栏必须比内层长,缩进可选;规范输出根据嵌套深度计算围栏长度,不额外缩进页签正文。旧的 `:::tabs`、`:::tab` 语法不再识别,既有 `.sy` 页签节点结构保持不变。-页签项的 IAL 紧接标题标记下一行,中间不留空行,之后以空行分隔正文。整组容器的 IAL 位于结束围栏之后,正文块的 IAL 紧随对应正文块。导入时,第一个有效的 `@tab:active` 标记决定 `tabs-active-id`,优先于组 IAL 中的值;没有选中标记时保留有效的 `tabs-active-id`,缺失或失效时回退到第一页。嵌套各组独立保存选择。代码块中的标记按字面保留;正文行首的字面标记使用 `\@tab` 或 `\@tab:active` 转义。标准 Markdown 导出所有页签的标题段落及正文;HTML 可增强为交互页签,打印、PDF 和 Word 展示全部页签。完整约定参见[页签设计](TABS.md)。+页签项的 IAL 紧接标题标记下一行,中间不留空行,之后以空行分隔正文。整组容器的 IAL 位于结束围栏之后,正文块的 IAL 紧随对应正文块。导入时,第一个有效的 `@tab:active` 标记决定 `tabs-active-id`,优先于组 IAL 中的值;没有选中标记时保留有效的 `tabs-active-id`,缺失或失效时回退到第一页。嵌套各组独立保存选择。代码块中的标记按字面保留;正文行首的字面标记使用 `\@tab` 或 `\@tab:active` 转义。标准 Markdown 导出所有页签的标题段落及正文;HTML 可增强为交互页签,打印、PDF 和 Word 展示全部页签。完整约定参见[页签块](TAB-BLOCK.zh-CN.md)。### 5.10 代码块(四段结构,仅围栏式)diff --git a/docs/TAB-BLOCK.md b/docs/TAB-BLOCK.mdnew file mode 100644index 0000000000..fccd069ffd--- /dev/null+++ b/docs/TAB-BLOCK.md@@ -0,0 +1,148 @@+# Tab Block++[中文](TAB-BLOCK.zh-CN.md)++A tab block groups content in a single container and switches between groups through top or left navigation. Each tab item is a container with its own block ID and can contain ordinary blocks and nested tab blocks.++Related issue: https://github.com/siyuan-note/siyuan/issues/17642++## Data model++| Node or attribute | Meaning |+| --- | --- |+| `NodeTabs` | Tab container whose direct content blocks are `NodeTabItem` nodes |+| `NodeTabItem` | An item containing a title and body; documents, bare list items and bare tab items are not valid direct children |+| `TabItemTitle` | Inline Markdown title using the same inline representation as callout titles |+| `tabs-title="true"` | Marks the item's first `NodeParagraph` as a separate title block; when present, this paragraph is the sole title source and overrides `TabItemTitle` |+| `tabs-active-id` | Selected direct item ID in the container IAL; missing or invalid values fall back to the first item |+| `tabs-position` | Container IAL layout attribute: `top` or `left`, defaulting to `top` |+| `tabs-task` | Optional task-state character in the item IAL; absence means an ordinary tab |+| `tabs-placeholder="true"` | Marks an empty body paragraph added during list-to-tabs conversion |++Child order determines tab order. Empty and duplicate titles are valid, and UI placeholder text is not saved as content. A separate title paragraph retains its ID, block attributes and complete inline content.++Canonical data contains at least one item and at least one body block per item, using an empty paragraph when needed. The kernel's `NormalizeTabs` fills empty containers and bodies and repairs selection and invalid layout attributes. When the frontend deletes or moves away the last item, it converts the original container into an empty paragraph while retaining the container ID.++Moving preserves IDs. When copying, inserting templates, importing or restoring regenerates IDs, it also remaps `tabs-active-id` and internal block references and block links in titles; external references retain their targets. A standalone item is a valid editing fragment and receives a tab container when pasted into ordinary content. Internal Markdown round trips temporarily wrap such fragments and restore their original fragment identity afterward.++## Markdown syntax++```markdown+::: tabs+@tab **Windows**++Instructions for Windows.++@tab:active Linux++Instructions for Linux.+:::+```++Opening fences contain at least three colons followed by spaces or tabs before `tabs`; canonical output uses one space. `@tab` or `@tab:active` starts a direct item. A nonempty inline title is separated from the marker by spaces or tabs. Items have no closing marker; the group closes with a standalone colon fence matching its opening length.++The first valid `@tab:active` in a group selects an item and takes precedence over `tabs-active-id` in the group IAL. Without that marker, a valid attribute is retained; otherwise the first item is selected. Internal Markdown emits the selected item as `@tab:active`. Nested groups are handled independently.++Tabs can nest inside lists, blockquotes, super blocks and other tab items. An outer fence must be longer than the fences it contains. Indentation is optional. Canonical output computes fence lengths from nesting depth without adding body indentation: three colons for a single level, four outside and three inside for two levels. The syntax has no fixed nesting-depth limit.++```markdown+:::: tabs+@tab First outer tab++::: tabs+@tab First inner tab++Inner content.+:::++@tab Second outer tab++Outer content.+::::+```++Markers inside code blocks remain literal. Escape literal item markers at the start of body lines as `\@tab` or `\@tab:active`. An isolated `@tab` outside a group is ordinary text. Content before the first marker becomes an item with an empty title. Incomplete input closes within the parser's scope, and canonical output supplies closing fences. Old `:::tabs` and `:::tab` forms are not tab syntax; existing `.sy` tab node structures are unaffected.++Item IAL goes immediately after the title marker with no intervening blank line, followed by a blank line before the body. Group IAL follows the closing fence, and body-block IAL follows its corresponding block. Task state also uses item IAL:++```markdown+::: tabs+@tab:active Example task+{: id="20260905120000-item001" tabs-task="/"}++Body.+{: id="20260905120000-para001"}+:::+{: id="20260905120000-tabs001" tabs-active-id="20260905120000-item001" tabs-position="left"}+```++Internal Markdown emits a separate title paragraph as the first paragraph, retaining `tabs-title="true"`, its ID and attributes. The `@tab` line then omits duplicate title text. Structured clipboard Markdown instead puts the complete title on the `@tab` line and omits the duplicate title paragraph.++## Menus and editing++The block icon operates on the whole container. Block icon menu - Tabbed container contains the top and left layout choices, followed by a separator and Task. All three options display their selection indicators on the right. These entries and the separator are registered in the configurable menu catalog for visibility and ordering.++A title's context menu operates on that item. It offers copying a block reference and, when editable, renaming, duplication and deletion. Task items also offer Custom task status. The header has no separate More button. Whole-container conversion is available through block icon menu - Turn into, including unordered lists, ordered lists, task lists and super blocks.++Clicking a title selects its item. Double-clicking or choosing Rename edits rich text directly at the title location, reusing callout-title inline formatting, selection and IME handling. The navigation copy is display-only; saving and reverse parsing use the original title inside the item. Font colors and other inline styles remain title content; renaming does not first expose an encoded string for the user to edit. Finishing editing preserves navigation scroll position and hides the inline toolbar. A hidden title selection cannot open the toolbar at the top of the document.++A new tab block starts with two items, each containing an empty paragraph. Adding an item appends it, selects it and starts title editing. Navigation truncates long titles visually and shows a title tooltip on hover; stored text has no fixed character cutoff. Navigation and the add button cannot be selected as body text.++### Task state++A single ASCII space in `tabs-task` means incomplete. `X` or `x` displays the completed icon; other supported single-character states display their exact character. Custom-state input uses task-list marker validation, accepting a single ASCII character other than square brackets. State is independent of title and selection and is saved and synced with the document.++Task in the block menu is a group toggle. It is checked if any direct item has `tabs-task`. Turning it off removes the attribute from every direct item; turning it on initializes all items as incomplete. A new item is an incomplete task whenever the group contains any task item. Moving between groups retains each item's state, so mixed groups remain possible and can be normalized through the group toggle.++Clicking a state icon does not select the tab or start renaming: incomplete becomes `X`, while any other state becomes a space. Right-clicking the icon or choosing Custom task status in the title menu edits the current item's state. The icon has no separate Task List tooltip.++### List and super-block conversion++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. 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.++Converting to a super block turns the container and its items into vertical super blocks, converts titles into paragraphs and retains container, item and body IDs. List and super-block conversions use ordinary editing transactions and support undo.++## Selection, navigation and dragging++In editable editors, explicit selection and selection triggered by search or block-reference navigation save `tabs-active-id` through the attribute API after queued editing transactions. Selection does not occupy the body undo stack or update body modification timestamps, but is written to disk and synced. Read-only pages, embedded previews, history previews and exported HTML allow temporary switching without saving selection.++When restoring position after refresh or restart, persisted selection takes precedence over a stale caret in a hidden item. Focus moves to the selected body without reusing the stale text offset. Explicit navigation to hidden content activates each containing tab. An incoming selection that would hide content currently being edited is deferred to avoid interrupting focus and IME composition.++Items use ordinary block-reference syntax, such as `((20260905120000-item001 'Tab title'))`, without a dedicated reference syntax. The target is the item ID, and navigation selects that item. Reference hover previews include the parent container for rendering. References and resources in string titles belong to the item; those in separate title paragraphs belong to the original paragraph ID.++Dragging a navigation title moves the entire item; dragging a body block moves content. Sorting previews move adjacent buttons out of the drop position, fade the dragged button and scroll near navigation edges, using the appropriate axis for each layout. Dropping commits one transaction; canceling or returning to the original position commits none. Cross-group moves update both groups in one transaction. Read-only targets and descendants of the dragged item reject drops.++Deleting the active item selects the next item if available, otherwise the previous one. Deleting the last item produces an empty paragraph. Ordinary text selection excludes hidden bodies; whole-container copying and deletion include every item. Backspace and Delete at body boundaries do not automatically merge adjacent items.++## Rendering and layout++`NodeTabs` renders as `.tabs` with direct `.tab-item` children. Navigation lives in `.tabs-header.protyle-action` and has no content block ID. The original title is `.tab-item-title.callout-title` inside `.tab-item-info`; the body is `.tab-item-content`, without reusing the callout body class. During editing, `.tabs-title-editor` overlays the corresponding navigation button.++The container uses a theme border and rounded corners. Top navigation scrolls horizontally. Left navigation sizes to content, with an 80px minimum header width and a column limit of the smaller of 200px and 40% of container width. A 48px gap leaves room for body block controls. Containers narrower than 420px temporarily display top navigation without changing `tabs-position`.++Navigation provides `tablist`, `tab` and `tabpanel` semantics with independent DOM IDs for each rendering instance. Arrow keys, Home and End move navigation focus; Enter or Space activates an item. Title editing follows text-editing key handling. Hidden items continue receiving data updates, and becoming visible reprocesses size-dependent render nodes and databases.++## Indexing, export and format compatibility++Titles participate in full-text indexing, reference and resource scanning, dynamic anchor text and history differences. String titles use temporary inline trees; separate title paragraphs use ordinary paragraph processing without duplicate scanning. Block names take precedence over titles as reference anchor text. Headings inside tabs do not participate in document heading numbering, and folding does not cross item boundaries.++Internal Markdown retains full structure and attributes. Structured output with `TabsMarkdown` enabled preserves fences, complete inline titles, active markers and task-state IAL. Clipboard output omits complete block IAL such as block IDs. Flattened output with that option disabled emits every item's title and body in order. Ordinary text-selection copying removes navigation, hidden bodies and container wrappers.++HTML initially shows all content and hides inactive items only after interactive initialization succeeds. Printing, PDF and Word expand all items, including nested content.++Documents containing tab nodes use `Spec 3`; ordinary documents use `Spec 2`, and upgraded documents are not automatically downgraded. JSON readers reject unsupported future versions before parsing and repair. Import paths in old clients that bypass version checks do not have this protection and must not process new-format documents. Lute supplies the nodes and syntax, so both the generated frontend script and the kernel dependency must include that support. `kernel/go.mod` records the actual dependency version.++## Code entry points++| Area | Entry points |+| --- | --- |+| Rendering, selection and title-editor placement | [`tabsRender.ts`](../app/src/protyle/render/tabsRender.ts), [`_tabs.scss`](../app/src/assets/scss/protyle/_tabs.scss) |+| Item operations and task state | [`tabs.ts`](../app/src/protyle/wysiwyg/tabs.ts), [`taskListMarker.ts`](../app/src/protyle/wysiwyg/taskListMarker.ts) |+| List conversion and deletion repair | [`tabsList.ts`](../app/src/protyle/wysiwyg/tabsList.ts), [`tabsRemoval.ts`](../app/src/protyle/wysiwyg/tabsRemoval.ts) |+| Block menu and configuration catalog | [`gutter/index.ts`](../app/src/protyle/gutter/index.ts), [`catalog.ts`](../app/src/config/entryVisibility/catalog.ts) |+| Kernel normalization and title traversal | [`treenode/tabs.go`](../kernel/treenode/tabs.go), [`model/tabs.go`](../kernel/model/tabs.go) |+| JSON format | [`SY-FORMAT.md`](SY-FORMAT.md) |diff --git a/docs/TAB-BLOCK.zh-CN.md b/docs/TAB-BLOCK.zh-CN.mdnew file mode 100644index 0000000000..5ad11199b5--- /dev/null+++ b/docs/TAB-BLOCK.zh-CN.md@@ -0,0 +1,148 @@+# 页签块++[English](TAB-BLOCK.md)++页签块将多个内容分组放在同一容器内,通过顶部或左侧的标题导航切换显示。每个页签项都是具有独立块 ID 的容器,可包含普通块和嵌套页签块。++关联问题:https://github.com/siyuan-note/siyuan/issues/17642++## 数据模型++| 节点或属性 | 含义 |+| --- | --- |+| `NodeTabs` | 页签容器,直属内容块为 `NodeTabItem` |+| `NodeTabItem` | 页签项,包含标题和正文,不能直接容纳文档、裸列表项或裸页签项 |+| `TabItemTitle` | 行级 Markdown 字符串标题,行级内容表示沿用提示块 |+| `tabs-title="true"` | 标记页签项首个 `NodeParagraph` 为独立标题块;存在时以该段落为唯一标题来源,不再使用 `TabItemTitle` |+| `tabs-active-id` | 保存在容器 IAL 中的选中直属页签项 ID,缺失或失效时回退到第一页 |+| `tabs-position` | 保存在容器 IAL 中的布局,取值为 `top` 或 `left`,默认 `top` |+| `tabs-task` | 保存在页签项 IAL 中的任务状态字符,缺失表示普通页签 |+| `tabs-placeholder="true"` | 标记列表转页签时自动补出的空正文段落 |++页签顺序由子节点顺序决定。标题允许重复和清空,空标题的界面占位文字不写入内容。独立标题段落保留自身 ID、块属性和完整行级内容。++规范数据至少有一个页签项,每页至少有一个正文块,空正文使用空段落。内核的 `NormalizeTabs` 补齐空容器和空正文,并修复选中项及无效布局属性。前端删除或移走最后一页时,将原页签容器转换为空段落并保留容器 ID。++移动保留 ID。复制、模板插入、导入和恢复中重建 ID 时,同步映射 `tabs-active-id` 及标题中的内部块引用和块链接,外部引用保持原目标。独立页签项是合法编辑片段,粘贴到普通正文时补齐页签容器;片段经过内部 Markdown 转换时使用临时包装,并按片段身份恢复。++## Markdown 语法++```markdown+::: tabs+@tab **Windows**++Windows 下的说明。++@tab:active Linux++Linux 下的说明。+:::+```++开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符,规范输出使用一个空格。`@tab` 或 `@tab:active` 开始一个直属页签项,有标题时以空格或制表符分隔标记和行级标题。页签项没有独立结束标记,整组以独占一行、与开始围栏等长的冒号围栏闭合。++一组内第一个有效的 `@tab:active` 指定选中项,优先于组 IAL 中的 `tabs-active-id`。没有该标记时保留有效属性,否则回退到第一页。内部 Markdown 将选中项输出为 `@tab:active`,嵌套各组独立处理。++页签可嵌套在列表、引述块、超级块和其他页签项中。外层围栏必须比其包含的内层围栏长,缩进可选。规范输出根据嵌套深度计算围栏长度,不额外缩进正文;单层三个冒号,两层外四内三,语法没有固定的嵌套层数上限。++```markdown+:::: tabs+@tab 外层第一页++::: tabs+@tab 内层第一页++内层正文。+:::++@tab 外层第二页++外层正文。+::::+```++代码块中的标记按字面保留。正文行首的字面页签标记使用 `\@tab` 或 `\@tab:active` 转义。组外孤立的 `@tab` 是普通文字;首个标记前的正文保存在空标题页签中。不完整输入在解析范围内收束,规范输出补齐结束围栏。旧的 `:::tabs`、`:::tab` 不识别为页签语法,既有 `.sy` 页签节点结构不受影响。++页签项 IAL 紧接标题标记下一行,中间不留空行,之后以空行分隔正文。组 IAL 放在结束围栏之后,正文块 IAL 紧随相应正文块。任务状态也使用页签项 IAL:++```markdown+::: tabs+@tab:active 示例任务+{: id="20260905120000-item001" tabs-task="/"}++正文。+{: id="20260905120000-para001"}+:::+{: id="20260905120000-tabs001" tabs-active-id="20260905120000-item001" tabs-position="left"}+```++独立标题段落在内部 Markdown 中作为首个段落输出,并保留 `tabs-title="true"`、ID 和属性;此时 `@tab` 行不重复标题文字。剪贴板的结构化 Markdown 则把完整标题放到 `@tab` 行,不再重复输出标题段落。++## 菜单与编辑++块标操作整个页签块。块标菜单 - 页签块包含“顶部页签”“左侧页签”,分隔线后为“任务”;三个选项的选中标记均位于右侧。这些入口及分隔线登记在可配置菜单目录中,支持显示和排序设置。++标题右键菜单作用于当前页签,提供复制块引用,以及可写状态下的重命名、创建副本、删除;任务页签另有“自定义任务状态”。标题栏没有独立的“更多”按钮。整组转换入口位于块标菜单 - 转换为,包括无序列表、有序列表、任务列表和超级块。++单击标题切页,双击或选择“重命名”直接在标题位置编辑富文本,复用提示块标题的行级格式、选区和输入法处理。导航中的标题副本只负责展示,保存和反向解析以页签项内的原始标题为准。字体颜色等样式属于标题内容,重命名不会先转换成供用户编辑的代码字符串。结束编辑保留页签栏滚动位置并隐藏行级工具栏,隐藏标题选区不能在文档顶部触发工具栏。++新建页签块默认包含两个页签,各有一个空段落。新增页签追加到组末尾、选中并进入标题编辑。长标题在导航中按宽度省略,悬浮显示标题提示;全文不截断为固定字符数。导航和新增按钮不可作为正文文字选中。++### 任务状态++`tabs-task` 为一个 ASCII 空格时表示未完成,`X` 或 `x` 显示完成图标,其他受支持的单字符状态按原字符显示。自定义状态输入沿用任务列表标记校验,接受单个 ASCII 字符但不接受方括号。状态独立于标题和选中项,写入文档并同步。++块标菜单中的“任务”是整组开关:组内只要有一项具有 `tabs-task`,开关即显示选中;关闭时移除所有直属项的任务属性,开启时全部设为未完成。组内存在任务项时,新建页签也为未完成任务。跨组移动保留页签自身状态,因此混合组仍可能存在,整组开关可统一处理。++点击状态图标不会切页或进入重命名:未完成变为 `X`,其他状态变为空格。右键点击图标或使用标题菜单中的“自定义任务状态”可设置当前页签状态。状态图标不显示单独的“任务列表”悬浮提示。++### 列表和超级块转换++列表转页签只转换当前层级。每个直属列表项的首个段落成为标题,保留全文、行级格式、引用、链接、ID 和属性,不在正文中重复保留。首个块不是段落时使用空标题,原块保留在正文。子列表和嵌套页签不展开;转换后选中第一页。++转回列表时将独立标题段落移回首部,移除 `tabs-title`,正文接在后面;非空字符串标题生成新段落。标题与正文即使文字相同也不去重。只有标题的列表项转页签时会补正文落点,转回时仅省略仍为空且没有行级元素、用户属性或引用计数的 `tabs-placeholder` 段落。++任务列表转页签保留未完成、完成和自定义状态;转为任务列表时恢复当前 `tabs-task`,没有任务属性的项默认为未完成。转为普通列表移除任务属性。有序列表重新从 1 编号,布局和选择状态不作为反向转换的备份保存。++转换为超级块将页签容器和各页签项转换为纵向超级块,标题成为段落,保留原容器、页签项和正文 ID。列表转换及超级块转换通过普通编辑事务支持撤销。++## 选择、定位与拖动++可写编辑器的主动切换,以及搜索和块引用定位触发的切换,通过属性接口保存 `tabs-active-id`,并排在编辑事务之后。切页不占用正文撤销栈,不更新正文修改时间,但会落盘并同步。只读页面、嵌入预览、历史预览和导出 HTML 可临时切换,不写回选择。++刷新或重启恢复位置时,持久化的页签选择优先于隐藏页中的旧光标;焦点转到当前页正文,不复用过期文本偏移。主动定位隐藏内容时逐层激活所属页签。外部选择更新若会隐藏正在编辑的正文,延后界面切换,避免打断焦点和输入法组合。++页签项使用普通块引用语法,例如 `((20260905120000-item001 '页签标题'))`,不引入专用引用语法。引用目标是页签项 ID,定位时切到对应页签;引用悬浮预览补齐父页签容器以正常渲染。字符串标题的引用和资源归属于页签项,独立标题段落的引用和资源归属于其原段落 ID。++拖动导航标题移动整页,拖动正文块移动内容。排序预览让相邻按钮让出落点,淡化被拖动按钮,并在导航边缘自动滚动;横向和纵向布局使用相应方向。松开后提交一次事务,取消或拖回原位不提交。跨组移动在同一事务中调整两组状态,只读目标和自身后代不接受落入。++删除当前页优先选择后一个页签,否则选择前一个;删除最后一页转为空段落。普通文字选区不包含隐藏正文,整组块的复制和删除涵盖全部页签。正文边界的退格和删除不自动合并相邻页签。++## 渲染与布局++`NodeTabs` 对应 `.tabs`,直属项为 `.tab-item`;导航位于 `.tabs-header.protyle-action`,没有内容块 ID。原始标题位于 `.tab-item-info` 内的 `.tab-item-title.callout-title`,正文位于 `.tab-item-content`,不复用提示块正文类。标题编辑时使用 `.tabs-title-editor` 覆盖到对应导航按钮位置。++容器使用主题边框和圆角。顶部导航可横向滚动;左侧导航按内容分配宽度,最小宽度为 80px,列宽上限为 200px 和容器宽度的 40% 中的较小值,正文侧保留 48px 的块标操作间隔。容器宽度小于 420px 时临时显示顶部导航,不改写 `tabs-position`。++导航提供 `tablist`、`tab`、`tabpanel` 语义,各渲染实例使用独立 DOM 标识。方向键、Home 和 End 移动导航焦点,Enter 或空格激活;标题编辑时按文本编辑规则处理。隐藏页继续接收数据更新,显示时重新处理依赖尺寸的渲染节点和数据库。++## 索引、导出与格式兼容++标题参与全文索引、引用及资源扫描、动态锚文本和历史差异。字符串标题通过临时行级树处理,独立标题段落按普通段落处理,避免重复扫描。块命名优先于标题作为引用锚文本。页签内的标题块不参与文档标题编号,折叠不跨越页签项边界。++内部 Markdown 保留完整结构和属性。启用 `TabsMarkdown` 的结构化输出保留围栏、完整行级标题、选中标记和任务状态 IAL;剪贴板不输出块 ID 等完整块 IAL。关闭该选项的平铺输出按顺序输出各页标题和正文。普通文字选区复制会移除导航、隐藏正文及页签容器包装。++HTML 在初始化前显示全部内容,交互初始化成功后才隐藏未选中的页。打印、PDF 和 Word 展开全部页签,包括嵌套内容。++包含页签节点的文档使用 `Spec 3`,普通文档使用 `Spec 2`,已升级文档不自动降级。JSON 读取入口在解析和修复前拒绝不支持的未来版本。旧客户端中绕过版本检查的导入入口不具备这种保护,不能用于处理新格式文档。节点和语法由 Lute 提供,前端生成脚本与内核依赖需要包含对应能力;仓库实际依赖版本以 `kernel/go.mod` 为准。++## 代码入口++| 范围 | 入口 |+| --- | --- |+| 渲染、选择和标题编辑布局 | [`tabsRender.ts`](../app/src/protyle/render/tabsRender.ts)、[`_tabs.scss`](../app/src/assets/scss/protyle/_tabs.scss) |+| 页签操作与任务状态 | [`tabs.ts`](../app/src/protyle/wysiwyg/tabs.ts)、[`taskListMarker.ts`](../app/src/protyle/wysiwyg/taskListMarker.ts) |+| 列表转换和删除修复 | [`tabsList.ts`](../app/src/protyle/wysiwyg/tabsList.ts)、[`tabsRemoval.ts`](../app/src/protyle/wysiwyg/tabsRemoval.ts) |+| 块标菜单及配置目录 | [`gutter/index.ts`](../app/src/protyle/gutter/index.ts)、[`catalog.ts`](../app/src/config/entryVisibility/catalog.ts) |+| 内核规范化和标题遍历 | [`treenode/tabs.go`](../kernel/treenode/tabs.go)、[`model/tabs.go`](../kernel/model/tabs.go) |+| JSON 格式 | [`SY-FORMAT.zh-CN.md`](SY-FORMAT.zh-CN.md) |diff --git a/docs/TABS.md b/docs/TABS.mddeleted file mode 100644index f68202970f..0000000000--- a/docs/TABS.md+++ /dev/null@@ -1,142 +0,0 @@-# 页签块设计与评审--关联问题:https://github.com/siyuan-note/siyuan/issues/17642--## 数据模型--- `NodeTabs` 是页签容器,直属内容块只能是 `NodeTabItem`。-- `NodeTabItem` 是有独立块 ID 的容器,正文容纳普通块,包括嵌套的 `NodeTabs`;不能直接容纳文档、裸列表项或裸页签项。-- 普通页签的 `TabItemTitle` 保存行级 Markdown,标题能力沿用提示块。列表转换后的标题使用 `NodeTabItem` 的首个 `NodeParagraph` 子节点,以 `tabs-title="true"` 标记,保留原段落 ID、属性和行级内容;存在该段落时以它为唯一标题来源,不再使用字符串字段。标题允许重复和清空,空标题的占位提示不写入正文。-- 页签顺序由子节点顺序决定。`tabs-active-id` 保存选中的直属页签项 ID,`tabs-position` 为 `top` 或 `left`。-- 两种属性均保存在页签容器的 IAL 中,随文档持久化、同步。缺失或失效的选中项回退到第一页,缺失布局采用 `top`。-- 规范数据至少包含一个页签项,每页至少包含一个正文块,空正文使用空段落。构造或事务过程允许暂时为空,事务结束和写入时统一规范化。-- 移动保留 ID;复制、模板插入、导入和恢复重建 ID 时,必须同时映射选中项和标题中的内部引用。-- 单独复制或剪切的页签项粘贴到普通正文时,自动补齐页签容器,保留完整标题和正文。--## 文本语法--```markdown-::: tabs-@tab **Windows**--Windows 下的说明。--@tab:active Linux--Linux 下的说明。-:::-```--开始围栏至少包含三个冒号,冒号与 `tabs` 之间需要空格或制表符;规范输出使用一个空格。标题是 `@tab` 或 `@tab:active` 后的行级内容,有标题时也以空格或制表符分隔。每个标记开始一个新的直属页签项,页签项没有单独的结束标记。整组以独占一行、与开始围栏冒号数量相同的结束围栏闭合。--`@tab:active` 指定该组当前选中的页签;一组内出现多个选中标记时,采用第一个有效标记。明确的选中标记优先于组 IAL 中的 `tabs-active-id`;没有选中标记时,保留有效的 `tabs-active-id`,缺失或失效时回退到第一页。内部 Markdown 输出将持久化的选中项写为 `@tab:active`,导入后恢复为 `tabs-active-id`,嵌套各组独立处理。--支持在列表、引述、超级块和页签项中嵌套。外层围栏必须比其包含的内层围栏长,缩进可选;规范输出根据嵌套深度自动计算围栏长度,不额外缩进页签正文。单层使用三个冒号,两层使用外四内三,依此类推,没有固定的语法嵌套层数上限。--```markdown-:::: tabs-@tab 外层第一页--::: tabs-@tab 内层第一页--内层正文。-:::--@tab 外层第二页--外层正文。-::::-```--代码块中的页签标记和围栏按字面保留。正文行首需要显示页签标记时,使用 `\@tab` 或 `\@tab:active` 转义。组外的孤立 `@tab` 保留为文字;首个页签标记之前的正文保留在空标题页签项中。不完整输入按解析范围容错收束,规范输出补齐整组结束围栏,不能丢失正文。旧的 `:::tabs`、`:::tab` Markdown 语法不再识别为页签,不影响既有 `.sy` 中的页签节点结构。--页签项的 IAL 紧接标题标记下一行,中间不留空行;正文在其后的空行之后开始。组结束围栏之后的 IAL 属于整组容器,正文块的 IAL 仍紧随对应正文块。该位置约定区分页签项与首个空段落的属性,分别保存各节点的 ID 和属性。使用独立标题段落时,内部 Markdown 的 `@tab` 行不重复写标题文字,首个段落及其 `tabs-title="true"` 属性完整保存标题;解析后将该段落渲染到标题区域。--```markdown-::: tabs-@tab:active 示例-{: id="20260905120000-item001"}--正文。-{: id="20260905120000-para001"}-:::-{: id="20260905120000-tabs001" tabs-active-id="20260905120000-item001"}-```--独立页签项的 BlockDOM 是合法编辑片段,但不能作为完整文档的直属内容。片段经过内部 Markdown 时使用临时页签容器,恢复时依据原片段身份去掉包装,保留页签项 ID。--## 渲染与编辑--通过块标菜单的 `转换为` 可以将当前列表转为页签,或者将当前页签转为无序、有序、任务列表。只转换当前层级,正文中的子列表和嵌套页签保持原样。列表容器、列表项及正文块沿用原 ID 和属性;类型专属状态随转换重置,整个操作支持一次撤销。--列表转页签时,每个直属列表项的首个段落成为页签标题,不再同时留在正文中。标题保存全文,包括行级格式、引用、链接和原段落的 ID、属性;不截取 12 个 rune。导航栏按可用宽度显示省略号,完整内容仍可编辑和还原。首个正文块不是段落时使用空标题,原块保留在正文。转换后默认选择第一页。--页签转列表时,将标题段落原样放回列表项首部,移除标题角色标记,原正文接在后面。普通页签的字符串标题转换为新段落。标题与正文即使文字相同也属于不同内容,不能仅凭文字去重。列表项只有标题时,转换为页签会补出带 `tabs-placeholder="true"` 标记的空正文落点;转回列表仅省略没有文字、行级元素、用户属性或引用计数的该类落点,已有空段落和填写过的正文保留。有序列表从 1 开始,任务列表全部未完成;不保留原列表编号、勾选状态或页签布局、选中状态用于后续反向转换。--- 页签容器使用 `.tabs`,导航控件位于 `.tabs-header.protyle-action`,控件不持有内容块 ID。-- 直属页签项使用 `.tab-item`,标题保存在项内唯一的 `.tab-item-title.callout-title`,正文位于 `.tab-item-content`。正文不复用 `.callout-content`,避免提示块退出行为破坏页签父子关系。-- 导航栏只是标题的展示,反向解析以页签项中的原始标题为唯一来源。嵌套查找必须限制到直属结构。-- 单击切页,双击或菜单进入标题编辑。标题编辑复用提示块行级格式、选区与输入法规则,移动端提供菜单入口。-- 重命名对话框使用行级 Markdown:普通格式使用标准 Markdown,含字体颜色等样式时使用可逆的 Kramdown,确认时重新解析,因此 `**foo**` 等格式可以直接输入,组合文本标记和字体样式不会因重命名而丢失。由列表转换的标题段落仍保留原 ID 和块属性。-- 新建页签块默认包含两个页签,各包含一个空段落。标题、正文、排序和布局变更参与正常撤销。-- 可写编辑器中的主动切换和搜索、引用定位保存选中项。切换不占用正文撤销栈,不刷新正文修改时间,但会落盘并参与同步。-- 刷新或重启后恢复文档位置时,页签选择优先于过期光标。旧光标位于未选中的页签内时,将焦点移到当前选中页的正文,不复用旧文本偏移;保存文档位置时也不记录隐藏页中的过期光标。主动搜索和块引用定位仍可切换到目标页。-- 只读页面、历史预览和导出 HTML 可临时切换。外部状态更新先接收数据,若将隐藏正在编辑的正文,延后界面切换,避免丢失焦点和输入法组合。-- 各层嵌套独立保存选择。定位隐藏内容时逐层激活所属页签;单独打开页签项展示标题与全部正文。-- 普通文字选区不隐式包含隐藏正文;选中整组块后,复制和删除涵盖全部页签。正文首尾的退格和删除不能自动合并相邻页签。-- 页签项拖动移动整页,正文块拖动移动内容。跨组移动及两组选择状态调整在同一事务中完成。-- 拖动导航页签时实时调整按钮位置并淡化被拖动的按钮,相邻页签让出落点;横向和纵向布局分别按对应方向判断位置,靠近导航边缘时滚动。预览不调整正文,松开后提交一次排序事务,取消拖动或拖回原位不提交排序。跨组拖动采用相同反馈,只读目标和自身后代不接受落入。-- 删除当前页后优先选中后一个页签,否则选前一个。删除最后一页时移除容器,必要时补空段落作为光标落点。-- 取消页签布局时,两层容器转换为纵向超级块,标题转换为段落,保留容器、页签项和原正文 ID。--## 布局与可访问性--顶部页签横向排列,过多时滚动并保证选中项可见。左侧页签限制栏宽;窄屏根据容器实际宽度临时改为顶部显示,不将响应式结果写回同步属性。--导航栏获得焦点时使用对应方向键移动,确认键激活;进入标题编辑后按文本编辑处理按键。提供页签列表、页签和面板的无障碍语义,每个渲染实例使用独立的 DOM 标识,支持同一块在多个编辑器或嵌入位置出现。--隐藏页仍接收内容更新。图表、数据库及其他依赖尺寸的组件首次显示时重新测量,切换保持合理的视口锚点。--## 索引与导出--页签标题需要显式接入全文索引、引用与资源扫描、动态锚文本和历史差异。字符串标题的临时行级树关联页签项 ID;由列表转换的标题段落沿用自身块 ID,按普通段落索引和扫描,不再合成临时标题,以免重复索引或错误归属引用。块命名优先于标题作为引用锚文本。页签内标题与提示块内标题一样,不参与文档标题编号;折叠不能越过页签项边界。--HTML 保留交互,初始化前或脚本失败时显示全部内容。打印、PDF 和 Word 递归展开全部页签并完成内容渲染。标准 Markdown 按顺序输出页签标题段落和正文,保留标题行级格式及正文原有标题级别;内部 Markdown 保留完整结构和属性。复制整组页签或独立页签项时,剪贴板 Markdown 保留围栏、完整行级标题、嵌套结构和选中标记,但不输出块 IAL;原标题段落只输出到 `@tab` 行,不重复出现在正文。普通文字选区先去掉导航及隐藏正文并解除页签容器,仅复制选中的可见内容。--## 兼容性--当前数据解析器会把不认识的节点转为段落并清空子节点,因此页签数据必须使用格式版本保护。读取上限扩展为 Spec 3,普通文档仍采用 Spec 2,包含页签节点的文档升级到 Spec 3,已经升级的文档不自动降级。--当前客户端各 JSON 加载入口在解析、修复之前检查格式版本,拒绝不支持的未来版本。旧客户端常规加载中的版本检查可以防止修复写回;已经发布的旧客户端中存在绕过版本检查的导入等路径,无法由本次修改追溯修复,不能将新格式文件交给这些旧入口处理。发布时需要协调桌面、浏览器与移动端内核版本。--## 验收要求--- Markdown、BlockDOM 和 JSON 多次转换后,结构、标题、ID、布局和选中项保持稳定。-- 覆盖嵌套、空标题、空页、连续 IAL、代码围栏、特殊字符、列表和引述内页签、不完整输入及独立编辑片段。-- 覆盖复制、模板、导入、跨组移动、删除、撤销和历史恢复的 ID 与选择状态。-- 覆盖标题全文检索、引用更新、资源路径、历史差异和隐藏内容定位。-- 覆盖多窗口状态更新、只读切换、输入法组合、正文选区、触控和窄屏布局。-- 覆盖隐藏内容首次渲染、HTML 无脚本回退,以及标准 Markdown、HTML、打印、PDF、Word 的完整内容输出。-- 覆盖不支持格式版本的拒绝读取和拒绝写回。-- 前端运行 `pnpm run lint` 和相关测试;语言修改运行 `python scripts/check-lang-keys.py`;Go 修改运行 `gofmt` 和相关测试。内核编译、重启及前端开发构建由开发者负责。--## 本地联调与发布依赖--本次同时修改 SiYuan、Lute 和 Petal。前端的 `lute.min.js` 从修改后的 Lute 源码重新生成。内核使用仓库根目录的本地 `go.work` 关联 `kernel` 和本机 Lute 检出;该文件通过 `.git/info/exclude` 排除,不把机器路径写入 `kernel/go.mod`。--发布前需要先发布 Lute,再将 `kernel/go.mod` 中的 Lute 版本更新到对应版本并更新校验和。现有旧版依赖不包含新节点,仅更新 SiYuan 源码不足以完成发布。Petal 的新增声明应随对应应用版本发布。--## 初次实现验证--- 前端类型和样式检查、189 项相关单元测试、21 种语言的键完整性检查通过。-- Lute 全量测试通过,包含嵌套语法、标题格式、独立页签片段和连续空段落 ID 的多轮转换。-- 内核的页签、格式版本、标题引用归属、标题资源改写、导出资源命名、历史差异和标题编号相关测试通过。四种语言的 12 份指南修改已检查块 ID 和结构。-- 使用重新生成的 Lute 脚本,在 Edge 中验证渲染、嵌套、顶部和左侧布局、窄屏、键盘、只读、延迟接收外部选择、打印,以及新增、复制、移动、删除、撤销快照、取消布局、粘贴和文字选区。操作测试替换了网络与事务提交边界,未运行完整应用。-- 完整应用中的输入法组合、真实多窗口同步、触控和 PDF 生成需要在开发者手动构建并启动新内核、前端后继续联调。本次未编译或重启内核,未运行前端构建。--## 列表标题与复制回归验证--- Lute 全量测试通过,新增独立标题段落的多轮 BlockDOM、内部 Markdown 和 HTML 转换,以及空标题、多行标题、长标题、嵌套选中状态和代码中 IAL 字面量的剪贴板回归覆盖。-- 内核页签、标题引用归属、索引和格式版本相关测试通过。独立标题引用继续归属于原段落,批量扫描和改写不重复合成标题。-- 前端类型、样式检查和相关单元测试通过。使用实际转换、页签操作、事务生成代码及重新生成的 Lute,在 Edge 中验证三种列表互转、改名、复制、内部 ID 映射、取消布局、折叠内容补全、普通文本选区和撤销快照。网络及事务执行边界使用测试替身,完整应用联调仍由手动构建后验证。