Repository navigation
fix(export): text, markdown, mirror and embeds - #13869
yuxi-liu-wired wants to merge 15 commits into
Conversation
| (cons content (tree->file-content-aux db children (assoc (select-keys opts [:open-blocks-only?]) | ||
| :init-level (inc level)) | ||
| context)) |
There was a problem hiding this comment.
🟡 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.
| (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)) |
Was this helpful? React with 👍 or 👎 to provide feedback.
| (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)) |
There was a problem hiding this comment.
🟡 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.
Was this helpful? React with 👍 or 👎 to provide feedback.
| 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')))) |
|
02fe86a to
4dda876
Compare
4dda876 to
546e627
Compare
dbb41e5 to
3a0f254
Compare
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.
c26c3e4 to
b82e6a4
Compare
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.
b82e6a4 to
7232c36
Compare
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/linkis the embedded block; its own title is empty.tree->file-content-auxinlogseq.common.export.filewrites 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/linkis written as the embedded block and its children, at the embed's level, as the embed shows them::inline-block-embeds?in the text export's content config, so the Markdown mirror, which sharestree->file-content-auxand matches one rendered line to one block, writes one line per block as before;open-blocks-onlyandinclude-propertiesoptions (block->contentkeeps:open-blocks-only?in the options it passes down);Test
In
frontend.handler.export-test:export-blocks-as-markdown-block-embed(a block that embeds a block with one child exports as- embeddedand\t- embedded child; a block embedding itself exports as-) andexport-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 (includingpage-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:
[[uuid]], and the target block has noid::line. No reader of the files can resolve it; Logseq's Markdown importer drops the ref.RangeError: Maximum call stack size exceeded, and that page is not mirrored.)[[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:nodeproperty value that is a block is written as((uuid)). Other exports do not set it and are unchanged.frontend.worker.markdown-mirror::block/_refsor:block/_link) getsid:: <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);{{embed ((uuid))}}instead of a copy of the target (this also removes the recursion);:block/refsor:block/linkalso re-mirrors the target's page, so itsid::line appears and disappears with the references.docs/adr/0016-markdown-mirror.md(Markdown Content 7, new 8) anddocs/logseq-markdown-syntax.md(References) describe the new output.Example:
Blocks nothing points at look exactly as before.
Test
page-mirror-writes-block-refs-embeds-and-node-values-by-block-id-testinfrontend.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-testchecks 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* xinside#+BEGIN_QUOTE) fails with the string "Insert at top".block-quoteinfrontend/handler/export/html.cljsbuilt the quote's content in a zipper rooted at a bare[:blockquote]. The zipper's branches are:ulnodes, so that root has no children to move to. A paragraph inside the quote works, because it only edits the root node. A list callsadd-next-level-ul-at-righton the root, andclojure.zip/insert-rightat 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-helperis split intoexport-hiccup, which builds the hiccup, and the rendering. The tests check the hiccup, because the rendering's pretty-print step uses the browser'sDOMParser, 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-exportis called with:include-children? falsefor 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? falseevery 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-rowinlogseq.db.sqlite.export-testexports 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 fixlogseq.db.sqlite.export-testpasses (45 tests, 191 assertions).Found by mutation testing: changing
:include-children? falsetotrueinbuild-view-nodes-exportmade 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 (
:graphand:graph-humancame back with no mismatch).1. A selected block that another selected block references is exported twice
Selecting
alphaandxwherexhas a node propertysource:: alpha(or a[[uuid]]ref toalpha) exportsalphatwice 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-exportavoids this by dropping its own page;build-selected-nodes-exportandbuild-view-nodes-exportpassed nothing.Fix:
build-uuid-block-exporttakes 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-fnincludes 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 pageAlphais not otherwise in the export: the export writes[:build/page {:block/title "Alpha"}]and relies onsqlite.build/add-new-pages-from-propertiesto create the page, butget-used-properties-from-optionsreads only each page's top-level:blocks, never:build/children, so the import throwsNo uuid for page '{:block/title "Alpha"}'. The same block at the top level imports fine.Fix:
get-used-properties-from-optionsalso walks:build/children.3. A ref inside a referenced block imports as a raw uuid
Exporting a block
export [[middle]]wheremiddleismiddle [[Beta]]:middleis exported (shallow) with its title, butBetais not, so the import showsmiddle [[<uuid>]].Fix:
build-content-ref-exportfollows 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.
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
Property:: valuewas written; the value's child and grandchild blocks were missing, with no warning.myprop::followed by a- some valuebullet, instead ofmyprop:: some value.order alpha,order beta [[order alpha]],order gammacame back as beta, gamma, alpha.Cause
block-properties-content(logseq.common.export.file). Text property values are written as nested blocks only when:export-default-property-values-as-blocks?is set (since master's fix: preserve Text property descendants and export filters #13573 also by the text, OPML and HTML exports). Markdown mirror sets it, so it wrote every Text property as blocks whatever the cardinality (点击标签,含有此标签的节点能被筛选出来(多标签搜索) #1218). The selection export config (get-content-config) does not set it, so children of the value were dropped (github pull到本地文件夹后,用logseq打开后属性全部被展开 #1390).merge-export-mapsjoined the two:blocksvectors without looking at:block/uuid, and the importer put the repeated block after the other siblings.Change
:single-text-property-value-inline?; with it, the nested block form is used only when the property allows multiple values, or a value has children or properties of its own that the export writes. A single value with neither is one property line in the mirror. The text export does not set it and writes every Text value as a block, as master's fix: preserve Text property descendants and export filters #13573 does and pins (export-blocks-as-markdown-with-properties). A follow-up commit added the "properties of its own" case, after review pointed out thatnotes=Draftwithrating:: 5lostrating:: 5.merge-export-mapskeeps one block per:block/uuidin a page's:blocks, at the position of its first occurrence, and merges the repeats. Blocks without a:block/uuidare kept as they are. A follow-up commit merges the:build/childrenof the repeats by child uuid, recursively, so a child exported in full is not replaced by the shallow copy made for a reference (otherwise the child was imported without its properties and tags when a selected block referred to both the selected parent and its child).Tests
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 adb-worker-node"Worker request timeout" that passed when the namespace was rerun alone.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-testnow 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-testcovers a single value with properties of its own and no children (rating:: 5undernotes=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.merge-export-maps-keeps-one-block-per-uuidandimport-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-twiceandimport-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. Thedeps/dbsuite and the whole main-bundle unit suite pass at the branch head.