Skip to content

feat(mirror): write block refs, embeds and block node values by block id - #13740

Closed
yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/mirror-block-ids
Closed

yuxi-liu-wired wants to merge 3 commits into
logseq:masterfrom
yuxi-liu-wired:fix/mirror-block-ids

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Proposal: the Markdown mirror writes block references, block embeds and node property values that are blocks by block id, and gives the block they point at an id:: <uuid> line. With that, the mirror files resolve in any reader of Logseq Markdown, including Logseq's own Markdown importer.

Why

The mirror refers to blocks by uuid but never writes the uuid where a reader can find it:

  • A block ref is written as the DB's internal [[uuid]], and the target block has no id:: line. No reader of the files can resolve it; Logseq's Markdown importer drops the ref.
  • A block embed is written as a copy of the target's content, so the file cannot tell an embed from a copy. (Writing the copy also recurses forever when a block embeds its own ancestor: RangeError: Maximum call stack size exceeded, and that page is not mirrored.)
  • A node property value that is a block is written as [[block title]], which reads back as a link to a page with that title.

These came from fuzzing the loop mirror → Markdown importer: random pages mirrored, the files imported as a file graph into a fresh DB graph, blocks compared.

ADR 0016 says the mirror is not a backup format with guaranteed import fidelity, and that is unchanged. But the mirror is meant to be read by external tools, and a reference that points at nothing is a hole in what they read. id:: <uuid> under the target block is the existing Logseq Markdown syntax for block identity (file graphs use it, the importer reads it), so this needs no new syntax.

Change

  • logseq.common.export.file: new context option :export-block-refs-as-uuid-refs?. With it, a [[uuid]] whose target is a block (not a page) is written as ((uuid)), in titles and in property value blocks, and a :node property value that is a block is written as ((uuid)). Other exports do not set it and are unchanged.
  • frontend.worker.markdown-mirror:
    • sets that option;
    • a block that something points at (:block/_refs or :block/_link) gets id:: <uuid> after its line; a code block gets it after its closing fence, as file graphs write it (inside the fence it would be code);
    • a block embed is written as {{embed ((uuid))}} instead of a copy of the target (this also removes the recursion);
    • a change to :block/refs or :block/link also re-mirrors the target's page, so its id:: line appears and disappears with the references.
  • docs/adr/0016-markdown-mirror.md (Markdown Content 7, new 8) and docs/logseq-markdown-syntax.md (References) describe the new output.

Example:

- Ship the draft
  id:: 22222222-2222-4222-8222-222222222222
- See ((22222222-2222-4222-8222-222222222222))
- {{embed ((22222222-2222-4222-8222-222222222222))}}
- Follow-up
  * blocked-by:: ((22222222-2222-4222-8222-222222222222))

Blocks nothing points at look exactly as before.

Test

page-mirror-writes-block-refs-embeds-and-node-values-by-block-id-test in frontend.worker.markdown-mirror-test: mirrors a target block, a block ref, a block embed and a node property value, checks both files, then imports the files with the file-graph importer (logseq.graph-parser.exporter/export-file-graph) and checks the target keeps its uuid, the ref points at it and the embed links it. It fails on master and passes with the change. page-mirror-writes-a-code-block-id-after-its-fence-test checks an embedded code block. page-mirror-renders-embedded-node-content-and-tags-test (which expected the embed copy) is renamed and now expects the embed macro. The other mirror and export tests pass.

A code block whose properties come after its fence imports as text on master; #13757 fixes that in the importer, so with both the code block also comes back as a code block.

The text loops' remaining cases are logseq/db-test#1442.

A block that something points at gets an id:: line; block refs are written as ((uuid)), block embeds as {{embed ((uuid))}}, node property values that are blocks as ((uuid)). The mirror files then resolve in any reader of Logseq Markdown, including the Markdown importer. Writing an embed as a reference also ends the endless recursion on a block that embeds its own ancestor.
An embedded or referenced code block got no id line (it would be inside the fence), so the embed did not resolve. The id goes after the closing fence, as file graphs write it.
The embed macro replaced the block's rendered line, heading marker included. The line matcher also takes an empty block's heading marker (###) for the empty block (the same change as in logseq#13742).
@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined with the other PRs that change the same files into #13784.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 17, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 20, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/mirror-block-ids branch October 21, 2026 18:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 23, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 26, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 13, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 14, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 15, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant