Merge remote-tracking branch 'upstream/master' into more-pasting-issues

pull/7002/head
Peng Xiao 2022-10-17 10:31:43 +08:00
commit 907bfa2e20
8 changed files with 89 additions and 50 deletions

View File

@ -62,6 +62,48 @@
:todo :doing :now :later :done}
@built-in-extended-properties))
(def built-in-property-types
"Types for built-in properties. Built-in properties whose values are to be
parsed by gp-text/parse-non-string-property-value should be added here"
{:template-including-parent :boolean
:public :boolean
:exclude-from-graph-view :boolean
:heading :boolean
:collapsed :boolean
:created-at :integer
:created_at :integer
:updated-at :integer
:last-modified-at :integer
:last_modified_at :integer
:query-table :boolean
:query-sort-desc :boolean
:hl-page :integer
:hl-stamp :integer
:todo :integer
:doing :integer
:now :integer
:later :integer
:done :integer})
(assert (set/subset? (set (keys built-in-property-types))
(set/union (hidden-built-in-properties)
(editable-built-in-properties)))
"Keys of built-in-property-types must be valid built-in properties")
(defn unparsed-built-in-properties
"Properties whose values will not be parsed by gp-text/parse-property"
[]
(set/difference (set/union (hidden-built-in-properties)
(editable-built-in-properties))
;; Most of these need to be auto-parsed as integers so exclude
;; them until we have ones that must be unparsed
@built-in-extended-properties
;; Refs need to be parsed
editable-linkable-built-in-properties
;; All these should be parsed by gp-text/parse-non-string-property-value
(set (keys built-in-property-types))))
(defonce properties-start ":PROPERTIES:")
(defonce properties-end ":END:")
(defonce properties-end-pattern

View File

@ -78,9 +78,6 @@
(not (string/starts-with? p "./"))
(not (gp-util/url? p))))
(defonce non-parsing-properties
(atom #{"background-color" "background_color"}))
(defn parse-non-string-property-value
"Return parsed non-string property value or nil if none is found"
[v]
@ -151,38 +148,37 @@
(map second))]
(set (mapcat sep-by-comma plains))))
(defn parse-property
"Property value parsing that takes into account built-in properties, and user config"
[k v mldoc-references-ast config-state]
(defn- parse-property-refs [k v mldoc-references-ast config-state]
(let [refs (extract-refs-from-mldoc-ast mldoc-references-ast)
property-separated-by-commas? (separated-by-commas? config-state k)
refs' (if property-separated-by-commas?
(->> (extract-refs-by-commas v (get config-state :format :markdown))
(set/union refs))
refs)
k (if (or (symbol? k) (keyword? k)) (subs (str k) 1) k)
v (string/trim (str v))
non-string-property (parse-non-string-property-value v)]
property-separated-by-commas? (separated-by-commas? config-state k)]
(if property-separated-by-commas?
(->> (extract-refs-by-commas v (get config-state :format :markdown))
(set/union refs))
refs)))
(defn parse-property
"Property value parsing that takes into account built-in properties, format
and user config"
[k v mldoc-references-ast config-state]
(let [v' (string/trim (str v))]
(cond
(contains? (set/union
#{"filters" "macro"}
(get config-state :ignored-page-references-keywords)) k)
v
(set (map name (gp-property/unparsed-built-in-properties)))
(get config-state :ignored-page-references-keywords))
(name k))
v'
(@non-parsing-properties k)
v
(string/blank? v)
(string/blank? v')
nil
(and (string? v) (gp-util/wrapped-by-quotes? v))
v
(seq refs')
refs'
(some? non-string-property)
non-string-property
(gp-util/wrapped-by-quotes? v')
v'
;; parse property value as needed
:else
v)))
(let [refs (parse-property-refs k v' mldoc-references-ast config-state)]
(if (seq refs)
refs
(if-some [new-val (parse-non-string-property-value v')]
new-val
v'))))))

View File

@ -80,8 +80,8 @@
(testing "for user comma separated properties with mixed values"
(are [k v y] (= (parse-property k v {:property/separated-by-commas #{:comma-prop}}) y)
:comma-prop "foo, #bar" #{"foo", "bar"}
:comma-prop "comma, separated, [[page ref]], [[nested [[page]]]], #[[nested [[tag]]]], end" #{"page ref" "nested [[page]]" "nested [[tag]]" "comma" "separated" "end"}))
:comma-prop "foo, #bar" #{"foo", "bar"}
:comma-prop "comma, separated, [[page ref]], [[nested [[page]]]], #[[nested [[tag]]]], end" #{"page ref" "nested [[page]]" "nested [[tag]]" "comma" "separated" "end"}))
(testing "for normal properties"
(are [k v y] (= (parse-property k v {}) y)
@ -101,7 +101,20 @@
(testing "parse-property with quoted strings"
(are [k v y] (= (parse-property k v {}) y)
:tags "\"foo, bar\"" "\"foo, bar\""
:tags "\"[[foo]], [[bar]]\"" "\"[[foo]], [[bar]]\"")))
:tags "\"[[foo]], [[bar]]\"" "\"[[foo]], [[bar]]\""))
(testing "parse title property with square bracket"
(are [k v y] (= (parse-property k v {}) y)
:title "[[Jan 11th, 2022]] 21:26" "[[Jan 11th, 2022]] 21:26"
:title "[[[[aldsfkd]] a.b/c.d]]" "[[[[aldsfkd]] a.b/c.d]]"))
(testing "built-in properties parse as expected"
(are [k v y] (= (parse-property k v {}) y)
:id "62e98716-9c0b-4253-83e7-7f8e8a23fe19" "62e98716-9c0b-4253-83e7-7f8e8a23fe19"
:filters "{\"product process\" true}" "{\"product process\" true}"
:collapsed "false" false
:created-at "1609233702047" 1609233702047
:background-color "#533e7d" "#533e7d")))
#_(cljs.test/test-ns 'logseq.graph-parser.text-test)

View File

@ -65,18 +65,7 @@
@conn)
(map first)
(map :block/properties)))
"id as text has correct :block/properties"))
(let [conn (ldb/start-conn)]
(graph-parser/parse-file conn "foo.md" "- id:: [[628953c1-8d75-49fe-a648-f4c612109098]]" {})
(is (= [{:id #{"628953c1-8d75-49fe-a648-f4c612109098"}}]
(->> (d/q '[:find (pull ?b [*])
:in $
:where [?b :block/content] [(missing? $ ?b :block/name)]]
@conn)
(map first)
(map :block/properties)))
"id as linked ref has correct :block/properties")))
"id as text has correct :block/properties")))
(testing "unexpected failure during block extraction"
(let [conn (ldb/start-conn)

View File

@ -5,7 +5,7 @@ const { ipcRenderer, contextBridge, shell, clipboard, webFrame } = require('elec
const IS_MAC = process.platform === 'darwin'
const IS_WIN32 = process.platform === 'win32'
const ALLOWED_EXTERNAL_PROTOCOLS = ['https:', 'http:', 'mailto:']
const ALLOWED_EXTERNAL_PROTOCOLS = ['https:', 'http:', 'mailto:', 'zotero:', 'file:']
function getFilePathFromClipboard () {
if (IS_WIN32) {

View File

@ -115,8 +115,7 @@
(when parsed-url
(condp contains? (.-protocol parsed-url)
#{"https:" "http:" "mailto:"} (.openExternal shell url)
#{"file:"} (when (empty? (.-host parsed-url)) (default-open url))
nil))))
(default-open url)))))
(defn setup-window-listeners!
[^js win]

View File

@ -685,7 +685,7 @@
:findController (js/pdfjsViewer.PDFFindController.
#js {:linkService link-service :eventBus event-bus})
:textLayerMode 2
:annotationMode 0 ;; disabled
:annotationMode 2
:removePageBorders true})]
(. link-service setDocument pdf-document)
(. link-service setViewer viewer)

View File

@ -23,7 +23,7 @@
(is (= file-name' file-name))
(is (= file-name'' file-name)))))
(deftest ^:focus page-name-sanitization-tests
(deftest page-name-sanitization-tests
(test-page-name "Some.Content!")
(test-page-name "More _/_ Con tents")
(test-page-name "More _________/________ Con tents")