|
|
@@ -1,7 +1,4 @@
|
|
|
(ns logseq.graph-parser.block
|
|
|
- ;; Disable clj linters since we don't support clj
|
|
|
- #?(:clj {:clj-kondo/config {:linters {:unresolved-namespace {:level :off}
|
|
|
- :unresolved-symbol {:level :off}}}})
|
|
|
"Block related code needed for graph-parser"
|
|
|
(:require [clojure.string :as string]
|
|
|
[clojure.walk :as walk]
|
|
|
@@ -12,9 +9,7 @@
|
|
|
[logseq.graph-parser.util :as gp-util]
|
|
|
[logseq.graph-parser.config :as gp-config]
|
|
|
[logseq.graph-parser.mldoc :as gp-mldoc]
|
|
|
- [logseq.graph-parser.date-time-util :as date-time-util]
|
|
|
- #?(:org.babashka/nbb [logseq.graph-parser.log :as log]
|
|
|
- :default [lambdaisland.glogi :as log])))
|
|
|
+ [logseq.graph-parser.date-time-util :as date-time-util]))
|
|
|
|
|
|
(defn heading-block?
|
|
|
[block]
|
|
|
@@ -546,45 +541,42 @@
|
|
|
:date-formatter and :db"
|
|
|
[blocks content with-id? format {:keys [user-config] :as options}]
|
|
|
{:pre [(seq blocks) (string? content) (boolean? with-id?) (contains? #{:markdown :org} format)]}
|
|
|
- (try
|
|
|
- (let [encoded-content (utf8/encode content)
|
|
|
- [blocks body pre-block-properties]
|
|
|
- (loop [headings []
|
|
|
- blocks (reverse blocks)
|
|
|
- timestamps {}
|
|
|
- properties {}
|
|
|
- body []]
|
|
|
- (if (seq blocks)
|
|
|
- (let [[block pos-meta] (first blocks)
|
|
|
- ;; fix start_pos
|
|
|
- pos-meta (assoc pos-meta :end_pos
|
|
|
- (if (seq headings)
|
|
|
- (get-in (last headings) [:meta :start_pos])
|
|
|
- nil))]
|
|
|
- (cond
|
|
|
- (paragraph-timestamp-block? block)
|
|
|
- (let [timestamps (extract-timestamps block)
|
|
|
- timestamps' (merge timestamps timestamps)]
|
|
|
- (recur headings (rest blocks) timestamps' properties body))
|
|
|
-
|
|
|
- (gp-property/properties-ast? block)
|
|
|
- (let [properties (extract-properties format (second block) user-config)]
|
|
|
- (recur headings (rest blocks) timestamps properties body))
|
|
|
-
|
|
|
- (heading-block? block)
|
|
|
- (let [block (construct-block block properties timestamps body encoded-content format pos-meta with-id? options)]
|
|
|
- (recur (conj headings block) (rest blocks) {} {} []))
|
|
|
-
|
|
|
- :else
|
|
|
- (recur headings (rest blocks) timestamps properties (conj body block))))
|
|
|
- [(-> (reverse headings)
|
|
|
- sanity-blocks-data)
|
|
|
- body
|
|
|
- properties]))
|
|
|
- result (with-pre-block-if-exists blocks body pre-block-properties encoded-content options)]
|
|
|
- (map #(dissoc % :block/meta) result))
|
|
|
- (catch :default e
|
|
|
- (log/error :extract-blocks-failure e))))
|
|
|
+ (let [encoded-content (utf8/encode content)
|
|
|
+ [blocks body pre-block-properties]
|
|
|
+ (loop [headings []
|
|
|
+ blocks (reverse blocks)
|
|
|
+ timestamps {}
|
|
|
+ properties {}
|
|
|
+ body []]
|
|
|
+ (if (seq blocks)
|
|
|
+ (let [[block pos-meta] (first blocks)
|
|
|
+ ;; fix start_pos
|
|
|
+ pos-meta (assoc pos-meta :end_pos
|
|
|
+ (if (seq headings)
|
|
|
+ (get-in (last headings) [:meta :start_pos])
|
|
|
+ nil))]
|
|
|
+ (cond
|
|
|
+ (paragraph-timestamp-block? block)
|
|
|
+ (let [timestamps (extract-timestamps block)
|
|
|
+ timestamps' (merge timestamps timestamps)]
|
|
|
+ (recur headings (rest blocks) timestamps' properties body))
|
|
|
+
|
|
|
+ (gp-property/properties-ast? block)
|
|
|
+ (let [properties (extract-properties format (second block) user-config)]
|
|
|
+ (recur headings (rest blocks) timestamps properties body))
|
|
|
+
|
|
|
+ (heading-block? block)
|
|
|
+ (let [block (construct-block block properties timestamps body encoded-content format pos-meta with-id? options)]
|
|
|
+ (recur (conj headings block) (rest blocks) {} {} []))
|
|
|
+
|
|
|
+ :else
|
|
|
+ (recur headings (rest blocks) timestamps properties (conj body block))))
|
|
|
+ [(-> (reverse headings)
|
|
|
+ sanity-blocks-data)
|
|
|
+ body
|
|
|
+ properties]))
|
|
|
+ result (with-pre-block-if-exists blocks body pre-block-properties encoded-content options)]
|
|
|
+ (map #(dissoc % :block/meta) result)))
|
|
|
|
|
|
(defn with-parent-and-left
|
|
|
[page-id blocks]
|