Browse Source

enhance: import quotes as #Quote

Can only support one quote per block so text around quotes
and multiple quotes aren't possible
Fixes https://github.com/logseq/db-test/issues/195
Gabriel Horner 8 months ago
parent
commit
5b4f43d6f4

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

@@ -930,9 +930,8 @@
           asset-name-to-uuids))
 
 (defn- handle-assets-in-block
-  [block* {:keys [assets ignored-assets]}]
-  (let [block (dissoc block* :block.temp/ast-blocks)
-        asset-links (find-all-asset-links (:block.temp/ast-blocks block*))]
+  [block {:keys [assets ignored-assets]}]
+  (let [asset-links (find-all-asset-links (:block.temp/ast-blocks block))]
     (if (seq asset-links)
       (let [asset-maps
             (keep
@@ -975,6 +974,16 @@
           (assoc :asset-blocks-tx asset-blocks)))
       {:block block})))
 
+(defn- handle-quote-in-block
+  [block]
+  ;; TODO: Use :block.temp/ast-blocks when there is a fn to convert them to text that user sees
+  (if-let [quote' (some->> (second (re-find #"(?s)#\+BEGIN_QUOTE(.*)#\+END_QUOTE" (:block/title block))) string/trim)]
+    (merge block
+           {:block/title quote'
+            :logseq.property.node/display-type :quote
+            :block/tags [:logseq.class/Quote-block]})
+    block))
+
 (defn- build-block-tx
   [db block* pre-blocks {:keys [page-names-to-uuids] :as per-file-state} {:keys [import-state journal-created-ats] :as options}]
   ;; (prn ::block-in block*)
@@ -994,12 +1003,13 @@
                    (fix-block-name-lookup-ref page-names-to-uuids)
                    (update-block-refs page-names-to-uuids options)
                    (update-block-tags db (:user-options options) per-file-state (:all-idents import-state))
+                   handle-quote-in-block
                    (update-block-marker options)
                    (update-block-priority options)
                    add-missing-timestamps
                    ;; old whiteboards may have :block/left
-                   (dissoc :block/left :block/format)
-                   ;; ((fn [x] (prn :block-out x) x))
+                   (dissoc :block/left :block/format :block.temp/ast-blocks)
+                  ;;  ((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'])))

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

@@ -212,6 +212,7 @@
       (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Task]] @conn))))
       (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @conn))))
       (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Card]] @conn))))
+      (is (= 1 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Quote-block]] @conn))))
 
       ;; Properties and tags aren't included in this count as they aren't a Page
       (is (= 10
@@ -415,7 +416,14 @@
           "Asset has correct properties")
       (is (= (d/entity @conn :logseq.class/Asset)
              (:block/page (db-test/find-block-by-content @conn "greg-popovich-thumbs-up_1704749687791_0")))
-          "Imported into Asset page"))
+          "Imported into Asset page")
+      ;; Quotes
+      (is (= {:block/tags [:logseq.class/Quote-block]
+              :logseq.property.node/display-type :quote}
+             (db-test/readable-properties (db-test/find-block-by-content @conn #"Saito"))))
+      (is (= "Saito: Cobb? Impossible. We were young men together. I'm an old man.\n...\nCobb: I've come back for you... to remind you of something. Something you once knew..."
+             (:block/title (db-test/find-block-by-content @conn #"Saito")))
+          "Quote node imports full multi-line quote"))
 
     (testing "tags convert to classes"
       (is (= :user.class/Quotes___life

+ 7 - 1
deps/graph-parser/test/resources/exporter-test-graph/journals/2025_06_12.md

@@ -2,4 +2,10 @@
   
   
   ![dino!](assets/subdir/partydino.gif){:width 105} tests an asset with a manual link, custom title and in a subdirectory
-- ![greg-popovich-thumbs-up.png](../assets/greg-popovich-thumbs-up_1704749687791_0.png){:height 288, :width 252} and ![HEART Teams](../assets/HEART_Teams.png){:width 335.99774169921875}
+- ![greg-popovich-thumbs-up.png](../assets/greg-popovich-thumbs-up_1704749687791_0.png){:height 288, :width 252} and ![HEART Teams](../assets/HEART_Teams.png){:width 335.99774169921875}
+- From Inception:
+  #+BEGIN_QUOTE
+  Saito: Cobb? Impossible. We were young men together. I'm an old man.
+  ...
+  Cobb: I've come back for you... to remind you of something. Something you once knew...
+  #+END_QUOTE