mirror of
https://github.com/logseq/logseq.git
synced 2026-02-01 22:47:36 +00:00
Move markdown property colons into a var
This commit is contained in:
committed by
Tienson Qin
parent
001e0d302d
commit
8be0deecd0
2
deps/graph-parser/.carve/ignore
vendored
2
deps/graph-parser/.carve/ignore
vendored
@@ -10,3 +10,5 @@ logseq.graph-parser.block/left-and-right-parens
|
||||
logseq.graph-parser.block/->block-ref
|
||||
;; API
|
||||
logseq.graph-parser.block/block-ref?
|
||||
;; API
|
||||
logseq.graph-parser.block/get-all-block-ref-ids
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
[goog.string :as gstring]
|
||||
[goog.string.format]))
|
||||
|
||||
(def colons "Property delimiter for markdown mode" "::")
|
||||
|
||||
(defn properties-ast?
|
||||
[block]
|
||||
(and
|
||||
@@ -77,7 +79,7 @@
|
||||
compare-k (keyword (string/lower-case k))
|
||||
k (if (contains? #{:id :custom_id :custom-id} compare-k) "id" k)
|
||||
k (if (contains? #{:last-modified-at} compare-k) "updated-at" k)]
|
||||
(str k ":: " (string/trim v)))
|
||||
(str k colons " " (string/trim v)))
|
||||
text)))))
|
||||
after (subvec lines (inc end-idx))
|
||||
lines (concat before middle after)]
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
[logseq.graph-parser.util :as gp-util]
|
||||
[logseq.graph-parser.config :as gp-config]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[goog.dom :as gdom]
|
||||
[goog.object :as gobj]
|
||||
[promesa.core :as p]))
|
||||
@@ -345,8 +346,8 @@
|
||||
(string/starts-with? last-pattern "[[")))
|
||||
(and s (string/starts-with? s "{{embed"))
|
||||
(and last-pattern
|
||||
(or (string/ends-with? last-pattern "::")
|
||||
(string/starts-with? last-pattern "::")))))))]
|
||||
(or (string/ends-with? last-pattern gp-property/colons)
|
||||
(string/starts-with? last-pattern gp-property/colons)))))))]
|
||||
(if (and space? (string/starts-with? last-pattern "#[["))
|
||||
false
|
||||
space?))
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
[frontend.util.cursor :as cursor]
|
||||
[frontend.util.keycode :as keycode]
|
||||
[logseq.graph-parser.util :as gp-util]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[goog.dom :as gdom]
|
||||
[promesa.core :as p]
|
||||
[react-draggable]
|
||||
@@ -262,7 +263,8 @@
|
||||
(not (string/blank? property)))
|
||||
(let [current-pos (cursor/pos input)
|
||||
edit-content (state/sub [:editor/content id])
|
||||
start-idx (string/last-index-of (subs edit-content 0 current-pos) "::")
|
||||
start-idx (string/last-index-of (subs edit-content 0 current-pos)
|
||||
gp-property/colons)
|
||||
q (or
|
||||
(when (>= current-pos (+ start-idx 2))
|
||||
(subs edit-content (+ start-idx 2) current-pos))
|
||||
|
||||
@@ -33,6 +33,7 @@
|
||||
[frontend.template :as template]
|
||||
[logseq.graph-parser.text :as text]
|
||||
[logseq.graph-parser.utf8 :as utf8]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[frontend.util :as util :refer [profile]]
|
||||
[frontend.util.clock :as clock]
|
||||
[frontend.util.cursor :as cursor]
|
||||
@@ -1852,9 +1853,10 @@
|
||||
|
||||
(and
|
||||
(not= :property-search (state/get-editor-action))
|
||||
(let [current-line (text-util/get-current-line-by-pos (.-value input) (dec pos))]
|
||||
(or (text-util/wrapped-by? current-line (dec pos) "" "::")
|
||||
(text-util/wrapped-by? current-line (dec pos) "\n" "::"))))
|
||||
(when-let [current-line (text-util/get-current-line-by-pos (.-value input) (dec pos))]
|
||||
(or (wrapped-by? current-line "" gp-property/colons)
|
||||
(wrapped-by? current-line "\n" gp-property/colons))))
|
||||
|
||||
(do
|
||||
(state/set-editor-action-data! {:pos (cursor/get-caret-pos input)})
|
||||
(state/set-editor-action! :property-search))
|
||||
@@ -2071,7 +2073,7 @@
|
||||
(let [value (.-value input)
|
||||
pos (util/get-selection-start input)
|
||||
postfix (subs value pos)
|
||||
end-index (when-let [idx (string/index-of postfix "::")]
|
||||
end-index (when-let [idx (string/index-of postfix gp-property/colons)]
|
||||
(+ (max 0 (count (subs value 0 pos))) idx))
|
||||
start-index (or (when-let [p (string/last-index-of (subs value 0 pos) "\n")]
|
||||
(inc p))
|
||||
@@ -2086,8 +2088,8 @@
|
||||
(when-let [input (gdom/getElement element-id)]
|
||||
(let [{:keys [end-index searching-property]} (get-searching-property input)]
|
||||
(cursor/move-cursor-to input (+ end-index 2))
|
||||
(commands/insert! element-id (str (or property q) ":: ")
|
||||
{:last-pattern (str searching-property "::")})
|
||||
(commands/insert! element-id (str (or property q) gp-property/colons " ")
|
||||
{:last-pattern (str searching-property gp-property/colons)})
|
||||
(state/clear-editor-action!)
|
||||
(js/setTimeout (fn []
|
||||
(let [pos (let [input (gdom/getElement element-id)]
|
||||
@@ -2100,8 +2102,8 @@
|
||||
(defn property-value-on-chosen-handler
|
||||
[element-id q]
|
||||
(fn [property-value]
|
||||
(commands/insert! element-id (str ":: " (or property-value q))
|
||||
{:last-pattern (str ":: " q)})
|
||||
(commands/insert! element-id (str gp-property/colons " " (or property-value q))
|
||||
{:last-pattern (str gp-property/colons " " q)})
|
||||
(state/clear-editor-action!)))
|
||||
|
||||
(defn parent-is-page?
|
||||
|
||||
@@ -36,6 +36,7 @@
|
||||
[logseq.graph-parser.util :as gp-util]
|
||||
[logseq.graph-parser.config :as gp-config]
|
||||
[logseq.graph-parser.block :as gp-block]
|
||||
[logseq.graph-parser.property :as gp-property]
|
||||
[frontend.format.block :as block]
|
||||
[goog.functions :refer [debounce]]))
|
||||
|
||||
@@ -247,8 +248,8 @@
|
||||
(defn- replace-property-ref!
|
||||
[content old-name new-name]
|
||||
(let [new-name (keyword (string/replace (string/lower-case new-name) #"\s+" "-"))
|
||||
old-property (str old-name "::")
|
||||
new-property (str (name new-name) "::")]
|
||||
old-property (str old-name gp-property/colons)
|
||||
new-property (str (name new-name) gp-property/colons)]
|
||||
(util/replace-ignore-case content old-property new-property)))
|
||||
|
||||
(defn- replace-old-page!
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
[line]
|
||||
(boolean
|
||||
(and (string? line)
|
||||
(util/safe-re-find #"^\s?[^ ]+:: " line))))
|
||||
(re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons " ")) line))))
|
||||
|
||||
(defn front-matter-property?
|
||||
[line]
|
||||
@@ -93,9 +93,10 @@
|
||||
(defn get-markdown-property-keys
|
||||
[content]
|
||||
(let [content-lines (string/split-lines content)
|
||||
properties (filter #(re-matches #"^.+::\s*.+" %) content-lines)]
|
||||
properties (filter #(re-matches (re-pattern (str "^.+" gp-property/colons "\\s*.+")) %)
|
||||
content-lines)]
|
||||
(when (seq properties)
|
||||
(map #(->> (string/split % "::")
|
||||
(map #(->> (string/split % gp-property/colons)
|
||||
(remove string/blank?)
|
||||
first
|
||||
string/upper-case)
|
||||
@@ -165,7 +166,7 @@
|
||||
[format properties]
|
||||
(when (seq properties)
|
||||
(let [org? (= format :org)
|
||||
kv-format (if org? ":%s: %s" "%s:: %s")
|
||||
kv-format (if org? ":%s: %s" (str "%s" gp-property/colons " %s"))
|
||||
full-format (if org? ":PROPERTIES:\n%s\n:END:" "%s\n")
|
||||
properties-content (->> (map (fn [[k v]] (util/format kv-format (name k) v)) properties)
|
||||
(string/join "\n"))]
|
||||
@@ -202,7 +203,7 @@
|
||||
built-in-properties-area (map (fn [[k v]]
|
||||
(if org?
|
||||
(str ":" (name k) ": " v)
|
||||
(str (name k) ":: " v))) properties)
|
||||
(str (name k) gp-property/colons " " v))) properties)
|
||||
body (concat (if no-title? nil [title])
|
||||
(when org? [properties-start])
|
||||
built-in-properties-area
|
||||
@@ -276,7 +277,7 @@
|
||||
|
||||
(not org?)
|
||||
(let [exists? (atom false)
|
||||
sym (if front-matter? ": " ":: ")
|
||||
sym (if front-matter? ": " (str gp-property/colons " "))
|
||||
new-property-s (str key sym value)
|
||||
property-f (if front-matter? front-matter-property? simplified-property?)
|
||||
groups (partition-by property-f lines)
|
||||
@@ -344,7 +345,7 @@
|
||||
(remove-f (fn [line]
|
||||
(let [s (string/triml (string/lower-case line))]
|
||||
(or (string/starts-with? s (str ":" key ":"))
|
||||
(string/starts-with? s (str key ":: ")))))))]
|
||||
(string/starts-with? s (str key gp-property/colons " ")))))))]
|
||||
(string/join "\n" lines)))))))
|
||||
|
||||
(defn remove-id-property
|
||||
|
||||
@@ -86,14 +86,14 @@
|
||||
(case (state/get-preferred-format) ;; TODO fix me to block's format
|
||||
:org (thing-at-point ":" input "\n")
|
||||
(when-let [line (:raw-content (line-at-point input))]
|
||||
(let [key (first (string/split line "::"))
|
||||
(let [key (first (string/split line gp-property/colons))
|
||||
line-beginning-pos (cursor/line-beginning-pos input)
|
||||
pos-in-line (- (cursor/pos input) line-beginning-pos)]
|
||||
(when (<= 0 pos-in-line (+ (count key) (count "::")))
|
||||
{:full-content (str key "::")
|
||||
(when (<= 0 pos-in-line (+ (count key) (count gp-property/colons)))
|
||||
{:full-content (str key gp-property/colons)
|
||||
:raw-content key
|
||||
:start line-beginning-pos
|
||||
:end (+ line-beginning-pos (count (str key "::")))}))))]
|
||||
:end (+ line-beginning-pos (count (str key gp-property/colons)))}))))]
|
||||
(assoc property :type "property-key"))))
|
||||
|
||||
(defn get-list-item-indent&bullet [line]
|
||||
|
||||
@@ -71,12 +71,20 @@
|
||||
"** hello\n\na:: b")))
|
||||
|
||||
(deftest test-get-property-keys
|
||||
(are [x y] (= x y)
|
||||
(property/get-property-keys :org "hello\n:PROPERTIES:\n:x1: y1\n:x2: y2\n:END:\n")
|
||||
["X1" "X2"]
|
||||
(testing "org mode"
|
||||
(are [x y] (= x y)
|
||||
(property/get-property-keys :org "hello\n:PROPERTIES:\n:x1: y1\n:x2: y2\n:END:\n")
|
||||
["X1" "X2"]
|
||||
|
||||
(property/get-property-keys :org "hello\n:PROPERTIES:\n:END:\n")
|
||||
nil))
|
||||
(property/get-property-keys :org "hello\n:PROPERTIES:\n:END:\n")
|
||||
nil))
|
||||
(testing "markdown mode"
|
||||
(are [x y] (= x y)
|
||||
(property/get-property-keys :markdown "hello\nx1:: y1\nx2:: y2\n")
|
||||
["X1" "X2"]
|
||||
|
||||
(property/get-property-keys :markdown "hello\n")
|
||||
nil)))
|
||||
|
||||
(deftest test-insert-property
|
||||
(are [x y] (= x y)
|
||||
|
||||
Reference in New Issue
Block a user