diff --git a/deps/graph-parser/src/logseq/graph_parser/block.cljs b/deps/graph-parser/src/logseq/graph_parser/block.cljs index a82e8eea4..aab34f1c9 100644 --- a/deps/graph-parser/src/logseq/graph_parser/block.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/block.cljs @@ -560,7 +560,7 @@ properties)) (defn- construct-block - [block properties timestamps body encoded-content format pos-meta {:keys [block-pattern db date-formatter parse-block]}] + [block properties timestamps body encoded-content format pos-meta {:keys [block-pattern db date-formatter parse-block remove-properties?]}] (let [id (get-custom-id-or-new-id properties) ref-pages-in-properties (->> (:page-refs properties) (remove string/blank?)) @@ -591,8 +591,10 @@ (update :properties-text-values dissoc :collapsed) (update :properties-order (fn [keys] (vec (remove #{:collapsed} keys))))) block) - block (assoc block - :block/title (get-block-content encoded-content block format pos-meta block-pattern)) + title (cond->> (get-block-content encoded-content block format pos-meta block-pattern) + remove-properties? + (gp-property/remove-properties (:format block))) + block (assoc block :block/title title) block (if (seq timestamps) (merge block (timestamps->scheduled-and-deadline timestamps)) block) @@ -679,20 +681,28 @@ (recur headings (rest blocks) (inc block-idx) timestamps properties body)) (heading-block? block) - ;; in db-graphs don't include property, deadline/scheduled or logbook text in :block/title - (let [pos-meta' (if (and db-graph-mode? - (when-let [prev-block (first (get all-blocks (dec block-idx)))] - (or (gp-property/properties-ast? prev-block) - (= ["Drawer" "logbook"] (take 2 prev-block)) - (and (= "Paragraph" (first prev-block)) - (seq (set/intersection (set (flatten prev-block)) #{"Deadline" "Scheduled"})))))) - pos-meta + ;; in db-graphs cut multi-line when there is property, deadline/scheduled or logbook text in :block/title + (let [cut-multiline? (and db-graph-mode? + (when-let [prev-block (first (get all-blocks (dec block-idx)))] + (or (and (gp-property/properties-ast? prev-block) + (not= "Custom" (ffirst (get all-blocks (- block-idx 2))))) + (= ["Drawer" "logbook"] (take 2 prev-block)) + (and (= "Paragraph" (first prev-block)) + (seq (set/intersection (set (flatten prev-block)) #{"Deadline" "Scheduled"})))))) + pos-meta' (if cut-multiline? + pos-meta ;; fix start_pos (assoc pos-meta :end_pos (if (seq headings) (get-in (last headings) [:meta :start_pos]) nil))) - block' (construct-block block properties timestamps body encoded-content format pos-meta' options) + ;; Remove properties text from custom queries in db graphs + options' (assoc options + :remove-properties? + (and db-graph-mode? + (and (gp-property/properties-ast? (first (get all-blocks (dec block-idx)))) + (= "Custom" (ffirst (get all-blocks (- block-idx 2))))))) + block' (construct-block block properties timestamps body encoded-content format pos-meta' options') block'' (if db-graph-mode? block' (assoc block' :macros (extract-macros-from-ast (cons block body))))] diff --git a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs index 30be2c4ef..614e19b8b 100644 --- a/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/exporter_test.cljs @@ -349,7 +349,9 @@ (testing "multiline blocks" (is (= "|markdown| table|\n|some|thing|" (:block/title (find-block-by-content @conn #"markdown.*table")))) (is (= "multiline block\na 2nd\nand a 3rd" (:block/title (find-block-by-content @conn #"multiline block")))) - (is (= "logbook block" (:block/title (find-block-by-content @conn #"logbook block"))))) + (is (= "logbook block" (:block/title (find-block-by-content @conn #"logbook block")))) + (is (is (re-find #"(?s)^Text before\n.*BEGIN_QUERY.*END_QUERY\nText after$" + (:block/title (find-block-by-content @conn #":title \"tasks")))))) (testing "block refs and path-refs" (let [block (find-block-by-content @conn "old todo block")] diff --git a/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_29.md b/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_29.md index b96f36f6a..587d9d853 100644 --- a/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_29.md +++ b/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_02_29.md @@ -1,10 +1,4 @@ - b1 rating:: 5 - :rating float - rating:: 5.5 -- query-table:: false - FIXME - #+BEGIN_QUERY - {:title "2nd level tasks with `#p1`" - :query (and (task todo doing) [[p1]])} - #+END_QUERY + rating:: 5.5 \ No newline at end of file diff --git a/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_08_07.md b/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_08_07.md index 5deda209a..23e8a5070 100644 --- a/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_08_07.md +++ b/deps/graph-parser/test/resources/exporter-test-graph/journals/2024_08_07.md @@ -1,6 +1,8 @@ -- test multilines +- test multilines in this page - |markdown| table| |some|thing| +- block with props + prop-num:: 10 - multiline block a 2nd and a 3rd @@ -8,4 +10,12 @@ :LOGBOOK: CLOCK: [2024-08-07 Wed 11:47:50] CLOCK: [2024-08-07 Wed 11:47:53] - :END: \ No newline at end of file + :END: +- Text before + query-table:: false + query-properties:: [:block] + #+BEGIN_QUERY + {:title "tasks with todo and doing" + :query (task todo doing)} + #+END_QUERY + Text after \ No newline at end of file