Просмотр исходного кода

fix: import quoted math blocks

and lists in quote blocks. Addresses main issue in https://github.com/logseq/db-test/issues/434
Gabriel Horner 3 месяцев назад
Родитель
Сommit
a81274cd0d

+ 34 - 0
deps/graph-parser/src/logseq/graph_parser/exporter.cljs

@@ -800,6 +800,32 @@
         (pr-str (dissoc query-map :title :group-by-page? :collapsed?))
         (pr-str (dissoc query-map :title :group-by-page? :collapsed?))
         query-str))))
         query-str))))
 
 
+(declare extract-block-list ast->text)
+(defn- extract-block-list-item
+  [{:keys [content items number checkbox]}]
+  (let [content* (mapcat #(ast->text % {}) content)
+        number* (if number
+                  (str number ". ")
+                  "* ")
+        checkbox* (if (some? checkbox)
+                    (if (boolean checkbox)
+                      "[X]" "[ ]")
+                    "")
+        items* (extract-block-list items :in-list? true)]
+    (concat [number* checkbox* " "]
+            content*
+            ["\n"]
+            items*
+            (when (seq items*) ["\n"]))))
+
+(defn- extract-block-list
+  [l & {:keys [in-list?]}]
+  (vec (concat (when-not in-list? ["\n"])
+               (mapcat extract-block-list-item l)
+               (when (and (pos? (count l))
+                          (not in-list?))
+                 ["\n\n"]))))
+
 (defn- ast->text
 (defn- ast->text
   "Given an ast block, convert it to text for use as a block title. This is a
   "Given an ast block, convert it to text for use as a block title. This is a
   slimmer version of handler.export.text/export-blocks-as-markdown"
   slimmer version of handler.export.text/export-blocks-as-markdown"
@@ -841,6 +867,14 @@
               (:arguments (second node))
               (:arguments (second node))
               (and (vector? node) (= (first node) "Example"))
               (and (vector? node) (= (first node) "Example"))
               (second node)
               (second node)
+              (and (vector? node) (= (first node) "Latex_Fragment"))
+              (let [[type' content] (second node)
+                    wrapper (case type' "Inline" "$" "Displayed" "$$")]
+                [wrapper content wrapper])
+              (and (vector? node) (= (first node) "Displayed_Math"))
+              ["$$" (second node) "$$"]
+              (and (vector? node) (= (first node) "List"))
+              (extract-block-list (second node))
               :else
               :else
               (do
               (do
                 (log-fn :ast->text "Ignored ast node" :node node)
                 (log-fn :ast->text "Ignored ast node" :node node)

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

@@ -214,7 +214,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/Task]] @conn))))
       (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Query]] @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 (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Card]] @conn))))
-      (is (= 3 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Quote-block]] @conn))))
+      (is (= 4 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Quote-block]] @conn))))
       (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Pdf-annotation]] @conn))))
       (is (= 2 (count (d/q '[:find ?b :where [?b :block/tags :logseq.class/Pdf-annotation]] @conn))))
 
 
       ;; Properties and tags aren't included in this count as they aren't a Page
       ;; Properties and tags aren't included in this count as they aren't a Page

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

@@ -1 +1,7 @@
-- Test ref to an annotation: ((68702394-3613-4bac-85a7-28643d58237f))
+- Test ref to an annotation: ((68702394-3613-4bac-85a7-28643d58237f))
+- background-color:: yellow
+    > The distribution of $x^n ~\text{mod}~ 1$ is more subtle. We have three basic facts.
+    > 
+    > 1. If $0 ≤ x < 1$, then $x^n → 0$ as $n → ∞$.
+    > 2. If $x = 1$ then $x^n = 1$ for all $n$.
+    > 3. For almost all $x > 1$ the sequence $x^n ~\text{mod}~ 1$ is uniformly distributed. But for some values of $x$ it is not, and there’s no known classification for these exceptional values of $x$.