Skip to content

fix(export): text, markdown, mirror and embeds - #13869

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

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

Conversation

@yuxi-liu-wired

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

Copy link
Copy Markdown
Contributor

Combines the PRs of this theme, to keep the number of open PRs down; the commits are unchanged. CI's unit suite passes on the combined branch.

fix(export): block embeds, block ids in the mirror, quotes holding lists; view and EDN exports keep child rows (was #13869)

Export fixes, combined from #13784 and #13785 (closed in favour of this one). Each section below is the original description; the commits are unchanged.

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

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.

fix(export): view and EDN exports keep child rows and import back whole (was #13785)

This PR combines #13681, #13744, 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.


#13681: fix(export): a view export keeps a row whose parent is also a row

Exporting the rows of a table or list view (export type :view-nodes) drops any row whose parent block is also a row. Example: a view lists "parent" and its child block "child"; the export contains only "parent", so "child" is lost on import.

Cause: build-blocks-export is called with :include-children? false for view exports, so it builds no parent-to-children map, but it still treats every block whose parent is among the exported blocks as a non-root. Such a block is then neither nested under its parent nor exported as a root.

Fix: with :include-children? false every given block is a root, so each row is exported once, flat, as view exports intend. Selected-node exports (:include-children? true) are unchanged.

Test: import-view-blocks-with-child-row in logseq.db.sqlite.export-test exports a parent and its child as view rows, checks both are in the export, imports it, validates the db and finds the child. On master it fails twice (the child is missing from the export and from the import); with the fix logseq.db.sqlite.export-test passes (45 tests, 191 assertions).

Found by mutation testing: changing :include-children? false to true in build-view-nodes-export made no existing test fail, and the changed version exported the child.


#13744: fix(export): EDN export of pages, blocks and selections imports back whole

Three ways an EDN export of a page, a block or a selection did not import back whole. Found by fuzzing export → import for every export type (:graph and :graph-human came back with no mismatch).

1. A selected block that another selected block references is exported twice

Selecting alpha and x where x has a node property source:: alpha (or a [[uuid]] ref to alpha) exports alpha twice on the same page: once as a selected node, once as a referenced block (build-uuid-block-export). The import creates a duplicate, or merges the two copies by uuid and the page's block order changes. build-page-export avoids this by dropping its own page; build-selected-nodes-export and build-view-nodes-export passed nothing.

Fix: build-uuid-block-export takes the nodes already in the export (:exported-nodes) and leaves them out. An exported node that is another node's property value keeps its uuid (:include-uuid-fn includes the property value entities), so the value still resolves.

2. A node property value on a nested block fails the import

A child block with source:: [[Alpha]], where page Alpha is not otherwise in the export: the export writes [:build/page {:block/title "Alpha"}] and relies on sqlite.build/add-new-pages-from-properties to create the page, but get-used-properties-from-options reads only each page's top-level :blocks, never :build/children, so the import throws No uuid for page '{:block/title "Alpha"}'. The same block at the top level imports fine.

Fix: get-used-properties-from-options also walks :build/children.

3. A ref inside a referenced block imports as a raw uuid

Exporting a block export [[middle]] where middle is middle [[Beta]]: middle is exported (shallow) with its title, but Beta is not, so the import shows middle [[<uuid>]].

Fix: build-content-ref-export follows refs in the titles of referenced blocks until no new ones turn up. The blocks it starts from include every value of a many node property (a set), not only single values.

Tests

In logseq.db.sqlite.export-test: import-selected-nodes-that-reference-each-other, import-selected-nodes-where-one-is-a-node-value-of-another, import-page-with-node-value-on-child-block, import-block-with-refs-two-levels-deep, import-block-with-node-value-whose-title-has-a-ref. Each fails or errors on master and passes with the fix; the other export tests pass.

The EDN export → import fuzzer (every export type, seeds 1 and 11) finds no mismatch with this PR. The text loops' remaining cases are logseq/db-test#1442.


Devin Review

fix(export): Text property values in exports and the Markdown mirror; no repeated blocks in selected-block EDN (was #13887)

Fixes logseq/db-test#1390.
Fixes logseq/db-test#1218.
Fixes logseq/db-test#1389.

Three export bugs, each fixed in its own commit.

What the user sees

Cause

Change

Tests

  • github pull到本地文件夹后,用logseq打开后属性全部被展开 #1390: export-blocks-as-markdown-keeps-text-property-value-children (frontend.handler.export-test) exports a block through the Text export path and checks the value's child and grandchild are present. Fails without the change (2 assertions); with it the namespace passes, and the whole unit suite passed except a db-worker-node "Worker request timeout" that passed when the namespace was rerun alone.
  • 点击标签,含有此标签的节点能被筛选出来(多标签搜索) #1218: page-mirror-exports-single-value-text-property-on-one-line-test (frontend.worker.markdown-mirror-test) checks a single-value and a multiple-value property side by side. Three existing mirror tests that pinned the list form for single-value properties now expect the one-line form; property-value-lines-do-not-render-db-id-comments-test now uses a multiple-value property so it still covers the bullet form. Without the change the namespace fails 4 tests; with it the namespace and the whole unit suite pass. page-mirror-exports-properties-of-single-text-property-value-test covers a single value with properties of its own and no children (rating:: 5 under notes = Draft); it fails without the follow-up commit and passes with it, and the whole unit suite passes at the branch head. Changing those three tests changes pinned output on purpose, as the issue asks; if the list form is wanted (for example for round-tripping the mirror), the 点击标签,含有此标签的节点能被筛选出来(多标签搜索) #1218 commit can be dropped on its own and the other two fixes stand.
  • Block UUID should be unchanged at best effort upon cut & paste #1389: merge-export-maps-keeps-one-block-per-uuid and import-selected-nodes-keeps-order-of-referenced-sibling (logseq.db.sqlite.export-test, deps/db) fail without the change and pass with it. For the follow-up, merge-export-maps-keeps-fuller-child-of-block-exported-twice and import-selected-nodes-keeps-child-properties-when-parent-and-child-are-referenced (a round trip where one selected block refers to both the selected parent and its child, checking the child's property and tag) fail without the change (3 failed assertions) and pass with it. The deps/db suite and the whole main-bundle unit suite pass at the branch head.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Devin Review found 3 potential issues.

Devin Review

Comment thread src/main/logseq/common/export/file.cljs Outdated
Comment on lines +460 to +462
(cons content (tree->file-content-aux db children (assoc (select-keys opts [:open-blocks-only?])
:init-level (inc level))
context))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Nested embeds restore excluded properties

When a child contains an embed, tree->file-content-aux drops :include-properties? before rendering it. The embedded block's properties then appear in exports made with “remove properties” enabled.

Suggested change
(cons content (tree->file-content-aux db children (assoc (select-keys opts [:open-blocks-only?])
:init-level (inc level))
context))
(cons content (tree->file-content-aux db children (assoc (select-keys opts [:open-blocks-only? :include-properties?])
:init-level (inc level))
context))

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +547 to +551
(let [closing? (code-fence-block-line? line)]
(recur more
(cons block-line-info' more-block-line-infos)
(cond-> (conj lines line)
(and closing? fence-id-line) (conj fence-id-line))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Code fences swallow referenced block IDs

When referenced code contains a triple-backtick line, code-fence-block-line? mistakes it for the closing fence. The mirror inserts id:: before the actual closing fence, leaving block references unresolved.

Learn more

The serializer chooses a fence longer than any backtick run in the code. The matcher instead accepts every line beginning with three backticks, including a shorter run inside the code. It inserts the id line inside the actual fence, where Markdown readers treat it as code.

Example: A referenced code block containing ``` as a line gets four-backtick fences. Its inner three-backtick line triggers the id insertion, before the four-backtick closing line.

Recommended fix: Track the opening fence length in decorate-rendered-content and insert fence-id-line only after the matching closing fence; retain ordinary interior lines without changing fence state.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +388 to +393
content-ref-uuids (loop [uuids (block-refs blocks)]
(let [ref-blocks (->> uuids
(keep #(d/entity db [:block/uuid %]))
(remove entity-util/page?))
uuids' (into uuids (block-refs ref-blocks))]
(if (= uuids uuids') uuids (recur uuids'))))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔍 Reference closure rescans visited blocks

Each iteration scans every UUID already found, so long chains repeat entity lookups. A frontier of newly discovered UUIDs avoids the repeated work.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author
  • Nested embeds and properties: agreed, fixed in the latest commit (children get :include-properties?; export-blocks-as-markdown-without-properties-in-a-nested-embed).
  • Code fences: agreed, fixed in the same commit: the id line goes after the line that closes the opening fence (only backticks, at least as many); a shorter run inside the code stays code (page-mirror-writes-a-code-block-id-after-a-longer-fence-test).
  • Reference closure rescans: a fair performance note; the closure runs once per export over the selection's refs, and is left as is in this PR.

@yuxi-liu-wired yuxi-liu-wired changed the title fix(export): block embeds, block ids in the mirror, quotes holding lists; view and EDN exports keep child rows fix(export): text, markdown, mirror and embeds Oct 28, 2026
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-combined branch 2 times, most recently from dbb41e5 to 3a0f254 Compare November 3, 2026 12:01
VictorVow added a commit to VictorVow/logseq that referenced this pull request Nov 7, 2026
Squash of logseq#13869 (17 commits, head
of pull/13869) applied onto fork. Only the PR's own changes are taken;
upstream commits newer than this fork that the PR's base includes are
left out (asset-export-title and the missing-block-ref test fixture),
and the export test gains the export-html require that the PR got from
that newer upstream context.

Fixes "Maximum call stack size exceeded" on Markdown mirror regenerate:
the mirror wrote a block embed as a copy of its target, recursing
forever when a block embeds its own ancestor. It now writes
{{embed ((uuid))}} and gives the target an id:: line.
@yuxi-liu-wired
yuxi-liu-wired force-pushed the fix/export-combined branch 6 times, most recently from c26c3e4 to b82e6a4 Compare November 18, 2026 14:37
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.
…whole

- Selected nodes: a selected block that another selected block references was exported a second time; blocks already in the export are no longer added as referenced blocks.
- A node property value on a nested block pointing at a page outside the export failed the import (No uuid for page): sqlite.build now looks at nested blocks when it creates pages from property values.
- A referenced block is exported with its title, so the refs in that title are followed too; before, they imported as raw uuids.
…rty value; follow refs in many node values

With the selected block no longer exported twice, a selected block that is another selected block's node value lost the uuid the value points at (build-export: uuids are not defined). Such a node now keeps its uuid. Property values with many values (sets) were skipped when collecting the blocks whose title refs are followed.
tree->file-content-aux passed only :open-blocks-only? to a block's children, so an embed in a child block was rendered with its properties in an export made without them. The children get :include-properties? too (export-blocks-as-markdown-without-properties-in-a-nested-embed).

The test fails without the change.
Exporting a selected block as Text dropped everything nested under a Text property's value. For a property whose value block had children, the output kept only `Property:: value`, and the child and grandchild blocks were missing with no warning.

The property exporter only writes Text values as nested blocks when :export-default-property-values-as-blocks? is set. Markdown mirror sets it, but the selection export config (get-content-config) does not, so that path always wrote the inline form.

When the flag is not set, a Text property now switches to the nested block form if any of its values has children. Values without children keep the inline `Property:: value` form, and the output when the flag is set (markdown mirror) is unchanged.

Added export-blocks-as-markdown-keeps-text-property-value-children, which exports a block through the Text export path and checks that the value's child and grandchild are present. It fails without the change.

Fixes logseq/db-test#1390
The Markdown mirror wrote every Text property as a list, even when "Multiple values" was off, so `myprop:: some value` became `myprop::` followed by a `- some value` child bullet.

The exporter wrote Text values as nested blocks for all Text properties whenever the markdown mirror asked for block output, without looking at the property's cardinality.

Text values are now written as nested blocks only when the property allows multiple values, or when a value has children (which would otherwise be dropped). A single value without children stays on the property line.

Updated the mirror tests that pinned the list form for single-value properties and added page-mirror-exports-single-value-text-property-on-one-line-test, which checks a single-value and a multiple-value property side by side. It fails without the change.

Fixes logseq/db-test#1218
Importing a Selected-block EDN export moved a block that another selected block refers to behind its siblings. With the blocks `order alpha`, `order beta [[order alpha]]` and `order gamma`, the import produced beta, gamma, alpha.

The export lists the referenced block once as a selected block and again as a referenced one, and merge-export-maps joined the two :blocks vectors without looking at :block/uuid. The importer then placed the repeated block after the other siblings.

merge-export-maps now keeps one block per :block/uuid in a page's :blocks, at the position of its first occurrence, and merges the repeated occurrences. Blocks without a :block/uuid are kept as they are.

Added merge-export-maps-keeps-one-block-per-uuid, and import-selected-nodes-keeps-order-of-referenced-sibling, which exports and imports the three blocks above and checks their order. Both fail without the change.

Fixes logseq/db-test#1389
When one selected block referred to both a selected parent and its child, importing the Selected-block EDN export created the child without its properties and tags.

The export holds the parent twice: in full as a selected block, and as a shallow copy made for the reference. merge-blocks-with-same-uuid merged the two with a plain map merge, so the shallow copy's :build/children replaced the full ones.

The :build/children of the two copies are now merged by child uuid, recursively, so the child exported in full is kept.

Added merge-export-maps-keeps-fuller-child-of-block-exported-twice and import-selected-nodes-keeps-child-properties-when-parent-and-child-are-referenced, an export and import round trip that checks the child's property and tag. Both fail without the change.

Refs logseq/db-test#1389
The previous change wrote a single-value Text property on one line unless its value had children. A value that has properties of its own but no children, such as `notes` = `Draft` with `rating:: 5`, was then written inline and lost `rating:: 5`.

The nested block form is now also used when a value has properties of its own that the export writes, in addition to children and multiple values.

Added page-mirror-exports-properties-of-single-text-property-value-test, which fails without the change.

Refs logseq/db-test#1218
The block embed fixture and the Text property fixture both used ...0701, so combined they built one block with both.
…xt export, keep the mirror's one-line single value

Master's logseq#13573 exports every Text property value as a block when the export asks for it (:export-default-property-values-as-blocks?, now set by the text, OPML and HTML exports as well as the Markdown mirror), and export-blocks-as-markdown-with-properties pins that for a single value. This branch had made the flag apply only to properties that allow multiple values, for logseq/db-test#1218 (the mirror wrote a single value as a one-item list), which also wrote that single value on the property line in the text export.

The mirror's content config now sets :single-text-property-value-inline?, and only with it does a plain value of a single-value property stay on the property line. The text export follows master again, and a value with children or properties of its own is a block in both.

block-properties-content takes the export opts since logseq#13573; the check for a value's own properties passes none.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

1 participant