Browse Source

fix: block references to annotations

Don't rewrite annotation uuids as we don't do that for other existing blocks
Gabriel Horner 5 months ago
parent
commit
f4a8b9438e

+ 5 - 21
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -1045,7 +1045,7 @@
                      :logseq.property.pdf/hl-page 1
                      :block/title ""}
                     user-attributes
-                    {:block/uuid (d/squuid)
+                    {:block/uuid (:id m)
                      :block/order (db-order/gen-key)
                      :logseq.property/ls-type :annotation
                      :logseq.property.pdf/hl-value (dissoc m :id)
@@ -1062,7 +1062,7 @@
 
 (defn- build-pdf-annotations-tx*
   "Creates annotations for a pdf asset given the asset's edn map and parsed markdown file"
-  [asset-edn-map parsed-md parent-asset image-asset-name-to-uuids {:keys [log-fn] :or {log-fn prn} :as opts}]
+  [asset-edn-map parsed-md parent-asset image-asset-name-to-uuids opts]
   (let [color-text-idents
         (->> (get-in db-property/built-in-properties [:logseq.property.pdf/hl-color :closed-values])
              (map (juxt :value :db-ident))
@@ -1078,24 +1078,8 @@
         (mapv #(build-annotation-block % color-text-idents parent-asset image-asset-name-to-uuids md-blocks opts)
               (get-in asset-edn-map [:edn-content :highlights]))
         md-children-blocks*
-        (mapv #(assoc %
-                      :block/uuid (d/squuid)
-                      :old-uuid (:block/uuid %))
-              (find-annotation-children-blocks (vals md-blocks) (set (map :id (get-in asset-edn-map [:edn-content :highlights])))))
-        old-to-new-annotation-uuids
-        (->> (map (fn [old-annotation new-block]
-                    [(:id old-annotation) (:block/uuid new-block)])
-                  (get-in asset-edn-map [:edn-content :highlights]) annotation-blocks)
-             (into {})
-             (merge (into {} (map (juxt :old-uuid :block/uuid)) md-children-blocks*)))
-        md-children-blocks (keep #(if-let [parent-uuid (get old-to-new-annotation-uuids (second (:block/parent %)))]
-                                    (sqlite-util/block-with-timestamps
-                                     (merge (select-keys % [:block/uuid :block/title :block/order])
-                                            {:block/parent [:block/uuid parent-uuid]
-                                             :block/page :logseq.class/Asset}))
-                                    (do (log-fn :invalid-md-annotation-block "Ignore md annotation block because it has no valid :block/parent"
-                                                :block %)
-                                        nil))
+        (find-annotation-children-blocks (vals md-blocks) (set (map :id (get-in asset-edn-map [:edn-content :highlights]))))
+        md-children-blocks (keep #(sqlite-util/block-with-timestamps (merge % {:block/page :logseq.class/Asset}))
                                  md-children-blocks*)]
     (into annotation-blocks md-children-blocks)))
 
@@ -1241,7 +1225,7 @@
                    add-missing-timestamps
                    ;; old whiteboards may have :block/left
                    (dissoc :block/left :block/format :block.temp/ast-blocks)
-                  ;;  ((fn [x] (prn :block-out x) x))
+                  ;;  ((fn [x] (prn ::block-out x) x))
                    )]
     ;; Order matters as previous txs are referenced in block
     (concat properties-tx deadline-properties-tx asset-blocks-tx [block'])))

+ 2 - 2
deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs

@@ -192,7 +192,7 @@
                 (remove #(= [{:db/ident :logseq.class/Tag}] (:block/tags %)))))
         "All classes only have :logseq.class/Tag as their tag (and don't have Page)")))
 
-(deftest-async ^:focus export-basic-graph-with-convert-all-tags
+(deftest-async export-basic-graph-with-convert-all-tags
   ;; This graph will contain basic examples of different features to import
   (p/let [file-graph-dir "test/resources/exporter-test-graph"
           conn (db-test/create-conn)
@@ -208,7 +208,7 @@
 
       ;; Counts
       ;; Includes journals as property values e.g. :logseq.property/deadline
-      (is (= 28 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
+      (is (= 29 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Journal]] @conn))))
 
       (is (= 5 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Asset]] @conn))))
       (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))

+ 1 - 0
deps/graph-parser/test/resources/exporter-test-graph/journals/2025_07_15.md

@@ -0,0 +1 @@
+- Test ref to an annotation: ((68702394-3613-4bac-85a7-28643d58237f))