block
This tool covers block insertion, updates, movement, metadata, references, and document-context helpers.
When to read this page: you need to manipulate block content directly instead of working at the whole-document level.
Related pages:
Common Actions
| Group | Actions |
|---|---|
| Insert and update | insert, prepend, append, update |
| Movement and structure | move, set_fold_state, get_children, breadcrumb |
| Metadata | set_attrs, get_attrs, info, dom, get_kramdown, batch_kramdown |
| Reference / utility | transfer_references, word_count, recent_updated |
| Daily note helper | add_to_daily_note |
| Document context | docs_info |
Parameters and Semantics
dataTypeis usuallymarkdownordom.prependandappendwork on either a document or a block child list.updateis a whole-block replacement, not a section editor. For a heading, a structuraldataType="dom"update must contain exactly one parsedNodeHeadingfor the target block. Do not send the heading together with the paragraphs, lists, or other blocks that follow it in the heading section; SiYuan normalizes a non-document update to the first content block.- Preserve the target block's existing IAL when constructing a structural DOM update. If heading text is interpolated into HTML, escape it as HTML text first; raw
<,>,&, or quotes can change the DOM instead of becoming heading text. Read the target DOM/kramdown before writing when you need to carry forward attributes or inline structure. - For a plain-text edit inside one existing block, prefer
replace: read that block's kramdown, use an exact old snippet, and letblock.replacepatch the original DOM. This avoids rebuilding a heading or dropping marks and IAL merely to change its text.replacedoes not traverse heading siblings or child blocks. moverequires at least one destination hint such asparentIDorpreviousID.- For batch
move, passidsin the desired final order. The tool reverses only the internal SiYuan API call order and returnsapiCallOrderfor debugging. add_to_daily_noteappends or prepends content to today's daily note viaposition.batch_kramdownaccepts 1–20 block or document IDs, performs a read-permission resolution for each item, fetches readable content in one kernel request, and returns an ordered item for every input ID. Duplicate IDs remain duplicated in the output; denied or missing IDs are returned as per-item errors.
Safety Rules
deleteandmoverequire explicit confirmation.- For multiline content, prefer
append,prepend, orinsertinstead ofupdate. - A successful write response is not structural proof. After
update,replace, or a kramdown/IAL normalization, read the fixed target back withget_kramdownand, when structure matters,dom,get_children, orinfo. Confirm the target ID, node type, heading level, IAL/attributes, and parent/child boundaries; do not use rendered text, search results, or an API success envelope as the only acceptance check. - Imported callouts and lists need the same structural readback. A block that looks like a callout may still be
NodeBlockquote, and paragraphs, tables, or images can escape their intended list item. VerifyNodeCalloutversusNodeBlockquote, list parent/child order and depth, and image kramdown after repair. TreatNodeSoftBreakand literal\nas separate cases when a repair splits paragraphs. - The block handler is a transparent native wrapper. It does not silently filter SiYuan superblock close-marker artifacts or rewrite SQL failures caused by the kernel (for example, an affected version replacing an explicit-LIMIT diagnostic with a fallback error). Preserve the native result and resolve those cases through the corresponding SiYuan upstream version/fix boundary.
Examples
MCP:
json
{
"action": "append",
"parentID": "<doc-id>",
"dataType": "markdown",
"data": "- [ ] Todo item"
}CLI:
bash
siyuan block append --parent-id <doc-id> --data-type markdown --data "- [ ] Todo item"Action List
insertprependappendupdatedeletemoveset_fold_stateget_kramdownbatch_kramdownget_childrentransfer_referencesset_attrsget_attrsinfobreadcrumbdomrecent_updatedword_countadd_to_daily_notedocs_info