Skip to content

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

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

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

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

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.

@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-block-embed branch 2 times, most recently from 7b28419 to f38a587 Compare October 13, 2026 04:50
@cursor

cursor Bot commented Oct 13, 2026

Copy link
Copy Markdown

Inlining a :block/link embed in text export is the right result for export-blocks-as-markdown. The walker is inside tree->file-content-aux, and the markdown mirror uses that same function.

render-page-content calls block->content, which walks tree->file-content-aux. decorate-rendered-content then matches one rendered line to one outline block. An embed's stored title is empty, so rendered-line-matches-block? matches it only to a blank line, and decorate-block-line expands :block/link itself. After this change the embed line is already the target's - embedded line, the match fails, and the block cursor stays on the embed. Later blocks on that page keep the embed's line info, so their status and tag decoration is skipped.

embed-content also calls block->content with only {:init-level level}. :open-blocks-only? and :include-properties? from the export dialog are dropped. tree->file-content-aux still appends the embed node's own :block/children after the inlined target. The UI shows the linked block's children.

export-blocks-as-markdown-block-embed checks a normal embed exactly, and the self-embed case is only (string? self-embed). A guard that compares a block with itself still passes, and A embeds B embeds A is untested.

Expand :block/link on the text-export entry that wants inlined content, and leave block->content as one line per block for the mirror. Pass the caller's tree options into the nested block->content, and skip the embed node's own children. Assert the self-embed text and an A→B→A cycle.

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

Copy link
Copy Markdown
Contributor Author

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

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