Skip to content

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

:memo: Improve .sy format documentation

Daniel7fdb2e1e87f8
diff --git a/docs/SY-FORMAT.md b/docs/SY-FORMAT.md
index 50ee60024a..89094e292e 100644
--- a/docs/SY-FORMAT.md
+++ b/docs/SY-FORMAT.md
@@ -1,13 +1,26 @@
# SiYuan `.sy` File JSON Structure — AI Read/Write Guide
-> Spec baseline: `2` (current across all files).
+> Canonical Spec baseline: `2` (the current writer output; compatible readers may encounter an older or missing `Spec` and upgrade it).
> Verified against samples: `20200825162036-4dx365o.sy` (formatting elements), `20200905090211-2vixtlf.sy` (block types).
-> All conclusions are based on real samples and the Lute / SiYuan kernel source. Fields marked `【inferred】` were not directly observed in the samples — re-verify against a real sample before generating them.
+> All conclusions are based on real samples and the current Lute / SiYuan kernel source. The cited samples contain a few known legacy artifacts; canonical write rules follow the current source when a sample differs.
+> This guide describes plaintext `.sy` JSON in an ordinary notebook, or the decrypted AST of an unlocked encrypted notebook. An encrypted notebook's on-disk `.sy` file is ciphertext and must not be edited as JSON.
> Companion document: [`WORKSPACE.md`](./WORKSPACE.md) covers the overall on-disk layout of the workspace (how notebooks, parent/child documents, and assets are organized); this document focuses on the **internal** JSON structure of a `.sy` file.
## 0. In one sentence
-A `.sy` file is a Lute AST tree serialized to JSON. The root node is always `NodeDocument`; the body is the `Children` array, recursively nested. There is no external schema — all state lives in the tree.
+A plaintext `.sy` file is a Lute AST tree serialized to JSON. The root node is `NodeDocument`; the body is the recursively nested `Children` array. There is no separately maintained JSON Schema — the Lute `ast.Node` and `ListData` Go structs are the serialization source of truth. The tree contains the document AST and its IAL, while assets, AttributeView definitions, and rebuildable indexes live outside the tree.
+
+## 0.1 Canonical writes vs. compatible reads
+
+This guide distinguishes the format that new writers should emit from historical data that the kernel can tolerate and normalize:
+
+| Term | Meaning |
+|---|---|
+| **Required** | Required in newly generated canonical Spec 2 data |
+| **Optional** | May be omitted because the field is empty or carries `omitempty` |
+| **Compatible input** | Historical or external data that the reader may accept and preserve, repair, or upgrade according to explicit compatibility rules |
+
+Unless a section explicitly says otherwise, "required" refers to canonical new writes. `dataparser.ParseJSON` is a compatibility reader rather than a strict schema validator: for example, it can add a missing empty paragraph, assign a missing block ID, and upgrade an old `Spec`.
---
@@ -31,6 +44,7 @@ Division of labor among the four paths:
| **Read/write `.sy` directly** | The scope of this guide | Offline, bulk, low-level structural work |
> ⚠️ After writing files directly you usually need a "rebuild index" pass before search/block-refs become effective. If SiYuan is running, prefer the HTTP API and let the kernel handle serialization and index sync.
+> ⚠️ Do not directly mutate encrypted-notebook persistent files. Use the dedicated APIs after unlocking the notebook so encryption, authentication, and isolated indexes remain consistent.
---
@@ -54,13 +68,14 @@ Division of labor among the four paths:
| Top-level key | Required | Meaning |
|---|---|---|
-| `ID` | ✅ | Document block ID. **Equals the filename without `.sy`** (not randomly generated) |
-| `Spec` | ✅ | Always `"2"` |
-| `Type` | ✅ | Always `"NodeDocument"` |
+| `ID` | ✅ | Document block ID. **Equals the filename without `.sy`** |
+| `Spec` | ✅ | `"2"` in canonical current files; older or missing values are compatible input and may be upgraded |
+| `Type` | ✅ | `"NodeDocument"` |
| `Properties` | ✅ | Document-level IAL — see §8 |
-| `Children` | ✅ | Array of body child blocks; must contain at least one block |
+| `Children` | ✅ | Array of body child blocks; canonical files contain at least one block |
> ⚠️ The file path strictly corresponds to the root ID: `data/<box>/<...>/<rootID>.sy`. Changing the root ID means renaming the file — don't change it casually. For the full file-system layout see [`WORKSPACE.md`](./WORKSPACE.md).
+> A compatible reader inserts an empty paragraph when `Children` is missing or empty, but new writers should emit that paragraph themselves.
---
@@ -69,39 +84,44 @@ Division of labor among the four paths:
| Field | Type | Presence | Meaning |
|---|---|---|---|
| `Type` | string | **required on every node** | Type discriminator, e.g. `"NodeParagraph"` |
-| `ID` | string | block nodes only | 22-char block ID; inline/marker nodes **do not carry it** |
+| `ID` | string | required on canonical block nodes; may occur on compatible non-block input | 22-char block ID for blocks; canonical writers do not add it to inline/marker nodes |
| `Data` | string | some | Text / HTML / markdown raw; **may be omitted** (don't assume it exists) |
-| `Properties` | object | most blocks | IAL, `map[string]string` |
-| `Children` | array | container / nestable nodes | Child node array |
+| `Properties` | object | blocks and some inline nodes | IAL, `map[string]string`; inline uses include styled text, images, and table cells |
+| `Children` | array | containers and structurally composite nodes | Child node array |
| Type-specific fields | - | per type | e.g. `HeadingLevel`, `ListData`, `TextMarkType`, `AttributeViewID` |
-**Core discriminator rule:** whether a node has an `ID` determines whether it is a block. Has `ID` ⇒ block (its `Properties.id` must equal its `ID`); no `ID` ⇒ inline/marker node.
+**Core discriminator rule:** `Type` determines whether a node is a block (`ast.Node.IsBlock()` is authoritative); the presence of `ID` does not. In canonical Spec 2 data, every block has an `ID` and matching `Properties.id`, while new inline/marker nodes have neither. Historical files produced by old bugs may contain IDs on non-block nodes such as `NodeCodeBlockCode` or `NodeMathBlockContent`. Compatible readers and editors may remove those legacy `ID` / `Properties.id` fields during normalization, but must classify the node by `Type` and must not delete the node merely because its `ID` conflicts with the canonical rule.
---
## 3. ID and timestamp rules
- **ID format:** `YYYYMMDDHHMMSS-xxxxxxx` = 14-digit timestamp + `-` + 7 random `[a-z0-9]` chars. Example: `20210104091228-ttcj9nm`.
+- **Uniqueness:** every newly generated document and block ID must be fresh and unique across the workspace, not merely unique within one file.
- The **root ID** comes from the filename and is **not** regenerated.
-- **Child block IDs** are generated with the above scheme.
+- **Child block IDs** are newly generated with the above scheme; never copy literal IDs from examples or templates.
- `Properties.updated` is the same 14-digit timestamp; semantics: "last updated time".
-- When you change any block's `ID`, you must **sync** `Properties.id`. `Properties.updated` should be refreshed to the current time as well.
+- When changing block content or structure, refresh `Properties.updated` on the changed block, its block-level ancestors, applicable preceding headings, and the document root.
+- When you change any block's `ID`, you must **sync** `Properties.id`. Its `Properties.updated` must be no earlier than the creation time encoded by the new ID.
+- Compatible historical input may lack `updated`; canonical new writes should always include it on block nodes.
---
## 4. Node-type catalog
-### Block nodes (have an ID)
+### Block nodes (have an ID in canonical data)
-**Leaf blocks:** `NodeParagraph`, `NodeHeading`, `NodeThematicBreak`, `NodeHTMLBlock`, `NodeCodeBlock`, `NodeMathBlock`, `NodeTable`, `NodeBlockQueryEmbed`, `NodeAttributeView`, `NodeIFrame`, `NodeVideo`, `NodeAudio`, `NodeWidget`, `NodeCustomBlock`, `NodeGitConflict`
+**Leaf blocks:** `NodeParagraph`, `NodeHeading`, `NodeThematicBreak`, `NodeHTMLBlock`, `NodeCodeBlock`, `NodeMathBlock`, `NodeTable`, `NodeBlockQueryEmbed`, `NodeAttributeView`, `NodeIFrame`, `NodeVideo`, `NodeAudio`, `NodeWidget`, `NodeCustomBlock`
**Container blocks:** `NodeList`, `NodeListItem`, `NodeBlockquote`, `NodeCallout`, `NodeSuperBlock`
-### Inline / marker nodes (no ID)
+### Inline / marker nodes (no ID in canonical data)
-`NodeText`, `NodeTextMark`, `NodeImage`, `NodeKramdownSpanIAL`, `NodeHeadingC8hMarker`, `NodeBlockquoteMarker`, `NodeTaskListItemMarker`, `NodeBang`, `NodeOpenBracket`, `NodeCloseBracket`, `NodeOpenParen`, `NodeCloseParen`, `NodeLinkText`, `NodeLinkDest`, `NodeCodeBlockCode`, `NodeCodeBlockFenceOpenMarker`, `NodeCodeBlockFenceInfoMarker`, `NodeCodeBlockFenceCloseMarker`, `NodeMathBlockContent`, `NodeMathBlockOpenMarker`, `NodeMathBlockCloseMarker`, `NodeSuperBlockOpenMarker`, `NodeSuperBlockLayoutMarker`, `NodeSuperBlockCloseMarker`, `NodeOpenBrace`, `NodeCloseBrace`, `NodeBlockQueryEmbedScript`, `NodeTableHead`, `NodeTableRow`, `NodeTableCell`
+`NodeText`, `NodeTextMark`, `NodeImage`, `NodeKramdownSpanIAL`, `NodeSoftBreak`, `NodeBr`, `NodeBackslash`, `NodeBackslashContent`, `NodeHeadingC8hMarker`, `NodeBlockquoteMarker`, `NodeTaskListItemMarker`, `NodeBang`, `NodeOpenBracket`, `NodeCloseBracket`, `NodeOpenParen`, `NodeCloseParen`, `NodeLinkText`, `NodeLinkDest`, `NodeLinkSpace`, `NodeLinkTitle`, `NodeCodeBlockCode`, `NodeCodeBlockFenceOpenMarker`, `NodeCodeBlockFenceInfoMarker`, `NodeCodeBlockFenceCloseMarker`, `NodeMathBlockContent`, `NodeMathBlockOpenMarker`, `NodeMathBlockCloseMarker`, `NodeSuperBlockOpenMarker`, `NodeSuperBlockLayoutMarker`, `NodeSuperBlockCloseMarker`, `NodeOpenBrace`, `NodeCloseBrace`, `NodeBlockQueryEmbedScript`, `NodeTableHead`, `NodeTableRow`, `NodeTableCell`
-> Types disabled by SiYuan (footnotes / ToC / YAML / LinkRef / HeadingID, etc.) are listed in §11 and never appear in a `.sy` — they are intentionally excluded from this catalog.
+> "Leaf block" means the node cannot contain other **block nodes**. A leaf may still have structural inline children, as code blocks, math blocks, and tables do.
+> The heading above is a canonical-write rule. An explicit normalization pass may remove an `ID` already present on a compatible historical non-block node, but must not use that field to decide whether the node is a block or whether the node itself should be removed.
+> Types excluded from canonical writes — including parser-disabled syntax and the detection-only `NodeGitConflict` family — are listed in §11 and intentionally omitted from this catalog.
---
@@ -128,7 +148,7 @@ Division of labor among the four paths:
### 5.3 Lists (key: distinguish type via `ListData.Typ`)
-> **★ Hard structural constraint of lists:** direct children of `NodeList` can **only** be `NodeListItem` (enforced by Lute's `CanContain`, `ast/node.go:993` `return NodeListItem == nodeType`). Paragraphs, code blocks, sub-lists, or any other block **cannot** be attached directly under `NodeList` — they must be wrapped in a `NodeListItem` first.
+> **★ Canonical structural constraint of lists:** direct children of `NodeList` can **only** be `NodeListItem` (`CanContain` returns `NodeListItem == nodeType`). Paragraphs, code blocks, sub-lists, or any other block **cannot** be attached directly under `NodeList` — they must be wrapped in a `NodeListItem` first. `dataparser.ParseJSON` does not enforce this as a strict validation step, so direct writers must validate the structure themselves.
```
✅ Correct ❌ Wrong
@@ -153,13 +173,13 @@ NodeList NodeList
```json
{ "Type": "NodeList", "ID": "...", "ListData": {},
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeListItem", "ID": "...",
"ListData": { "BulletChar": 42, "Marker": "Kg==" },
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "Item one" } ] }
] }
] }
@@ -168,21 +188,33 @@ NodeList NodeList
**Ordered list** (`Typ: 1`):
```json
-{ "Type": "NodeListItem", "ID": "...", "Data": "1",
- "ListData": { "Typ": 1, "Tight": true, "Start": 1, "Delimiter": 46, "Padding": 3, "Marker": "MQ==", "Num": 1 },
- "Properties": { "id": "..." }, "Children": [ ... ] }
+{ "Type": "NodeList", "ID": "...", "ListData": { "Typ": 1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeListItem", "ID": "...",
+ "ListData": { "Typ": 1, "Tight": true, "Start": 1, "Delimiter": 46, "Padding": 3, "Marker": "MS4=", "Num": 1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
+ "Children": [ { "Type": "NodeText", "Data": "Item one" } ] }
+ ] }
+ ] }
```
-**Task list** (`Typ: 3`); the first child is a `NodeTaskListItemMarker`:
+**Task list** (`Typ: 3`); each `NodeListItem` starts with a `NodeTaskListItemMarker`:
```json
-{ "Type": "NodeListItem", "ID": "...",
- "ListData": { "Typ": 3, "Tight": true, "BulletChar": 45, "Padding": 2, "Checked": true, "Marker": "LQ==", "Num": -1 },
- "Properties": { "id": "..." },
+{ "Type": "NodeList", "ID": "...", "ListData": { "Typ": 3 },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
- { "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true },
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
- "Children": [ { "Type": "NodeText", "Data": "Task one" } ] }
+ { "Type": "NodeListItem", "ID": "...",
+ "ListData": { "Typ": 3, "Tight": true, "BulletChar": 45, "Padding": 2, "Marker": "LQ==", "Num": -1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 88 },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
+ "Children": [ { "Type": "NodeText", "Data": "Task one" } ] }
+ ] }
] }
```
@@ -197,29 +229,41 @@ NodeList NodeList
| `Start` | int | number | Ordered-list start number |
| `Num` | int | number | This item's number; usually omitted or `-1` for unordered/task lists |
| `Padding` | int | number | Indent padding; optional |
-| `Checked` | bool | boolean | Whether the task item is checked (aggregated at the list level) |
+| `MarkerOffset` | int | number | Marker indentation offset; optional |
+| `Checked` | bool | boolean | Compatibility metadata derived while parsing a task marker; it is not an aggregate for the whole list and may be omitted |
| `Marker` | []byte | **base64 string** | The marker text, **base64-encoded**; may include a delimiter (`"MS4="` = `1.`) or not (`"MQ=="` = `1`) |
> Key distinction: **`BulletChar`/`Delimiter` are `byte` in code and appear as int codepoints in JSON**; **`Marker` is `[]byte` in code and appears as a base64 string in JSON**. `Marker`/`BulletChar`/`Delimiter` all carry `omitempty` and may be omitted.
### 5.5 Task marker
+Checked with `X`:
+
```json
-// Checked
-{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true }
-// Unchecked
-{ "Type": "NodeTaskListItemMarker" }
+{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 88 }
```
-> In real `.sy` files, `NodeTaskListItemMarker` **usually has no `Data` field** (SiYuan rebuilds the marker from the DOM `data-task` attribute and doesn't keep the `[X]`/`[ ]` source): checked items carry only `Type`+`TaskListItemChecked`, unchecked only `Type`. If you do write `Data` by hand, the checked form should be uppercase `[X]` (not `[x]`) — but that's only used for normalized Markdown export.
+Unchecked with a space:
+
+```json
+{ "Type": "NodeTaskListItemMarker", "TaskListItemMarker": 32 }
+```
+
+An arbitrary non-space marker such as `!` is also treated as checked and preserves its original byte:
+
+```json
+{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 33 }
+```
+
+`TaskListItemMarker` is a Go `byte`, so JSON stores its ASCII codepoint as a number. Current rendering prefers this field and falls back to `TaskListItemChecked` for compatible older data. `Data` may appear when the AST comes directly from Markdown parsing (for example `"[X]"`), but editor-generated `.sy` data usually omits it; do not use `Data` as the authoritative task state.
### 5.6 Blockquote
```json
-{ "Type": "NodeBlockquote", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeBlockquote", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeBlockquoteMarker", "Data": "> " },
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "Quoted content" } ] }
] }
```
@@ -232,7 +276,7 @@ NodeList NodeList
{ "Type": "NodeCallout", "ID": "...",
"CalloutType": "NOTE", "CalloutTitle": "Note", "CalloutIcon": "✏️",
"Properties": { "id": "...", "updated": "..." },
- "Children": [ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ "Children": [ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "Callout content" } ] } ] }
```
@@ -244,26 +288,26 @@ NodeList NodeList
| `WARNING` | `Warning` | `⚠️` |
| `CAUTION` | `Caution` | `🚨` |
-> `CalloutIcon` is a **literal emoji character**, not base64, not a codepoint.
+The table lists the five built-in types and their defaults. Custom `CalloutType`, title, and icon values are also supported. `CalloutIcon` is a literal emoji for `CalloutIconType: 0` (the default, omitted by `omitempty`); `CalloutIconType: 1` means `CalloutIcon` is a custom icon path.
-### 5.8 Super block (nestable; three-part structure)
+### 5.8 Super block (nestable; three-marker envelope)
```json
-{ "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeSuperBlockOpenMarker" },
{ "Type": "NodeSuperBlockLayoutMarker", "Data": "col" },
- { "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "..." }, "Children": [ ... nested super block, Data "row" ... ] },
+ { "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." }, "Children": [ ... nested super block, Data "row" ... ] },
{ "Type": "NodeSuperBlockCloseMarker" }
] }
```
-> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (horizontal) or `"col"` (vertical). Super blocks can nest, and it is the only container that can hold any block (including itself).
+> `NodeSuperBlockLayoutMarker.Data` can only be `"row"` (horizontal) or `"col"` (vertical). A canonical super block contains the open marker, layout marker, at least one content block, and close marker — at least four children total. It may contain multiple content blocks, can nest, and is the only container that can hold any block (including itself).
### 5.9 Embed block (five-part structure `{{ ... }}`)
```json
-{ "Type": "NodeBlockQueryEmbed", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeBlockQueryEmbed", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeOpenBrace" },
{ "Type": "NodeOpenBrace" },
@@ -279,7 +323,7 @@ NodeList NodeList
{ "Type": "NodeCodeBlock", "ID": "...", "IsFencedCodeBlock": true,
"CodeBlockFenceChar": 96, "CodeBlockFenceLen": 3,
"CodeBlockOpenFence": "YGBg", "CodeBlockInfo": "Z28=", "CodeBlockCloseFence": "YGBg",
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeCodeBlockFenceOpenMarker", "Data": "```", "CodeBlockFenceLen": 3 },
{ "Type": "NodeCodeBlockFenceInfoMarker", "CodeBlockInfo": "Z28=" },
@@ -291,13 +335,13 @@ NodeList NodeList
Notes:
- `NodeCodeBlockCode` carries the code content (in `Data`, raw text with `\n` escaped); it's an inline child of `NodeCodeBlock`.
- The surrounding fence markers (Open/Info/Close) are likewise inline children.
-- `CodeBlockInfo` is the **base64-encoded language** (`"Z28="` = `go`). The parent's seven fields (`IsFencedCodeBlock`/`CodeBlockFenceChar`/`CodeBlockFenceLen`/`CodeBlockOpenFence`/`CodeBlockInfo`/`CodeBlockCloseFence`) all carry `omitempty` and may be omitted as needed — newer `.sy` files often write only `"IsFencedCodeBlock": true`.
-- SiYuan **does not support indented code blocks** (`SetIndentCodeBlock(false)`); all code blocks are fenced.
+- `CodeBlockInfo` is the **base64-encoded language** (`"Z28="` = `go`). The parent's six fields (`IsFencedCodeBlock`/`CodeBlockFenceChar`/`CodeBlockFenceLen`/`CodeBlockOpenFence`/`CodeBlockInfo`/`CodeBlockCloseFence`) all carry `omitempty` and may be omitted as needed — newer `.sy` files often write only `"IsFencedCodeBlock": true`.
+- The current SiYuan Markdown configuration disables indented code blocks (`SetIndentCodeBlock(false)`); canonical new code blocks are fenced.
### 5.11 Math block (three-part structure)
```json
-{ "Type": "NodeMathBlock", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeMathBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeMathBlockOpenMarker" },
{ "Type": "NodeMathBlockContent", "Data": "a^2 + b^2 = c^2" },
@@ -305,22 +349,23 @@ Notes:
] }
```
-### 5.12 HTML / IFrame / Video / Audio blocks (leaf; content in the top-level `Data`)
+### 5.12 HTML / IFrame / Widget / Video / Audio blocks (leaf; content in the top-level `Data`)
```json
-{ "Type": "NodeHTMLBlock", "ID": "...", "Data": "<div>\n<ruby>你<rt>nǐ</rt>...</div>", "Properties": { "id": "..." } }
-{ "Type": "NodeIFrame", "ID": "...", "Data": "<iframe src=\"...\"></iframe>", "Properties": { "id": "..." } }
-{ "Type": "NodeVideo", "ID": "...", "Data": "<video controls src=\"assets/x.mp4\"></video>", "Properties": { "id": "..." } }
-{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "..." } }
+{ "Type": "NodeHTMLBlock", "ID": "...", "Data": "<div>\n<ruby>你<rt>nǐ</rt>...</div>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeIFrame", "ID": "...", "Data": "<iframe src=\"...\"></iframe>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeWidget", "ID": "...", "Data": "<iframe src=\"/widgets/example\" data-subtype=\"widget\"></iframe>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeVideo", "ID": "...", "Data": "<video controls src=\"assets/x.mp4\"></video>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "...", "updated": "..." } }
```
-> These four **have no `Children`**; the HTML content (JSON-escaped) goes directly in the top-level `Data`.
+> These five **have no `Children`**; the HTML content (JSON-escaped) goes directly in the top-level `Data`.
### 5.13 Table
```json
{ "Type": "NodeTable", "ID": "...", "TableAligns": [0, 0, 0],
- "Properties": { "id": "...", "colgroup": "||" },
+ "Properties": { "id": "...", "updated": "...", "colgroup": "||" },
"Children": [
{ "Type": "NodeTableHead", "Data": "thead", "Children": [
{ "Type": "NodeTableRow", "Data": "tr", "Children": [
@@ -334,9 +379,11 @@ Notes:
```
- Nesting is fixed: `NodeTable > NodeTableHead/NodeTableRow > NodeTableCell > inline`.
-- `TableAligns`: int array of per-column alignment, `0` = default/left.
+- `TableAligns`: int array of per-column alignment: `0` = default, `1` = left, `2` = center, `3` = right.
- `Data` (`thead`/`tr`/`th`/`td`) may be **omitted** in compact files.
-- Column widths are stored in `Properties.colgroup` (`|`-separated).
+- `Properties.colgroup` stores a `|`-separated CSS style string for each column; empty segments represent columns without an explicit style.
+- A table's optional `Properties.caption` stores its caption HTML.
+- A `NodeTableCell` may carry `Properties.colspan`, `Properties.rowspan`, and `Properties.style` for merged-cell and cell-style state.
### 5.14 AttributeView block (database; leaf)
@@ -350,16 +397,25 @@ Notes:
- **Has no `Children`.**
- `AttributeViewID` points to the AV table data (stored in a separate `.json` — **don't** fabricate this ID).
- `AttributeViewType`: `table` / `kanban` / `gallery`, etc.
-- `custom-sy-av-view` records the current view ID.
+- Optional `custom-sy-av-view` records the current view ID; it may be absent when no explicit current view is stored.
> AI is advised **not to create new AttributeView blocks**, since the table data is not in the `.sy` — it requires accompanying files.
### 5.15 Thematic break
```json
-{ "Type": "NodeThematicBreak", "ID": "...", "Properties": { "id": "..." } }
+{ "Type": "NodeThematicBreak", "ID": "...", "Properties": { "id": "...", "updated": "..." } }
```
+### 5.16 Custom block
+
+```json
+{ "Type": "NodeCustomBlock", "ID": "...", "Data": "raw custom content",
+ "CustomBlockInfo": "info", "Properties": { "id": "...", "updated": "..." } }
+```
+
+`NodeCustomBlock` is a leaf with no `Children`. `Data` stores its raw content and `CustomBlockInfo` stores the fence info string.
+
---
## 6. Inline nodes in detail
@@ -370,7 +426,7 @@ Notes:
{ "Type": "NodeText", "Data": "plain text" }
```
-`Data` **may be omitted** (common as a placeholder zero-width space: `{ "Type": "NodeText" }`).
+`Data` **may be omitted** because an empty string carries `omitempty`; `{ "Type": "NodeText" }` therefore represents empty text, not U+200B. An actual zero-width space must be present in `Data` (for example as the JSON escape `"\u200b"`).
### 6.2 `NodeTextMark` (the unified carrier for modern inline formatting)
@@ -421,7 +477,7 @@ A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be imme
> When generating styled inline text, these two nodes must appear as a pair, otherwise the kramdown round-trip will drop the style.
-### 6.4 `NodeImage` (seven-part structure)
+### 6.4 `NodeImage` (seven-part core; optional title adds two nodes)
```json
{ "Type": "NodeImage", "Data": "span", "Children": [
@@ -431,13 +487,28 @@ A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be imme
{ "Type": "NodeCloseBracket" },
{ "Type": "NodeOpenParen" },
{ "Type": "NodeLinkDest", "Data": "assets/image-2021.png" },
+ { "Type": "NodeLinkSpace" },
+ { "Type": "NodeLinkTitle", "Data": "Image title" },
{ "Type": "NodeCloseParen" }
] }
```
-- The image node itself has `Data` = `"span"`.
+- Editor-generated image nodes normally have `Data` = `"span"`; compatible compact data may omit an empty `Data`.
- `NodeBang`/`NodeOpenBracket`/`NodeCloseBracket`/`NodeOpenParen`/`NodeCloseParen` markers **may omit** `Data`.
-- Only `NodeLinkText` and `NodeLinkDest` carry `Data`.
+- `NodeLinkText` and `NodeLinkDest` carry the alt text and destination. When a title exists, insert `NodeLinkSpace` and `NodeLinkTitle` immediately before `NodeCloseParen`; the seven-node form without them is also valid.
+
+### 6.5 Line breaks and backslash escapes
+
+```json
+{ "Type": "NodeSoftBreak", "Data": "\n" }
+{ "Type": "NodeBr" }
+{ "Type": "NodeBackslash",
+ "Children": [ { "Type": "NodeBackslashContent", "Data": "|" } ] }
+```
+
+- `NodeSoftBreak` represents a soft line break.
+- `NodeBr` represents an explicit `<br>`.
+- `NodeBackslash` wraps the escaped character as inline content; it is not a `NodeTextMark` subtype.
---
@@ -449,21 +520,24 @@ A `NodeTextMark` carrying color/effects (with `Properties.style`) **must be imme
| `CodeBlockInfo` | base64 | `Z28=` = `go`, `amF2YQ==` = `java` |
| `CodeBlockOpenFence`/`CloseFence` | base64 | `YGBg` = ` ``` ` |
| `ListData.BulletChar`/`Delimiter` | **int ASCII codepoint** (**not** base64) | `42` = `*`, `46` = `.` |
+| `TaskListItemMarker` | **int ASCII codepoint** (**not** base64) | `32` = space, `88` = `X`, `33` = `!` |
| `Data` (paragraph text, code content, link, SQL, etc.) | **raw** (not encoded) | `"package main\n..."` |
-> Rule of thumb: **marker fields** like `Marker`/`Fence`/`Info` are base64; **content fields** like `Data`, `TextMarkTextContent`, `TextMarkInlineMathContent` are raw; `BulletChar`/`Delimiter` are int codepoints.
+> Rule of thumb: Go `[]byte` fields such as `Marker`/`Fence`/`Info` become base64 strings; Go `byte` fields such as `BulletChar`/`Delimiter`/`TaskListItemMarker` become JSON numbers; content strings such as `Data`, `TextMarkTextContent`, and `TextMarkInlineMathContent` remain raw strings.
---
-## 8. Properties (IAL) in full
+## 8. Properties (IAL)
A flat `map[string]string`.
-**Document-level (required):** `id`, `title`, `type` (always `"doc"`), `updated`. Optional: `icon` (emoji codepoint hex, e.g. `"1f4f0"`; custom-icon filename; or HTTP(S) image URL), `title-img` (document title image style as a CSS declaration string, e.g. `background-image:url("assets/example.jpg")`).
+**Document-level (required in canonical writes):** `id`, `title`, `type` (always `"doc"`), `updated`. Optional: `icon` (emoji codepoint hex, e.g. `"1f4f0"`; custom-icon filename; or HTTP(S) image URL), `title-img` (document title image style as a CSS declaration string, e.g. `background-image:url("assets/example.jpg")`).
-**Block-level (required):** `id` (= the node's `ID`), `updated`. Optional: `style` (inline CSS), `fold: "1"` (collapsed), `colgroup` (table column widths), arbitrary `custom-*` custom attributes.
+**Block-level (required in canonical writes):** `id` (= the node's `ID`), `updated`. Compatible historical data may lack `updated`, but new writers should provide it. Common optional attributes include `style`, `fold: "1"`, `name`, `alias`, `memo`, `bookmark`, table `colgroup` / `caption`, AttributeView `custom-sy-av-view`, and arbitrary `custom-*` attributes.
-> The authoritative key is **lowercase** `id`. Some legacy imported files also carry a leftover uppercase `ID` — prefer lowercase.
+**Inline-level (optional):** some inline or structural nodes also use `Properties`, including styled `NodeTextMark`, positioned or sized `NodeImage`, and merged/styled `NodeTableCell`. An inline `Properties` object does not make the node a block.
+
+> The authoritative canonical key is **lowercase** `id`. Some legacy imported files also carry a leftover uppercase `ID`; an explicit normalization pass may remove that compatibility artifact.
---
@@ -475,25 +549,26 @@ A flat `map[string]string`.
| `NodeListItem` | any non-`NodeListItem` block (paragraph/code block/sub-`NodeList`/super block…) | `NodeListItem` (nesting requires another `NodeList`) |
| `NodeBlockquote` | any non-`NodeListItem` block + one `NodeBlockquoteMarker` | `NodeListItem` |
| `NodeCallout` | any non-`NodeListItem` block | `NodeListItem` |
-| `NodeSuperBlock` | **any block** (incl. nested super blocks), wrapped by the three markers | none (most permissive) |
+| `NodeSuperBlock` | **any block** (incl. nested super blocks), inside its open/layout/close marker envelope | none (most permissive) |
| `NodeDocument` | any non-`NodeListItem` block | `NodeListItem` |
-> These rules are enforced by Lute's `CanContain` (`ast/node.go:988`). Violations cause parse/render anomalies — AI must obey them when generating.
+> These are canonical writer constraints derived from Lute's `CanContain`. The Markdown parser applies them while building a tree, but `dataparser.ParseJSON` is not a strict containment validator and does not reject every violation. Direct writers must validate these relationships themselves; invalid trees can cause parse or render anomalies.
---
-## 10. Zero-width space convention
+## 10. Zero-width space handling
-`.sy` files make heavy use of `​` (U+200B) as a separator placeholder. Around images, inline code, tags, kbd, etc., there is **usually a** `NodeText` with `Data` = `​` on **each side**, to keep rendering and caret behavior correct. AI should follow this convention when generating such content.
+Compatible AST data may contain `​` (U+200B) in `NodeText` for caret boundaries around inline elements. Preserve an existing U+200B when editing, but do not synthesize a `NodeText` containing U+200B on both sides of every image, inline code, tag, kbd, or similar node: Protyle injects these caret placeholders contextually while rendering the editor DOM. An omitted `Data` field represents an empty string, not U+200B.
---
-## 11. Markdown syntax disabled by SiYuan (must not appear in `.sy`)
+## 11. Types disabled for canonical writes (do not generate)
-SiYuan disables the following syntax via `SetXxx(false)` in `NewLute()` (`kernel/util/lute.go`). The corresponding node types **never** appear in `.sy` files — AI must not generate them:
+Canonical writers must not generate the following syntax or node families. Most are disabled via `SetXxx(false)` in `NewLute()` (`kernel/util/lute.go`), so the configured Markdown parser does not generate them. `NodeGitConflict` is the special case: `NewLute()` enables `SetGitConflict(true)` only so existing raw Git conflict markers can be recognized; that node family is still disabled for canonical `.sy` writes. A compatibility reader may encounter any of these types in historical or externally produced JSON.
-| Disabled item | Corresponding node types | Note |
+| Rule | Corresponding node types | Note |
|---|---|---|
+| Canonical-write prohibition; `SetGitConflict(true)` recognizes existing input | `NodeGitConflict`/`NodeGitConflictOpenMarker`/`NodeGitConflictContent`/`NodeGitConflictCloseMarker` | raw Git conflict marker block; never generate |
| `SetFootnotes(false)` | `NodeFootnotesDefBlock`/`NodeFootnotesDef`/`NodeFootnotesRef` | footnotes, fully disabled |
| `SetToC(false)` | `NodeToC` | `[toc]` table of contents |
| `SetIndentCodeBlock(false)` | indented code blocks | only fenced code blocks are supported |
@@ -509,24 +584,27 @@ SiYuan disables the following syntax via `SetXxx(false)` in `NewLute()` (`kernel
## 12. AI write checklist
-When generating a `.sy` that SiYuan can load cleanly, verify item by item:
+When generating or compatibly editing a `.sy` that SiYuan can load cleanly, verify item by item:
1. ☐ Root `Type` = `"NodeDocument"`, `Spec` = `"2"`; root `ID` = filename (without `.sy`) and equals `Properties.id`
2. ☐ Root `Properties` contains `id`/`title`/`type:"doc"`/`updated`
-3. ☐ Every block has a 22-char `ID`; `Properties.id` = `ID`; `Properties.updated` is a valid 14-digit timestamp
-4. ☐ Inline/marker nodes **do not carry** `ID`
-5. ☐ Lists are distinguished via `ListData.Typ` (omitted = unordered / `1` = ordered / `3` = task)
-6. ☐ `NodeList`'s direct children are **only** `NodeListItem`; nested lists wrap another `NodeList`
-7. ☐ `BulletChar`/`Delimiter` are byte (appear as int codepoints in JSON); `Marker` is base64
-8. ☐ Task markers usually carry no `Data` (checked items use `TaskListItemChecked:true`, unchecked only `Type`)
-9. ☐ Code block four parts, math block three parts, embed five parts, super block three parts — structure intact
-10. ☐ `NodeCodeBlockCode`/`NodeMathBlockContent` are inline children, usually only `Type`+`Data`
-11. ☐ base64 fields are encoded; content fields stay raw
-12. ☐ Prefer `NodeTextMark` for inline formatting over legacy `NodeStrong`/`NodeEmphasis`/`NodeLink`
-13. ☐ A styled `TextMark` must be followed by a paired `NodeKramdownSpanIAL`
-14. ☐ HTML/IFrame/Video/Audio/AttributeView are leaves with no `Children` (content in `Data` or type-specific fields)
-15. ☐ Do not fabricate `AttributeViewID`/`block-ref` target IDs (they must point to real blocks/AVs)
-16. ☐ Do not generate disabled types (footnotes/ToC/YAML/LinkRef/HeadingID, etc. — see §11)
+3. ☐ Every newly generated ID is fresh and workspace-wide unique; every canonical block has a 22-char `ID`, matching `Properties.id`, and a valid 14-digit `Properties.updated`
+4. ☐ Determine block status from `Type`, not from `ID`; do not add IDs to new inline/marker nodes, and only remove historical non-block IDs as field normalization without deleting the node
+5. ☐ Content or structure changes refresh `updated` on the changed block, its block ancestors, applicable preceding headings, and the document root
+6. ☐ Lists are distinguished via `ListData.Typ` (`0` or omitted = unordered / `1` = ordered / `3` = task), and both `NodeList` and each `NodeListItem` carry the appropriate `Typ`
+7. ☐ `NodeList` direct children are **only** `NodeListItem`; nested lists use another `NodeList` inside an item
+8. ☐ Go `byte` fields (`BulletChar`, `Delimiter`, `TaskListItemMarker`) are JSON numbers; Go `[]byte` fields (`Marker`, fences, info) are base64 strings
+9. ☐ A task marker records its original marker byte in `TaskListItemMarker` (`32` = space, `88` = `X`, other non-space bytes are checked); `TaskListItemChecked` is a compatibility fallback and `Data` is not authoritative
+10. ☐ Code blocks have four structural children, math blocks have three, query embeds have five, and super blocks have an open/layout/close envelope around at least one content block
+11. ☐ `NodeCodeBlockCode` and `NodeMathBlockContent` are inline structural children; historical IDs on them may be removed without removing the nodes
+12. ☐ Content strings stay raw; only `[]byte` fields are base64-encoded
+13. ☐ Prefer `NodeTextMark` for modern inline formatting over legacy `NodeStrong`/`NodeEmphasis`/`NodeLink`
+14. ☐ A styled `NodeTextMark` is followed by its paired `NodeKramdownSpanIAL`
+15. ☐ HTML/IFrame/Widget/Video/Audio/AttributeView/CustomBlock nodes are leaves with no `Children`; their content uses `Data` or type-specific fields
+16. ☐ Do not fabricate `AttributeViewID` or block-reference target IDs; they must point to real AVs or blocks
+17. ☐ Do not generate disabled types such as `NodeGitConflict`, footnotes, ToC, YAML, LinkRef, or HeadingID; tolerate them when compatibility-reading historical or external data
+18. ☐ Preserve existing U+200B text when editing, but do not blanket-synthesize zero-width-space nodes around inline elements
+19. ☐ Treat encrypted notebook files on disk as ciphertext, not JSON; mutate them only through the unlocked notebook APIs
---
@@ -535,23 +613,27 @@ When generating a `.sy` that SiYuan can load cleanly, verify item by item:
| ❌ Wrong | ✅ Correct |
|---|---|
| Assuming every node has `Data` | `Data` may be omitted; marker nodes often lack it |
-| Inline node carries `ID` | Inline/marker nodes have no `ID` |
+| Deciding that a node is a block because it has `ID`, or deleting the whole node as cleanup | `Type` determines block status; compatible editors may remove a historical non-block `ID` field without removing the node |
| Using legacy nodes like `NodeStrong`/`NodeLink` | Use `NodeTextMark` + `TextMarkType` |
-| `ListData.Typ` only accepts `1` | omitted = unordered, `1` = ordered, `3` = task |
+| `ListData.Typ` only accepts `1` | `0` or omitted = unordered, `1` = ordered, `3` = task |
| Treating `BulletChar` as base64 | It's `byte`, appearing as an int codepoint in JSON (`42` = `*`) |
-| Forcing `"Data":"[X]"` into a task marker | Real `.sy` usually has no `Data`; checked items only carry `TaskListItemChecked:true` |
+| Using `"Data":"[X]"` as the authoritative task state | Preserve the marker byte in numeric `TaskListItemMarker`; `TaskListItemChecked` is a compatibility fallback |
| Styled `TextMark` without the IAL | Must pair with `NodeKramdownSpanIAL` |
-| Adding `Children` to `NodeAttributeView` | It's a leaf — use `AttributeViewID`/`AttributeViewType` |
+| Adding `Children` to AttributeView, Widget, or CustomBlock nodes | They are leaves — use `Data` or their type-specific fields |
| Changing `ID` without syncing `Properties.id` | The two must match |
+| Updating only the directly edited block's timestamp | Also refresh its block ancestors, applicable preceding headings, and the document root |
| `inline-math` carrying `TextMarkTextContent` | It only has `TextMarkInlineMathContent` |
| Fabricating block-ref / AV target IDs | Targets must really exist |
| Hanging a paragraph directly under `NodeList` | `NodeList` can only contain `NodeListItem` — wrap first |
-| Generating footnotes/ToC/YAML, etc. | SiYuan disables these; they never appear in `.sy` |
+| Adding U+200B text nodes on both sides of every inline element | Preserve existing U+200B; let Protyle add editor-DOM caret placeholders contextually |
+| Generating `NodeGitConflict`, footnotes, ToC, YAML, etc. | They are disabled for canonical writes; compatibility readers may still encounter historical or external nodes |
---
## 14. Minimal writable document template
+> ⚠️ All IDs and timestamps below are illustrative. Generate fresh workspace-wide unique IDs and current timestamps; never copy these literal values into a real `.sy` file.
+
```json
{
"ID": "20260628120000-abc1234",
@@ -586,9 +668,11 @@ When generating a `.sy` that SiYuan can load cleanly, verify item by item:
## Appendix: verification sources
-- Sample 1: `app/guide/.../20200825162036-4dx365o.sy` (formatting elements — covers nearly all block types)
-- Sample 2: `app/guide/.../20200905090211-2vixtlf.sy` (block types — incl. compact lists, AttributeView)
-- Node-type constants and serialization logic: `lute/ast/node.go`, `lute/render/json_renderer.go`, `dataparser/sy.go`
-- List containment check: `lute/ast/node.go:988` (`CanContain`)
-- Disabled-syntax config: `kernel/util/lute.go:51` (`NewLute`)
-- Fields marked `【inferred】` (e.g. the sub-fields of `file-annotation-ref`) should be re-verified against a real sample before generation.
+- Sample 1: `app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy` (formatting elements — covers nearly all block types)
+- Sample 2: `app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy` (block types — incl. compact lists and AttributeView)
+- The samples contain historical artifacts produced by earlier bugs. Treat them as compatibility fixtures; a normalization pass may remove legacy non-block IDs, while canonical new writes follow current node semantics.
+- Node-type constants and task/list fields: `lute/ast/node.go`
+- Serialization and compatibility parsing: `lute/render/json_renderer.go`, `dataparser/sy.go`
+- Containment rules: Lute `ast.Node.CanContain`
+- Canonical-write exclusions and syntax configuration: `kernel/util/lute.go` (`NewLute`), including Git-conflict input recognition
+- Lute dependency version: `kernel/go.mod`
diff --git a/docs/SY-FORMAT.zh-CN.md b/docs/SY-FORMAT.zh-CN.md
index 4582eb4688..a0dd30c4ad 100644
--- a/docs/SY-FORMAT.zh-CN.md
+++ b/docs/SY-FORMAT.zh-CN.md
@@ -1,19 +1,32 @@
# SiYuan `.sy` 文件 JSON 结构规范 —— AI 读写指南
-> 版本基准:Spec `2`(当前所有文件)。
+> 规范写入基准:Spec `2`(当前写入器的输出;兼容读取器可能遇到旧版或缺少 `Spec` 的数据,并将其升级)。
> 核验样本:`20200825162036-4dx365o.sy`(排版元素)、`20200905090211-2vixtlf.sy`(内容块类型)。
-> 本文档所有结论均基于真实样本与 Lute / 思源内核代码核验;标注 `【推断】` 的字段表示未在样本中直接出现,建议生成前再用真实样本核验。
+> 本文档所有结论均基于真实样本及当前 Lute / 思源内核源码核验。上述样本包含少量已知的历史遗留数据;样本与当前源码不一致时,规范写入规则以当前源码为准。
+> 本指南描述普通笔记本中的明文 `.sy` JSON,或已解锁加密笔记本的解密后 AST。加密笔记本磁盘上的 `.sy` 文件是密文,不能当作 JSON 直接编辑。
> 配套文档:[`WORKSPACE.zh-CN.md`](./WORKSPACE.zh-CN.md) 讲工作区在磁盘上的整体布局(笔记本、父子文档、资源文件的组织方式);本文档专注 `.sy` 文件**内部**的 JSON 结构。
## 0. 一句话本质
-`.sy` = 一个 Lute AST 树序列化成的 JSON。根节点恒为 `NodeDocument`,正文是其 `Children` 数组递归嵌套的节点树。没有外部 schema,全部状态在树里。
+明文 `.sy` 文件是序列化为 JSON 的 Lute AST 树。根节点为 `NodeDocument`,正文是递归嵌套的 `Children` 数组。不存在单独维护的 JSON Schema;Lute 的 `ast.Node` 和 `ListData` Go 结构体是序列化格式的事实来源。树中保存文档 AST 及其 IAL,资源文件、属性视图定义和可重建索引则位于树外。
+
+## 0.1 规范写入与兼容读取
+
+本指南区分新写入器应生成的格式,以及内核可以容忍并规范化的历史数据:
+
+| 术语 | 含义 |
+|---|---|
+| **必需** | 新生成的规范 Spec 2 数据中必须存在 |
+| **可选** | 字段为空或带有 `omitempty` 时可以省略 |
+| **兼容输入** | 读取器可按明确兼容规则接收并保留、修复或升级的历史或外部数据 |
+
+除非某节另有说明,本文的“必需”均指新数据的规范写入要求。`dataparser.ParseJSON` 是兼容读取器,而不是严格的 Schema 校验器;例如,它可以补入缺失的空段落、为缺少 ID 的块分配 ID,并升级旧版 `Spec`。
---
## 0.5 何时直接读写 `.sy`(优先级)
-思源提供了 **HTTP API、MCP、CLI** 三条官方路径来修改数据。**默认应优先使用它们**,因为内核会负责 AST 序列化、块 ID 分配,以及两套索引的同步——块树索引(`blocktree.db`,块 ID → 文件路径映射,块引用/面包屑依赖它)和全文搜索索引(`siyuan.db` + FTS5)。直接改盘绕过了这些逻辑,容易导致索引不一致。
+思源提供了 **HTTP API、MCP、CLI** 三条官方路径来修改数据。**默认应优先使用它们**,因为内核会负责 AST 序列化、块 ID 分配,以及两套索引的同步——块树索引(`blocktree.db`,块 ID 到文件路径的映射,块引用和面包屑依赖它)和全文搜索索引(`siyuan.db` + FTS5)。直接改盘绕过了这些逻辑,容易导致索引不一致。
**仅当官方路径不便时,才直接以 JSON 读写 `.sy`**。适用场景:
- 批量离线迁移(冷初始化工作区、外部数据导入;工作区的磁盘布局见 [`WORKSPACE.zh-CN.md`](./WORKSPACE.zh-CN.md))
@@ -30,7 +43,8 @@
| **CLI** | 批处理 / 运维 | 导入、导出、同步、SQL 等命令行任务 |
| **直接读写 `.sy`** | 本规范覆盖范围 | 离线、批量、底层结构操作 |
-> ⚠️ 直接改盘后,通常需要触发一次「重建索引」才能让搜索/块引用生效。若思源正在运行,更稳妥的是走 HTTP API,由内核负责序列化与索引同步。
+> ⚠️ 直接改盘后,通常需要触发一次“重建索引”才能让搜索和块引用生效。若思源正在运行,应优先使用 HTTP API,由内核负责序列化与索引同步。
+> ⚠️ 不要直接修改加密笔记本的持久化文件。请在解锁笔记本后使用专用 API,以保持加密、认证和隔离索引的一致性。
---
@@ -54,13 +68,14 @@
| 顶层键 | 必有 | 说明 |
|---|---|---|
-| `ID` | ✅ | 文档块 ID,**等于文件名去掉 `.sy`**(不是随机生成) |
-| `Spec` | ✅ | 恒 `"2"` |
-| `Type` | ✅ | 恒 `"NodeDocument"` |
-| `Properties` | ✅ | 文档级 IAL,见 §8 |
-| `Children` | ✅ | 正文子块数组,至少含一个块 |
+| `ID` | ✅ | 文档块 ID,**等于去掉 `.sy` 后的文件名** |
+| `Spec` | ✅ | 当前规范文件为 `"2"`;旧值或缺失值属于兼容输入,可以升级 |
+| `Type` | ✅ | `"NodeDocument"` |
+| `Properties` | ✅ | 文档级 IAL,见 §8 |
+| `Children` | ✅ | 正文子块数组;规范文件至少包含一个块 |
> ⚠️ 文件路径与根 ID 严格对应:`data/<box>/<...>/<根ID>.sy`。改根 ID 等于改文件名,AI 不要随意改根 ID。文件系统的完整布局见 [`WORKSPACE.zh-CN.md`](./WORKSPACE.zh-CN.md)。
+> 兼容读取器会在 `Children` 缺失或为空时插入空段落,但新写入器应自行写出该段落。
---
@@ -69,43 +84,48 @@
| 字段 | 类型 | 出现条件 | 语义 |
|---|---|---|---|
| `Type` | string | **所有节点必有** | 类型判别字段,如 `"NodeParagraph"` |
-| `ID` | string | 仅 block 节点 | 22 字符块 ID;内联/标记节点**不带** |
+| `ID` | string | 规范块节点必需;兼容输入的非块节点也可能存在 | 块使用的 22 字符 ID;规范写入器不为内联或标记节点新增该字段 |
| `Data` | string | 部分 | 文本/HTML/markdown 原文;**可省略**(不能假设必有) |
-| `Properties` | object | 多数 block | IAL,`map[string]string` |
-| `Children` | array | 容器/可嵌套节点 | 子节点数组 |
+| `Properties` | object | 块及部分内联节点 | IAL,`map[string]string`;内联用途包括带样式文本、图片和表格单元格 |
+| `Children` | array | 容器和结构复合节点 | 子节点数组 |
| 类型专属字段 | - | 按类型 | 如 `HeadingLevel`、`ListData`、`TextMarkType`、`AttributeViewID` |
-**核心判别规则**:是否有 `ID` 决定是否是 block。有 `ID` ⇒ block(其 `Properties.id` 必须等于 `ID`);无 `ID` ⇒ 内联/标记节点。
+**核心判别规则**:`Type` 决定节点是否为块,`ast.Node.IsBlock()` 是权威判断;不能根据是否存在 `ID` 判断。规范 Spec 2 数据中的每个块都有 `ID` 及与之匹配的 `Properties.id`,新建的内联或标记节点则没有这些字段。旧版缺陷生成的历史文件可能在 `NodeCodeBlockCode`、`NodeMathBlockContent` 等非块节点上带有 ID。兼容读取器和编辑器可在规范化过程中清理这些遗留的 `ID` / `Properties.id` 字段,但必须按 `Type` 判断节点类型,不能仅因 `ID` 不符合规范而删除节点本身。
---
## 3. ID 与时间戳规则
-- **ID 格式**:`YYYYMMDDHHMMSS-xxxxxxx` = 14 位时间戳 + `-` + 7 位随机 `[a-z0-9]`。例:`20210104091228-ttcj9nm`。
-- **根 ID** 来自文件名,**不**重新生成。
-- **子块 ID** 用上述算法生成。
-- `Properties.updated` 用 14 位时间戳,语义「最后更新时间」。
-- 改任何 block 的 `ID`,必须**同步** `Properties.id`。`Properties.updated` 建议同步刷新为当前时间。
+- **ID 格式**:`YYYYMMDDHHMMSS-xxxxxxx` = 14 位时间戳 + `-` + 7 位随机 `[a-z0-9]`。例:`20210104091228-ttcj9nm`。
+- **唯一性**:每个新生成的文档和块 ID 必须在整个工作区中保持唯一,而不只是在单个文件中唯一。
+- **根 ID** 来自文件名,**不**重新生成。
+- **子块 ID** 按上述格式重新生成;绝不能复制示例或模板中的字面 ID。
+- `Properties.updated` 使用同样的 14 位时间戳,语义为“最后更新时间”。
+- 修改块内容或结构时,应刷新被修改块、其块级祖先、适用的前置标题以及文档根节点的 `Properties.updated`。
+- 修改任何块的 `ID` 时,必须**同步** `Properties.id`。其 `Properties.updated` 不得早于新 ID 中编码的创建时间。
+- 兼容的历史输入可能缺少 `updated`;规范写入的新数据应为所有块节点提供该字段。
---
## 4. 节点类型目录
-### Block 节点(有 ID)
+### 块节点(规范数据中有 ID)
-**叶子 block**:`NodeParagraph`、`NodeHeading`、`NodeThematicBreak`、`NodeHTMLBlock`、`NodeCodeBlock`、`NodeMathBlock`、`NodeTable`、`NodeBlockQueryEmbed`、`NodeAttributeView`、`NodeIFrame`、`NodeVideo`、`NodeAudio`、`NodeWidget`、`NodeCustomBlock`、`NodeGitConflict`
+**叶子块**:`NodeParagraph`、`NodeHeading`、`NodeThematicBreak`、`NodeHTMLBlock`、`NodeCodeBlock`、`NodeMathBlock`、`NodeTable`、`NodeBlockQueryEmbed`、`NodeAttributeView`、`NodeIFrame`、`NodeVideo`、`NodeAudio`、`NodeWidget`、`NodeCustomBlock`
-**容器 block**:`NodeList`、`NodeListItem`、`NodeBlockquote`、`NodeCallout`、`NodeSuperBlock`
+**容器块**:`NodeList`、`NodeListItem`、`NodeBlockquote`、`NodeCallout`、`NodeSuperBlock`
-### 内联/标记节点(无 ID)
+### 内联或标记节点(规范数据中无 ID)
-`NodeText`、`NodeTextMark`、`NodeImage`、`NodeKramdownSpanIAL`、`NodeHeadingC8hMarker`、`NodeBlockquoteMarker`、`NodeTaskListItemMarker`、`NodeBang`、`NodeOpenBracket`、`NodeCloseBracket`、`NodeOpenParen`、`NodeCloseParen`、`NodeLinkText`、`NodeLinkDest`、`NodeCodeBlockCode`、`NodeCodeBlockFenceOpenMarker`、`NodeCodeBlockFenceInfoMarker`、`NodeCodeBlockFenceCloseMarker`、`NodeMathBlockContent`、`NodeMathBlockOpenMarker`、`NodeMathBlockCloseMarker`、`NodeSuperBlockOpenMarker`、`NodeSuperBlockLayoutMarker`、`NodeSuperBlockCloseMarker`、`NodeOpenBrace`、`NodeCloseBrace`、`NodeBlockQueryEmbedScript`、`NodeTableHead`、`NodeTableRow`、`NodeTableCell`
+`NodeText`、`NodeTextMark`、`NodeImage`、`NodeKramdownSpanIAL`、`NodeSoftBreak`、`NodeBr`、`NodeBackslash`、`NodeBackslashContent`、`NodeHeadingC8hMarker`、`NodeBlockquoteMarker`、`NodeTaskListItemMarker`、`NodeBang`、`NodeOpenBracket`、`NodeCloseBracket`、`NodeOpenParen`、`NodeCloseParen`、`NodeLinkText`、`NodeLinkDest`、`NodeLinkSpace`、`NodeLinkTitle`、`NodeCodeBlockCode`、`NodeCodeBlockFenceOpenMarker`、`NodeCodeBlockFenceInfoMarker`、`NodeCodeBlockFenceCloseMarker`、`NodeMathBlockContent`、`NodeMathBlockOpenMarker`、`NodeMathBlockCloseMarker`、`NodeSuperBlockOpenMarker`、`NodeSuperBlockLayoutMarker`、`NodeSuperBlockCloseMarker`、`NodeOpenBrace`、`NodeCloseBrace`、`NodeBlockQueryEmbedScript`、`NodeTableHead`、`NodeTableRow`、`NodeTableCell`
-> 思源禁用的类型(脚注 / ToC / YAML / LinkRef / HeadingID 等)见 §11,不应出现在 `.sy` 中,故未列入目录。
+> “叶子块”表示该节点不能包含其他**块节点**;它仍可拥有结构性内联子节点,例如代码块、数学块和表格。
+> 上述“规范数据中无 ID”是规范写入规则。显式规范化过程可以清理兼容历史非块节点已有的 `ID`,但不能用该字段判断节点是否为块,也不能据此删除节点本身。
+> 规范写入禁用的类型,包括解析器禁用的语法及仅用于检测的 `NodeGitConflict` 节点族,列于 §11,因此未纳入此目录。
---
-## 5. 各 Block 类型详解 + 可复制样例
+## 5. 各块类型详解与可复制示例
### 5.1 段落
@@ -123,12 +143,12 @@
```
- `HeadingLevel` 取值 `1`–`6`。
-- `NodeHeadingC8hMarker`(`Data` 如 `"## "`)**可选**,有无都合法。建议生成时**省略**它,更简洁。
-- SiYuan 建议**正文顶层用二级标题**,不要用一级。
+- `NodeHeadingC8hMarker`(`Data` 如 `"## "`)**可选**,有无都合法。建议生成时**省略**它,更简洁。
+- 思源建议**正文顶层用二级标题**,不要用一级。
### 5.3 列表(关键:用 `ListData.Typ` 区分类型)
-> **★ 列表的硬性结构约束**:`NodeList` 的直接子节点**只能**是 `NodeListItem`(Lute 在 `CanContain` 中强制校验,`ast/node.go:993` `return NodeListItem == nodeType`)。段落、代码块、子列表等任何其他块都**不能**直接挂在 `NodeList` 下,必须先包一层 `NodeListItem`。
+> **★ 列表的规范结构约束**:`NodeList` 的直接子节点**只能**是 `NodeListItem`,即 `CanContain` 返回 `NodeListItem == nodeType`。段落、代码块、子列表等任何其他块都**不能**直接挂在 `NodeList` 下,必须先包一层 `NodeListItem`。`dataparser.ParseJSON` 不会将其作为严格校验步骤,因此直接写入器必须自行验证结构。
```
✅ 正确 ❌ 错误
@@ -137,7 +157,7 @@ NodeList NodeList
└─ NodeParagraph └─ NodeCodeBlock ← 非法
```
-**嵌套列表**的正确写法是再套一层 `NodeList`(`NodeListItem` 走默认 `CanContain` 分支,不能直接含另一个 `NodeListItem`):
+**嵌套列表**的正确写法是再套一层 `NodeList`(`NodeListItem` 走默认 `CanContain` 分支,不能直接含另一个 `NodeListItem`):
```
✅ 正确 ❌ 错误
@@ -149,40 +169,52 @@ NodeList NodeList
└─ NodeParagraph
```
-**无序列表**(`Typ` 缺省):
+**无序列表**(省略 `Typ`):
```json
{ "Type": "NodeList", "ID": "...", "ListData": {},
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeListItem", "ID": "...",
"ListData": { "BulletChar": 42, "Marker": "Kg==" },
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "列表项一" } ] }
] }
] }
```
-**有序列表**(`Typ: 1`):
+**有序列表**(`Typ: 1`):
```json
-{ "Type": "NodeListItem", "ID": "...", "Data": "1",
- "ListData": { "Typ": 1, "Tight": true, "Start": 1, "Delimiter": 46, "Padding": 3, "Marker": "MQ==", "Num": 1 },
- "Properties": { "id": "..." }, "Children": [ ... ] }
+{ "Type": "NodeList", "ID": "...", "ListData": { "Typ": 1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeListItem", "ID": "...",
+ "ListData": { "Typ": 1, "Tight": true, "Start": 1, "Delimiter": 46, "Padding": 3, "Marker": "MS4=", "Num": 1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
+ "Children": [ { "Type": "NodeText", "Data": "列表项一" } ] }
+ ] }
+ ] }
```
-**任务列表**(`Typ: 3`),子节点首项是 `NodeTaskListItemMarker`:
+**任务列表**(`Typ: 3`);每个 `NodeListItem` 都以 `NodeTaskListItemMarker` 开头:
```json
-{ "Type": "NodeListItem", "ID": "...",
- "ListData": { "Typ": 3, "Tight": true, "BulletChar": 45, "Padding": 2, "Checked": true, "Marker": "LQ==", "Num": -1 },
- "Properties": { "id": "..." },
+{ "Type": "NodeList", "ID": "...", "ListData": { "Typ": 3 },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
- { "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true },
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
- "Children": [ { "Type": "NodeText", "Data": "待办一" } ] }
+ { "Type": "NodeListItem", "ID": "...",
+ "ListData": { "Typ": 3, "Tight": true, "BulletChar": 45, "Padding": 2, "Marker": "LQ==", "Num": -1 },
+ "Properties": { "id": "...", "updated": "..." },
+ "Children": [
+ { "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 88 },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
+ "Children": [ { "Type": "NodeText", "Data": "待办一" } ] }
+ ] }
] }
```
@@ -190,36 +222,48 @@ NodeList NodeList
| 字段 | 类型(代码) | JSON 表现 | 说明 |
|---|---|---|---|
-| `Typ` | int | 数字 | **列表类型判别**:缺省=无序,`1`=有序,`3`=任务 |
+| `Typ` | int | 数字 | **列表类型判别**:省略表示无序,`1` 表示有序,`3` 表示任务 |
| `Tight` | bool | 布尔 | 紧凑态(无空行);可选 |
| `BulletChar` | byte | 数字 | 无序/任务列表的项目符号 **ASCII 码点**(`42`=`*`,`45`=`-`) |
| `Delimiter` | byte | 数字 | 有序列表分隔符 ASCII 码点(`46`=`.`) |
| `Start` | int | 数字 | 有序列表起始编号 |
| `Num` | int | 数字 | 该项序号;无序/任务列表通常缺省或为 `-1` |
| `Padding` | int | 数字 | 缩进填充数;可选 |
-| `Checked` | bool | 布尔 | 任务列表项是否勾选(列表级聚合) |
+| `MarkerOffset` | int | 数字 | 标记符缩进偏移;可选 |
+| `Checked` | bool | 布尔 | 解析任务标记时派生的兼容元数据;不是整个列表的聚合值,可以省略 |
| `Marker` | []byte | **base64 字符串** | 标记符原文的 **base64**;可能含分隔符(`"MS4="`=`1.`)也可能不含(`"MQ=="`=`1`) |
-> 关键区分:**`BulletChar`/`Delimiter` 在代码里是 `byte`,JSON 中表现为数字 ASCII 码点**;**`Marker` 在代码里是 `[]byte`,JSON 中表现为 base64 字符串**。`Marker`/`BulletChar`/`Delimiter` 都带 `omitempty`,可缺省。
+> 关键区别:`BulletChar` / `Delimiter` 在代码中是 `byte`,在 JSON 中表现为 ASCII 码点数字;`Marker` 在代码中是 `[]byte`,在 JSON 中表现为 base64 字符串。`Marker` / `BulletChar` / `Delimiter` 都带 `omitempty`,可以省略。
### 5.5 任务标记
+使用 `X` 勾选:
+
+```json
+{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 88 }
+```
+
+使用空格表示未勾选:
+
+```json
+{ "Type": "NodeTaskListItemMarker", "TaskListItemMarker": 32 }
+```
+
+`!` 等任意非空格标记也表示已勾选,并保留其原始字节:
+
```json
-// 已勾选
-{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true }
-// 未勾选
-{ "Type": "NodeTaskListItemMarker" }
+{ "Type": "NodeTaskListItemMarker", "TaskListItemChecked": true, "TaskListItemMarker": 33 }
```
-> 真实 `.sy` 里 `NodeTaskListItemMarker` **通常没有 `Data` 字段**(思源走 DOM `data-task` 属性重建标记,不保留 `[X]`/`[ ]` 原文),勾选时仅有 `Type`+`TaskListItemChecked`,未勾选仅有 `Type`。规范上若手动写入 `Data`,勾选态应为大写 `[X]`(非 `[x]`),仅用于导出 Markdown 时的归一化输出。
+`TaskListItemMarker` 是 Go `byte`,因此 JSON 使用数字保存其 ASCII 码点。当前渲染优先读取该字段,并在兼容旧数据时回退到 `TaskListItemChecked`。AST 直接由 Markdown 解析而来时,`Data` 可能存在,例如 `"[X]"`;编辑器生成的 `.sy` 数据通常省略它,不能将 `Data` 当作任务状态的权威来源。
### 5.6 引述块
```json
-{ "Type": "NodeBlockquote", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeBlockquote", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeBlockquoteMarker", "Data": "> " },
- { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "引述内容" } ] }
] }
```
@@ -232,7 +276,7 @@ NodeList NodeList
{ "Type": "NodeCallout", "ID": "...",
"CalloutType": "NOTE", "CalloutTitle": "Note", "CalloutIcon": "✏️",
"Properties": { "id": "...", "updated": "..." },
- "Children": [ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "..." },
+ "Children": [ { "Type": "NodeParagraph", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [ { "Type": "NodeText", "Data": "提示内容" } ] } ] }
```
@@ -244,26 +288,26 @@ NodeList NodeList
| `WARNING` | `Warning` | `⚠️` |
| `CAUTION` | `Caution` | `🚨` |
-> `CalloutIcon` 是**直接 emoji 字符**,不是 base64、不是码点。
+上表列出五种内置类型及其默认值,同时也支持自定义 `CalloutType`、标题和图标。`CalloutIconType: 0` 表示 `CalloutIcon` 是直接的 emoji 字符;这是默认值,会因 `omitempty` 省略。`CalloutIconType: 1` 表示 `CalloutIcon` 是自定义图标路径。
-### 5.8 超级块(可嵌套,三段结构)
+### 5.8 超级块(可嵌套,三标记包络)
```json
-{ "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeSuperBlockOpenMarker" },
{ "Type": "NodeSuperBlockLayoutMarker", "Data": "col" },
- { "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "..." }, "Children": [ ... 内嵌超级块,Data 为 "row" ... ] },
+ { "Type": "NodeSuperBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." }, "Children": [ ... 内嵌超级块,Data 为 "row" ... ] },
{ "Type": "NodeSuperBlockCloseMarker" }
] }
```
-> `NodeSuperBlockLayoutMarker.Data` 只能是 `"row"`(横向)或 `"col"`(纵向)。超级块可嵌套,且是唯一能容纳任意块(含嵌套自身)的容器。
+> `NodeSuperBlockLayoutMarker.Data` 只能是 `"row"`(横向)或 `"col"`(纵向)。规范超级块包含开始标记、布局标记、至少一个内容块和结束标记,因此至少有四个子节点。它可以包含多个内容块并可嵌套,也是唯一能容纳任意块(包括自身)的容器。
### 5.9 嵌入块(五段结构 `{{ ... }}`)
```json
-{ "Type": "NodeBlockQueryEmbed", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeBlockQueryEmbed", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeOpenBrace" },
{ "Type": "NodeOpenBrace" },
@@ -279,7 +323,7 @@ NodeList NodeList
{ "Type": "NodeCodeBlock", "ID": "...", "IsFencedCodeBlock": true,
"CodeBlockFenceChar": 96, "CodeBlockFenceLen": 3,
"CodeBlockOpenFence": "YGBg", "CodeBlockInfo": "Z28=", "CodeBlockCloseFence": "YGBg",
- "Properties": { "id": "..." },
+ "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeCodeBlockFenceOpenMarker", "Data": "```", "CodeBlockFenceLen": 3 },
{ "Type": "NodeCodeBlockFenceInfoMarker", "CodeBlockInfo": "Z28=" },
@@ -289,15 +333,16 @@ NodeList NodeList
```
要点:
+
- `NodeCodeBlockCode` 承载代码内容(放 `Data`,原始文本,`\n` 转义),是 `NodeCodeBlock` 的内联子节点。
- 外围 fence marker(Open/Info/Close)同样是内联子节点。
-- `CodeBlockInfo` 是**语言名的 base64**(`"Z28="`=`go`)。父节点上的 7 个字段(`IsFencedCodeBlock`/`CodeBlockFenceChar`/`CodeBlockFenceLen`/`CodeBlockOpenFence`/`CodeBlockInfo`/`CodeBlockCloseFence`)全部带 `omitempty`,可按需省略——新版 `.sy` 常仅写 `"IsFencedCodeBlock": true`。
-- 思源**不支持缩进式代码块**(`SetIndentCodeBlock(false)`),所有代码块都是围栏式。
+- `CodeBlockInfo` 是**语言名的 base64**(`"Z28="` = `go`)。父节点上的六个字段(`IsFencedCodeBlock` / `CodeBlockFenceChar` / `CodeBlockFenceLen` / `CodeBlockOpenFence` / `CodeBlockInfo` / `CodeBlockCloseFence`)均带 `omitempty`,可按需省略;较新的 `.sy` 文件通常只写 `"IsFencedCodeBlock": true`。
+- 当前思源 Markdown 配置禁用缩进式代码块(`SetIndentCodeBlock(false)`);规范新代码块采用围栏式结构。
### 5.11 数学块(三段结构)
```json
-{ "Type": "NodeMathBlock", "ID": "...", "Properties": { "id": "..." },
+{ "Type": "NodeMathBlock", "ID": "...", "Properties": { "id": "...", "updated": "..." },
"Children": [
{ "Type": "NodeMathBlockOpenMarker" },
{ "Type": "NodeMathBlockContent", "Data": "a^2 + b^2 = c^2" },
@@ -305,22 +350,23 @@ NodeList NodeList
] }
```
-### 5.12 HTML / IFrame / Video / Audio 块(叶子,内容在顶层 `Data`)
+### 5.12 HTML / IFrame / Widget / Video / Audio 块(叶子,内容在顶层 `Data`)
```json
-{ "Type": "NodeHTMLBlock", "ID": "...", "Data": "<div>\n<ruby>你<rt>nǐ</rt>...</div>", "Properties": { "id": "..." } }
-{ "Type": "NodeIFrame", "ID": "...", "Data": "<iframe src=\"...\"></iframe>", "Properties": { "id": "..." } }
-{ "Type": "NodeVideo", "ID": "...", "Data": "<video controls src=\"assets/x.mp4\"></video>", "Properties": { "id": "..." } }
-{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "..." } }
+{ "Type": "NodeHTMLBlock", "ID": "...", "Data": "<div>\n<ruby>你<rt>nǐ</rt>...</div>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeIFrame", "ID": "...", "Data": "<iframe src=\"...\"></iframe>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeWidget", "ID": "...", "Data": "<iframe src=\"/widgets/example\" data-subtype=\"widget\"></iframe>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeVideo", "ID": "...", "Data": "<video controls src=\"assets/x.mp4\"></video>", "Properties": { "id": "...", "updated": "..." } }
+{ "Type": "NodeAudio", "ID": "...", "Data": "<audio controls src=\"assets/x.wav\"></audio>", "Properties": { "id": "...", "updated": "..." } }
```
-> 这四种**没有 Children**,HTML 内容(JSON 转义后)直接放顶层 `Data`。
+> 这五种节点**没有 `Children`**;HTML 内容经 JSON 转义后直接放在顶层 `Data` 中。
### 5.13 表格
```json
{ "Type": "NodeTable", "ID": "...", "TableAligns": [0, 0, 0],
- "Properties": { "id": "...", "colgroup": "||" },
+ "Properties": { "id": "...", "updated": "...", "colgroup": "||" },
"Children": [
{ "Type": "NodeTableHead", "Data": "thead", "Children": [
{ "Type": "NodeTableRow", "Data": "tr", "Children": [
@@ -334,11 +380,13 @@ NodeList NodeList
```
- 嵌套层级固定:`NodeTable > NodeTableHead/NodeTableRow > NodeTableCell > 内联`。
-- `TableAligns`:每列对齐值的 int 数组,`0`=默认/左。
+- `TableAligns`:每列对齐方式组成的 int 数组,`0` 表示默认,`1` 表示左对齐,`2` 表示居中,`3` 表示右对齐。
- `Data`(`thead`/`tr`/`th`/`td`)在紧凑文件里**可省略**。
-- 列宽用 `Properties.colgroup`(`|` 分隔)记录。
+- `Properties.colgroup` 使用 `|` 分隔各列的 CSS 样式字符串;空段表示该列没有显式样式。
+- 表格可选的 `Properties.caption` 保存标题 HTML。
+- `NodeTableCell` 可使用 `Properties.colspan`、`Properties.rowspan` 和 `Properties.style` 保存合并单元格及单元格样式状态。
-### 5.14 数据库块(AttributeView,叶子)
+### 5.14 数据库块(AttributeView,叶子)
```json
{ "Type": "NodeAttributeView", "ID": "...",
@@ -348,18 +396,27 @@ NodeList NodeList
```
- **没有 Children**。
-- `AttributeViewID` 指向 AV 表数据(存在单独的 `.json`,**不要**由 AI 凭空构造 ID)。
+- `AttributeViewID` 指向 AV 表数据,该数据存放在单独的 `.json` 中;**不要**凭空构造此 ID。
- `AttributeViewType`:`table` / `kanban` / `gallery` 等。
-- `custom-sy-av-view` 记录当前视图 ID。
+- 可选的 `custom-sy-av-view` 记录当前视图 ID;没有显式保存当前视图时可以缺失。
-> 建议 AI **不要创建新的 AttributeView 块**,因为表数据不在 `.sy` 里,需配套文件。
+> 建议 AI **不要创建新的 AttributeView 块**,因为表数据不在 `.sy` 中,还需要配套文件。
### 5.15 分隔线
```json
-{ "Type": "NodeThematicBreak", "ID": "...", "Properties": { "id": "..." } }
+{ "Type": "NodeThematicBreak", "ID": "...", "Properties": { "id": "...", "updated": "..." } }
+```
+
+### 5.16 自定义块
+
+```json
+{ "Type": "NodeCustomBlock", "ID": "...", "Data": "自定义原始内容",
+ "CustomBlockInfo": "info", "Properties": { "id": "...", "updated": "..." } }
```
+`NodeCustomBlock` 是没有 `Children` 的叶子节点。`Data` 保存原始内容,`CustomBlockInfo` 保存围栏信息字符串。
+
---
## 6. 内联节点详解
@@ -370,7 +427,7 @@ NodeList NodeList
{ "Type": "NodeText", "Data": "普通文本" }
```
-`Data` **可省略**(用作占位零宽空格时常见 `{ "Type": "NodeText" }`)。
+`Data` 为空字符串时会因 `omitempty` **省略**;因此 `{ "Type": "NodeText" }` 表示空文本,而不是 U+200B。实际零宽空格必须明确写入 `Data`,例如使用 JSON 转义 `"\u200b"`。
### 6.2 `NodeTextMark`(现代内联格式的统一载体)
@@ -406,7 +463,7 @@ NodeList NodeList
- `TextMarkBlockRefSubtype`:`"s"`=静态锚文本,`"d"`=动态锚文本(锚文本跟随目标块内容变化;注意「嵌入块」是另一种节点 `NodeBlockQueryEmbed`,与此无关)。
- `TextMarkType` 可空格叠加多标记,如 `"strong em"`。
- `TextMarkTextContent` 不是所有类型都有(`inline-math` 就没有)。
-- 删除线**仅支持双波浪 `~~x~~`**,不支持单波浪 `~x~`(`SetGFMStrikethrough1(false)`)。
+- 删除线**仅支持双波浪 `~~x~~`**,不支持单波浪 `~x~`(`SetGFMStrikethrough1(false)`)。
- 反斜杠转义不是 `NodeTextMark` 子类型:它对应独立的 `NodeBackslash` 节点,不会出现在 `TextMarkType` 取值中。
### 6.3 带样式的内联文本(★ 必须成对)
@@ -421,7 +478,7 @@ NodeList NodeList
> AI 生成带样式的内联文本时,这两节点必须成对出现,否则 kramdown 往返会丢样式。
-### 6.4 `NodeImage`(七段子结构)
+### 6.4 `NodeImage`(七段核心结构;可选标题增加两个节点)
```json
{ "Type": "NodeImage", "Data": "span", "Children": [
@@ -431,13 +488,28 @@ NodeList NodeList
{ "Type": "NodeCloseBracket" },
{ "Type": "NodeOpenParen" },
{ "Type": "NodeLinkDest", "Data": "assets/image-2021.png" },
+ { "Type": "NodeLinkSpace" },
+ { "Type": "NodeLinkTitle", "Data": "图片标题" },
{ "Type": "NodeCloseParen" }
] }
```
-- 图片节点本身 `Data` 是 `"span"`。
-- `NodeBang`/`NodeOpenBracket`/`NodeCloseBracket`/`NodeOpenParen`/`NodeCloseParen` 这些 marker 的 `Data` **可省略**。
-- 只有 `NodeLinkText`、`NodeLinkDest` 带 `Data`。
+- 编辑器生成的图片节点通常带有 `Data: "span"`;兼容的紧凑数据可以省略空 `Data`。
+- `NodeBang` / `NodeOpenBracket` / `NodeCloseBracket` / `NodeOpenParen` / `NodeCloseParen` 等标记节点的 `Data` **可以省略**。
+- `NodeLinkText` 和 `NodeLinkDest` 分别保存替代文本和目标地址。存在标题时,在 `NodeCloseParen` 前依次插入 `NodeLinkSpace` 和 `NodeLinkTitle`;不含这两个节点的七节点形式同样有效。
+
+### 6.5 换行与反斜杠转义
+
+```json
+{ "Type": "NodeSoftBreak", "Data": "\n" }
+{ "Type": "NodeBr" }
+{ "Type": "NodeBackslash",
+ "Children": [ { "Type": "NodeBackslashContent", "Data": "|" } ] }
+```
+
+- `NodeSoftBreak` 表示软换行。
+- `NodeBr` 表示显式 `<br>`。
+- `NodeBackslash` 使用内联子节点包装被转义字符;它不是 `NodeTextMark` 子类型。
---
@@ -445,25 +517,28 @@ NodeList NodeList
| 字段 | 编码 | 例 |
|---|---|---|
-| `ListData.Marker` | base64 | `Kg==`=`*`,`MS4=`=`1.`,`MQ==`=`1` |
-| `CodeBlockInfo` | base64 | `Z28=`=`go`,`amF2YQ==`=`java` |
-| `CodeBlockOpenFence`/`CloseFence` | base64 | `YGBg`=` ``` ` |
-| `ListData.BulletChar`/`Delimiter` | **int ASCII 码点**(**不是** base64) | `42`=`*`,`46`=`.` |
+| `ListData.Marker` | base64 | `Kg==` = `*`,`MS4=` = `1.`,`MQ==` = `1` |
+| `CodeBlockInfo` | base64 | `Z28=` = `go`,`amF2YQ==` = `java` |
+| `CodeBlockOpenFence`/`CloseFence` | base64 | `YGBg` = ` ``` ` |
+| `ListData.BulletChar`/`Delimiter` | **int ASCII 码点**(**不是** base64) | `42` = `*`,`46` = `.` |
+| `TaskListItemMarker` | **int ASCII 码点**(**不是** base64) | `32` = 空格,`88` = `X`,`33` = `!` |
| `Data`(段落文本、代码内容、链接、SQL 等) | **原文**(不编码) | `"package main\n..."` |
-> 判别规则:`Marker`/`Fence`/`Info` 这类**标记符字段**是 base64;`Data`、`TextMarkTextContent`、`TextMarkInlineMathContent` 等内容字段是原文;`BulletChar`/`Delimiter` 是 int 码点。
+> 判断规则:Go `[]byte` 字段(如 `Marker` / `Fence` / `Info`)会成为 base64 字符串;Go `byte` 字段(如 `BulletChar` / `Delimiter` / `TaskListItemMarker`)会成为 JSON 数字;`Data`、`TextMarkTextContent`、`TextMarkInlineMathContent` 等内容字符串保持原文。
---
-## 8. Properties(IAL)全解
+## 8. Properties(IAL)
扁平 `map[string]string`。
-**文档级必有**:`id`、`title`、`type`(恒 `"doc"`)、`updated`。可选:`icon`(emoji 码点十六进制,如 `"1f4f0"`;自定义图标文件名;或 HTTP(S) 图片 URL)、`title-img`(题头图样式,CSS 声明字符串,如 `background-image:url("assets/example.jpg")`)。
+**文档级(规范写入时必需)**:`id`、`title`、`type`(恒为 `"doc"`)、`updated`。可选:`icon`(emoji 码点十六进制,如 `"1f4f0"`;自定义图标文件名;或 HTTP(S) 图片 URL)、`title-img`(题头图样式,CSS 声明字符串,如 `background-image:url("assets/example.jpg")`)。
-**Block 级必有**:`id`(= 节点 `ID`)、`updated`。可选:`style`(行内 CSS)、`fold: "1"`(折叠态)、`colgroup`(表格列宽)、任意 `custom-*` 自定义属性。
+**块级(规范写入时必需)**:`id`(等于节点 `ID`)、`updated`。兼容的历史数据可能缺少 `updated`,但新写入器应提供它。常见可选属性包括 `style`、`fold: "1"`、`name`、`alias`、`memo`、`bookmark`、表格的 `colgroup` / `caption`、属性视图的 `custom-sy-av-view`,以及任意 `custom-*` 属性。
-> 权威键是**小写** `id`。某些旧导入文件里同时有遗留的大写 `ID`,以小写为准。
+**内联级(可选)**:部分内联或结构节点也使用 `Properties`,包括带样式的 `NodeTextMark`、定位或缩放后的 `NodeImage`,以及合并或带样式的 `NodeTableCell`。内联节点存在 `Properties` 并不会使其成为块。
+
+> 规范权威键是**小写** `id`。某些旧导入文件还带有遗留的大写 `ID`;显式规范化过程可以清理该兼容遗留字段。
---
@@ -475,25 +550,26 @@ NodeList NodeList
| `NodeListItem` | 任意非 `NodeListItem` 块(段落/代码块/子 `NodeList`/超级块…) | `NodeListItem`(嵌套要再套 `NodeList`) |
| `NodeBlockquote` | 任意非 `NodeListItem` 块 + 一个 `NodeBlockquoteMarker` | `NodeListItem` |
| `NodeCallout` | 任意非 `NodeListItem` 块 | `NodeListItem` |
-| `NodeSuperBlock` | **任意块**(含嵌套超级块),三段 marker 包裹 | 无(最宽松) |
+| `NodeSuperBlock` | **任意块**(含嵌套超级块),位于开始、布局和结束标记组成的包络内 | 无(最宽松) |
| `NodeDocument` | 任意非 `NodeListItem` 块 | `NodeListItem` |
-> 这些规则由 Lute 的 `CanContain` 强制校验,违反会导致解析/渲染异常,AI 生成时必须遵守。
+> 这些是从 Lute `CanContain` 派生的规范写入约束。Markdown 解析器在构造树时会应用它们,但 `dataparser.ParseJSON` 不是严格的容纳关系校验器,不会拒绝所有违规结构。直接写入器必须自行验证这些关系;无效树可能导致解析或渲染异常。
---
-## 10. 零宽空格约定
+## 10. 零宽空格处理
-`.sy` 大量使用 `​`(U+200B)作分隔占位。图片、行内代码、标签、kbd 等内联元素**两侧通常各有一个** `Data` 为 `​` 的 `NodeText`,保证渲染与光标行为。AI 生成这类内容时建议遵循该约定。
+兼容 AST 数据可能在 `NodeText` 中包含 `​`(U+200B),用于内联元素附近的光标边界。编辑时应保留已有的 U+200B,但不要在每个图片、行内代码、标签、kbd 或类似节点两侧都合成含 U+200B 的 `NodeText`;Protyle 会在渲染编辑器 DOM 时按上下文注入这些光标占位符。省略 `Data` 表示空字符串,而不是 U+200B。
---
-## 11. 思源禁用的 Markdown 语法(不应出现在 `.sy` 中)
+## 11. 规范写入禁用的类型(不要生成)
-思源在 `kernel/util/lute.go` 的 `NewLute()` 中通过 `SetXxx(false)` 禁用了以下语法,对应节点类型**永远不会**出现在 `.sy` 文件里,AI 不要生成:
+规范写入器不得生成以下语法或节点族。其中大多数通过 `kernel/util/lute.go` 的 `NewLute()` 中的 `SetXxx(false)` 禁用,因此当前配置的 Markdown 解析器不会生成相应节点。`NodeGitConflict` 是特殊情况:`NewLute()` 启用 `SetGitConflict(true)` 仅用于识别输入中已有的原始 Git 冲突标记,该节点族仍属于规范 `.sy` 写入禁用类型。兼容读取器可能在历史或外部生成的 JSON 中遇到下列任意类型。
-| 禁用项 | 对应节点类型 | 说明 |
+| 规则 | 对应节点类型 | 说明 |
|---|---|---|
+| 规范写入禁用;`SetGitConflict(true)` 用于识别已有输入 | `NodeGitConflict`/`NodeGitConflictOpenMarker`/`NodeGitConflictContent`/`NodeGitConflictCloseMarker` | 原始 Git 冲突标记块;不得生成 |
| `SetFootnotes(false)` | `NodeFootnotesDefBlock`/`NodeFootnotesDef`/`NodeFootnotesRef` | 脚注,全禁 |
| `SetToC(false)` | `NodeToC` | `[toc]` 目录 |
| `SetIndentCodeBlock(false)` | 缩进式代码块 | 仅支持围栏代码块 |
@@ -509,24 +585,27 @@ NodeList NodeList
## 12. AI 写入检查清单
-生成一份能被 SiYuan 正常加载的 `.sy`,逐条核对:
-
-1. ☐ 根 `Type`=`"NodeDocument"`、`Spec`=`"2"`,根 `ID`=文件名(去 `.sy`)且 = `Properties.id`
-2. ☐ 根 `Properties` 含 `id`/`title`/`type:"doc"`/`updated`
-3. ☐ 每个 block 有 22 字符 `ID`,且 `Properties.id` = `ID`,`Properties.updated` 为合法 14 位时间戳
-4. ☐ 内联/标记节点**不带** `ID`
-5. ☐ 列表用 `ListData.Typ` 区分(缺省=无序/`1`=有序/`3`=任务)
-6. ☐ `NodeList` 直接子节点**只能是** `NodeListItem`;嵌套列表要再套一层 `NodeList`
-7. ☐ `BulletChar`/`Delimiter` 是 byte(JSON 表现为 int 码点);`Marker` 是 base64
-8. ☐ 任务标记通常不带 `Data`(勾选时 `TaskListItemChecked:true`,未勾选仅有 `Type`)
-9. ☐ 代码块四段、数学块三段、嵌入块五段、超级块三段——结构完整
-10. ☐ `NodeCodeBlockCode`/`NodeMathBlockContent` 是内联子节点,通常只有 `Type`+`Data`
-11. ☐ base64 字段已编码;内容字段保持原文
-12. ☐ 内联格式优先用 `NodeTextMark`,不用 `NodeStrong`/`NodeEmphasis`/`NodeLink`
-13. ☐ 带样式的 TextMark 后必须跟配对的 `NodeKramdownSpanIAL`
-14. ☐ HTML/IFrame/Video/Audio/AttributeView 是叶子,无 Children(内容在 `Data` 或专属字段)
-15. ☐ 不要凭空构造 `AttributeViewID`/`block-ref` 的目标 ID(须指向真实存在的块/AV)
-16. ☐ 不要生成思源禁用的类型(脚注/ToC/YAML/LinkRef/HeadingID 等,见 §11)
+生成或兼容编辑一份能被思源正常加载的 `.sy` 时,应逐条核对:
+
+1. ☐ 根 `Type` = `"NodeDocument"`、`Spec` = `"2"`;根 `ID` 等于去掉 `.sy` 后的文件名,并等于 `Properties.id`
+2. ☐ 根 `Properties` 包含 `id` / `title` / `type:"doc"` / `updated`
+3. ☐ 每个新生成的 ID 都是新值且在整个工作区中唯一;每个规范块都有 22 字符 `ID`、与之匹配的 `Properties.id`,以及合法的 14 位 `Properties.updated`
+4. ☐ 根据 `Type` 而不是 `ID` 判断块;不要为新内联或标记节点添加 ID,只能将历史非块 ID 作为字段规范化清理,不能删除节点本身
+5. ☐ 修改内容或结构时,刷新被修改块、其块级祖先、适用的前置标题以及文档根节点的 `updated`
+6. ☐ 列表通过 `ListData.Typ` 区分(`0` 或省略表示无序,`1` 表示有序,`3` 表示任务),`NodeList` 和每个 `NodeListItem` 都使用对应的 `Typ`
+7. ☐ `NodeList` 的直接子节点**只能**是 `NodeListItem`;嵌套列表应在列表项中再放一个 `NodeList`
+8. ☐ Go `byte` 字段(`BulletChar`、`Delimiter`、`TaskListItemMarker`)是 JSON 数字;Go `[]byte` 字段(`Marker`、围栏、信息)是 base64 字符串
+9. ☐ 任务标记使用 `TaskListItemMarker` 保存原始标记字节(`32` 表示空格,`88` 表示 `X`,其他非空格字节表示已勾选);`TaskListItemChecked` 是兼容回退,`Data` 不是权威状态
+10. ☐ 代码块有四个结构子节点,数学块有三个,查询嵌入块有五个,超级块使用开始、布局、结束标记包裹至少一个内容块
+11. ☐ `NodeCodeBlockCode` 和 `NodeMathBlockContent` 是结构性内联子节点;其历史 ID 可以清理,但不能删除节点
+12. ☐ 内容字符串保持原文;只有 `[]byte` 字段使用 base64
+13. ☐ 现代内联格式优先使用 `NodeTextMark`,而不是旧式 `NodeStrong` / `NodeEmphasis` / `NodeLink`
+14. ☐ 带样式的 `NodeTextMark` 后紧跟配对的 `NodeKramdownSpanIAL`
+15. ☐ HTML / IFrame / Widget / Video / Audio / AttributeView / CustomBlock 节点是没有 `Children` 的叶子;内容放在 `Data` 或类型专属字段中
+16. ☐ 不要凭空构造 `AttributeViewID` 或块引用目标 ID;它们必须指向真实的属性视图或块
+17. ☐ 不要生成 `NodeGitConflict`、脚注、ToC、YAML、LinkRef、HeadingID 等禁用类型;兼容读取历史或外部数据时应容忍它们
+18. ☐ 编辑时保留已有的 U+200B 文本,但不要在内联元素周围统一合成零宽空格节点
+19. ☐ 将加密笔记本磁盘文件视为密文而不是 JSON;只能通过已解锁笔记本的 API 修改
---
@@ -534,24 +613,28 @@ NodeList NodeList
| ❌ 错误 | ✅ 正确 |
|---|---|
-| 假设所有节点都有 `Data` | `Data` 可省略,marker 节点常无 `Data` |
-| 内联节点带 `ID` | 内联/标记节点不带 `ID` |
+| 假设所有节点都有 `Data` | `Data` 可以省略,标记节点通常没有 `Data` |
+| 因节点带有 `ID` 就认定它是块,或将整个节点作为异常数据删除 | `Type` 决定块类型;兼容编辑器可以清理历史非块节点的 `ID` 字段,但不能删除节点本身 |
| 用 `NodeStrong`/`NodeLink` 等旧式节点 | 用 `NodeTextMark` + `TextMarkType` |
-| `ListData.Typ` 只认 `1` | `Typ` 缺省=无序,`1`=有序,`3`=任务 |
-| 把 `BulletChar` 当 base64 | 它是 byte,JSON 中表现为 int 码点(`42`=`*`) |
-| 任务标记里强写 `"Data":"[X]"` | 真实 `.sy` 通常无 `Data`,勾选仅写 `TaskListItemChecked:true` |
+| `ListData.Typ` 只接受 `1` | `0` 或省略表示无序,`1` 表示有序,`3` 表示任务 |
+| 把 `BulletChar` 当作 base64 | 它是 `byte`,在 JSON 中表现为 int 码点(`42` = `*`) |
+| 把 `"Data":"[X]"` 当作权威任务状态 | 使用数字 `TaskListItemMarker` 保存原始标记字节;`TaskListItemChecked` 是兼容回退 |
| 带样式 TextMark 不配 IAL | 必须配 `NodeKramdownSpanIAL` |
-| 给 `NodeAttributeView` 加 Children | 它是叶子,用 `AttributeViewID`/`AttributeViewType` |
+| 给 AttributeView、Widget 或 CustomBlock 节点添加 `Children` | 它们是叶子,应使用 `Data` 或类型专属字段 |
| 改 `ID` 不同步 `Properties.id` | 二者必须一致 |
+| 只更新时间戳被直接编辑的块 | 还要刷新其块级祖先、适用的前置标题以及文档根节点 |
| `inline-math` 带 `TextMarkTextContent` | 它只有 `TextMarkInlineMathContent` |
-| 凭空造 block-ref / AV 的目标 ID | 目标必须真实存在 |
+| 凭空构造块引用或属性视图的目标 ID | 目标必须真实存在 |
| 把段落直接挂到 `NodeList` 下 | `NodeList` 只能含 `NodeListItem`,必须先包一层 |
-| 生成脚注/ToC/YAML 等节点 | 思源禁用这些语法,不会出现在 `.sy` 中 |
+| 在每个内联元素两侧都添加 U+200B 文本节点 | 保留已有 U+200B;由 Protyle 按上下文添加编辑器 DOM 光标占位符 |
+| 生成 `NodeGitConflict`、脚注、ToC、YAML 等节点 | 它们属于规范写入禁用类型;兼容读取器仍可能遇到历史或外部节点 |
---
## 14. 最小可写文档模板
+> ⚠️ 下列 ID 和时间戳仅用于示意。实际写入时必须生成在整个工作区中唯一的新 ID 和当前时间戳,绝不能复制这些字面值。
+
```json
{
"ID": "20260628120000-abc1234",
@@ -586,9 +669,11 @@ NodeList NodeList
## 附:核验来源
-- 样本 1:`app/guide/.../20200825162036-4dx365o.sy`(排版元素,覆盖几乎所有块类型)
-- 样本 2:`app/guide/.../20200905090211-2vixtlf.sy`(内容块类型,含紧凑列表、AttributeView)
-- 节点类型常量与序列化逻辑:`lute/ast/node.go`、`lute/render/json_renderer.go`、`dataparser/sy.go`
-- 列表容纳校验:`lute/ast/node.go:988`(`CanContain`)
-- 思源禁用语法配置:`kernel/util/lute.go:51`(`NewLute`)
-- 标注 `【推断】` 的字段(如 `file-annotation-ref` 的子字段)建议在生成前用真实样本再核验一次。
+- 样本 1:`app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-abz7w6k/20200825162036-4dx365o.sy`(排版元素,覆盖几乎所有块类型)
+- 样本 2:`app/guide/20210808180117-czj9bvb/20200812220555-lj3enxa/20210808180320-fqgskfj/20200905090211-2vixtlf.sy`(内容块类型,包含紧凑列表和 AttributeView)
+- 这些样本包含旧版缺陷产生的历史遗留数据,应将其视为兼容性样本;规范化过程可以清理遗留的非块 ID,而规范新写入遵循当前节点语义。
+- 节点类型常量及任务、列表字段:`lute/ast/node.go`
+- 序列化与兼容解析:`lute/render/json_renderer.go`、`dataparser/sy.go`
+- 容纳规则:Lute `ast.Node.CanContain`
+- 规范写入禁用项与语法配置:`kernel/util/lute.go`(`NewLute`),包括 Git 冲突输入识别
+- Lute 依赖版本:`kernel/go.mod`