Skip to content

fix(export): block embeds, block ids in the mirror, and quotes holding lists - #13784

Closed
yuxi-liu-wired wants to merge 7 commits into
logseq:masterfrom
yuxi-liu-wired:fix/export-embed-combined
Closed

yuxi-liu-wired wants to merge 7 commits into
logseq:masterfrom
yuxi-liu-wired:fix/export-embed-combined

Conversation

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor

This PR combines #13718, #13740, #13771, which change the same files, into one branch on current master so they no longer conflict with each other. Each part is unchanged except where two of them touched the same lines.


#13718: fix(export): export a block embed as the embedded block

Exporting blocks as text writes a block embed as an empty bullet: the embedded block and its children are missing from the export.

Cause

In a DB graph a block embed is a block whose :block/link is the embedded block; its own title is empty. tree->file-content-aux in logseq.common.export.file writes each block's own title, so it writes - for the embed. (The export only resolves embeds written as {{embed ((uuid))}} text.)

Fix

In the text export, a block with :block/link is written as the embedded block and its children, at the embed's level, as the embed shows them:

  • it is turned on by :inline-block-embeds? in the text export's content config, so the Markdown mirror, which shares tree->file-content-aux and matches one rendered line to one block, writes one line per block as before;
  • the embedded block gets the export's open-blocks-only and include-properties options (block->content keeps :open-blocks-only? in the options it passes down);
  • the embedding block's own children are not written, as the embed shows the embedded block's children;
  • an embed cycle (a block embedding itself, or A embeds B embeds A) stops, and the block is written as itself.

Test

In frontend.handler.export-test: export-blocks-as-markdown-block-embed (a block that embeds a block with one child exports as - embedded and \t- embedded child; a block embedding itself exports as -) and export-blocks-as-markdown-block-embed-cycle-and-options (A embeds B embeds A; an embed block with a child of its own; an embed of a collapsed block with open-blocks-only). They fail on master and pass with the fix; the other export tests and the Markdown mirror tests (including page-mirror-renders-embedded-node-content-and-tags-test) still pass.


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

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.


#13771: fix(export): a quote holding a list does not fail the HTML export

HTML export of a block whose quote holds a list (> * x, > 1. x, or * x inside #+BEGIN_QUOTE) fails with the string "Insert at top".

block-quote in frontend/handler/export/html.cljs built the quote's content in a zipper rooted at a bare [:blockquote]. The zipper's branches are :ul nodes, so that root has no children to move to. A paragraph inside the quote works, because it only edits the root node. A list calls add-next-level-ul-at-right on the root, and clojure.zip/insert-right at the root throws "Insert at top".

The fix builds the quote's content in a zipper rooted like the page's ([:ul [:placeholder]]), and puts the placeholder's items and the nodes after it into [:blockquote ...]. A quote holding paragraphs exports as before.

export-helper is split into export-hiccup, which builds the hiccup, and the rendering. The tests check the hiccup, because the rendering's pretty-print step uses the browser's DOMParser, which Node does not have.

Found by a fuzzer that exports random Markdown as text, HTML and OPML.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 16, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
the `((uuid))` that points at it."
[block]
(and (not (ldb/page? block))
(boolean (or (seq (:block/_refs block))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

referenced-block? is documented as true for a block ref, an embed, or a node-property value, but it only looks at :block/_refs and :block/_link.

A node property is stored on its own attribute. rebuild-block-refs adds that value to :block/refs only when page-or-object? is true (a page, or a block that has tags). An untagged block therefore gets source:: ((uuid)) from block-node-ref and no id:: line. affected-page-ids has the same gap: it refreshes the target page only for :block/refs and :block/link, so a property-only change on another page never rewrites the target file.

page-mirror-writes-block-refs-embeds-and-node-values-by-block-id-test also transacts :block/refs and :block/link onto the target, so it does not catch this. Treat a non-page block as referenced when a :node property datom points at it, and include that target's page in affected-page-ids.

yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 17, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from e5a8dd5 to 78776e8 Compare October 18, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from 78776e8 to b4b8cee Compare October 19, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 19, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 20, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from b4b8cee to 1b0d215 Compare October 21, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 21, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from 1b0d215 to 3db45da Compare October 22, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 22, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 23, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from 3db45da to b9ec138 Compare October 24, 2026 00:27
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 24, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-embed-combined branch from b9ec138 to e0c7ad7 Compare October 25, 2026 11:01
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 25, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 26, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
A block embed is a block linking to the embedded block (:block/link); the text export wrote the linking block's empty title, so the embed exported as an empty bullet.
…tions

The Markdown mirror shares tree->file-content-aux and writes one line per block; the inlining is now turned on by :inline-block-embeds? in the text export's content config. The embedded block gets the export's open-blocks-only and include-properties options, the embedding block's own children are not written (the embed shows the embedded block's), and an embed cycle (a block embedding itself, or A embeds B embeds A) is written as the block itself.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 29, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 30, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Oct 31, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 1, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 2, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 3, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 4, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 11, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 12, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 13, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 14, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 15, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 16, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
@yuxi-liu-wired
yuxi-liu-wired deleted the fix/export-embed-combined branch November 17, 2026 02:20
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 17, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 18, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
yuxi-liu-wired added a commit to yuxi-liu-wired/logseq that referenced this pull request Nov 19, 2026
block->content-context-test compared the whole options map, so any key
added to it broke the test: it now checks only its own keys. The nested
embed test pinned the inline embed text logseq#13784 changes; dropped.
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