diff --git a/deps/db/src/logseq/db/frontend/content.cljs b/deps/db/src/logseq/db/frontend/content.cljs index 7f1e906d6..aa0489526 100644 --- a/deps/db/src/logseq/db/frontend/content.cljs +++ b/deps/db/src/logseq/db/frontend/content.cljs @@ -3,10 +3,21 @@ (:require [clojure.string :as string] [logseq.common.util.page-ref :as page-ref] [datascript.core :as d] - [logseq.db.sqlite.util :as sqlite-util])) + [logseq.db.sqlite.util :as sqlite-util] + [logseq.common.util :as common-util])) (defonce page-ref-special-chars "~^") +(defonce special-id-ref-pattern + (re-pattern + (str + "(?i)" + "\\[\\[~\\^" + "(" + common-util/uuid-pattern + ")" + "\\]\\]"))) + (defn special-id->page "Convert special id backs to page name." [content refs] diff --git a/deps/db/src/logseq/db/frontend/entity_plus.cljc b/deps/db/src/logseq/db/frontend/entity_plus.cljc index a4e0941fa..5dc9e6d7e 100644 --- a/deps/db/src/logseq/db/frontend/entity_plus.cljc +++ b/deps/db/src/logseq/db/frontend/entity_plus.cljc @@ -19,13 +19,15 @@ (lookup-entity e :block/content default-value) (= k :block/content) - (let [result (lookup-entity e k default-value) - refs (:block/refs e) - tags (:block/tags e)] - (or - (when (string? result) - (db-content/special-id->page result (distinct (concat refs tags)))) - default-value)) + (or + (get (.-kv e) k) + (let [result (lookup-entity e k default-value) + refs (:block/refs e) + tags (:block/tags e)] + (or + (when (string? result) + (db-content/special-id->page result (distinct (concat refs tags)))) + default-value))) :else (or (get (.-kv e) k) diff --git a/deps/outliner/src/logseq/outliner/core.cljs b/deps/outliner/src/logseq/outliner/core.cljs index 7c62033ec..41d7aab6c 100644 --- a/deps/outliner/src/logseq/outliner/core.cljs +++ b/deps/outliner/src/logseq/outliner/core.cljs @@ -208,7 +208,7 @@ (reset! (:editor/create-page? @state/state) false)))) (defn ^:api rebuild-block-refs - [repo conn date-formatter block new-properties & {:keys [skip-content-parsing?]}] + [repo conn date-formatter block new-properties] (let [db @conn property-key-refs (keys new-properties) property-value-refs (->> (vals new-properties) @@ -236,16 +236,14 @@ property-refs (->> (concat property-key-refs property-value-refs) (map (fn [id-or-map] (if (uuid? id-or-map) {:block/uuid id-or-map} id-or-map))) (remove (fn [b] (nil? (d/entity db [:block/uuid (:block/uuid b)]))))) - content-refs (when-not skip-content-parsing? - (when-let [content (:block/content block)] - (gp-block/extract-refs-from-text repo db content date-formatter)))] + content-refs (when-let [content (:block/content block)] + (gp-block/extract-refs-from-text repo db content date-formatter))] (concat property-refs content-refs))) (defn- rebuild-refs [repo conn date-formatter txs-state block m] (when (sqlite-util/db-based-graph? repo) - (let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block) - :skip-content-parsing? true) + (let [refs (->> (rebuild-block-refs repo conn date-formatter block (:block/properties block)) (concat (:block/refs m)) (concat (if (seq (:block/tags m)) (:block/tags m) diff --git a/src/main/frontend/handler/db_based/property.cljs b/src/main/frontend/handler/db_based/property.cljs index 56ea096f8..47f153b1e 100644 --- a/src/main/frontend/handler/db_based/property.cljs +++ b/src/main/frontend/handler/db_based/property.cljs @@ -70,10 +70,10 @@ :default))) (defn- rebuild-block-refs - [repo block new-properties & opts] + [repo block new-properties] (let [conn (db/get-db repo false) date-formatter (state/get-date-formatter)] - (outliner-core/rebuild-block-refs repo conn date-formatter block new-properties opts))) + (outliner-core/rebuild-block-refs repo conn date-formatter block new-properties))) (defn convert-property-input-string [schema-type v-str] diff --git a/src/main/frontend/worker/rtc/core.cljs b/src/main/frontend/worker/rtc/core.cljs index e1c1dc1cd..c0d905d2e 100644 --- a/src/main/frontend/worker/rtc/core.cljs +++ b/src/main/frontend/worker/rtc/core.cljs @@ -6,6 +6,7 @@ [cljs-time.core :as t] [cljs.core.async :as async :refer [! chan go go-loop]] [clojure.set :as set] + [clojure.string :as string] [cognitect.transit :as transit] [frontend.worker.async-util :include-macros true :refer [block repo db shape page-name)]))))) +(defn- special-id-ref->page + "Convert special id ref backs to page name." + [db content] + (let [matches (distinct (re-seq db-content/special-id-ref-pattern content))] + (if (seq matches) + (reduce (fn [content [full-text id]] + (if-let [page (d/entity db [:block/uuid (uuid id)])] + (string/replace content full-text + (str page-ref/left-brackets + (:block/original-name page) + page-ref/right-brackets)) + content)) content matches) + content))) + (defn- update-block-attrs [repo conn date-formatter block-uuid {:keys [parents properties _content] :as op-value}] (let [key-set (set/intersection @@ -289,7 +310,8 @@ (cond-> b-ent (and (contains? key-set :content) (not= (:content op-value) - (:block/raw-content b-ent))) (assoc :block/content (:content op-value)) + (:block/raw-content b-ent))) (assoc :block/content + (special-id-ref->page @conn (:content op-value))) (contains? key-set :updated-at) (assoc :block/updated-at (:updated-at op-value)) (contains? key-set :created-at) (assoc :block/created-at (:created-at op-value)) (contains? key-set :alias) (assoc :block/alias (some->> (seq (:alias op-value))