fix: import quoted math blocks

and lists in quote blocks. Addresses main issue in https://github.com/logseq/db-test/issues/434
This commit is contained in:
Gabriel Horner
2025-09-02 13:52:32 -04:00
parent 6ed338b96a
commit a81274cd0d
3 changed files with 42 additions and 2 deletions

View File

@@ -800,6 +800,32 @@
(pr-str (dissoc query-map :title :group-by-page? :collapsed?))
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
"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"
@@ -841,6 +867,14 @@
(:arguments (second node))
(and (vector? node) (= (first node) "Example"))
(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
(do
(log-fn :ast->text "Ignored ast node" :node node)

View File

@@ -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/Query]] @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))))
;; Properties and tags aren't included in this count as they aren't a Page

View File

@@ -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 theres no known classification for these exceptional values of $x$.