From 99dc9c371c76989adddc18c0b177db5680667e52 Mon Sep 17 00:00:00 2001 From: Junyi Du Date: Thu, 13 Oct 2022 22:22:58 +0800 Subject: [PATCH 1/8] test: double queare bracket in title --- deps/graph-parser/test/logseq/graph_parser/text_test.cljs | 6 +++++- src/test/frontend/db/name_sanity_test.cljs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/deps/graph-parser/test/logseq/graph_parser/text_test.cljs b/deps/graph-parser/test/logseq/graph_parser/text_test.cljs index 3d6d0dfc1..7f921d969 100644 --- a/deps/graph-parser/test/logseq/graph_parser/text_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/text_test.cljs @@ -101,7 +101,11 @@ (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\""))) #_(cljs.test/test-ns 'logseq.graph-parser.text-test) diff --git a/src/test/frontend/db/name_sanity_test.cljs b/src/test/frontend/db/name_sanity_test.cljs index a7b56d076..95d627d9d 100644 --- a/src/test/frontend/db/name_sanity_test.cljs +++ b/src/test/frontend/db/name_sanity_test.cljs @@ -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") From c6a3eb2de091ee852323e98d488d1d37e8f27fcf Mon Sep 17 00:00:00 2001 From: Gabriel Horner Date: Thu, 13 Oct 2022 16:03:50 -0400 Subject: [PATCH 2/8] Fix title and other built-in properties incorrectly parsing refs Fixes issues in #6970. Introduced built-in property types as there are fewer to list as parsed than unparsed. Also removed test case that was incorrectly introduced in #5580 --- .../src/logseq/graph_parser/property.cljs | 42 ++++++++++++++ .../src/logseq/graph_parser/text.cljs | 56 +++++++++---------- .../test/logseq/graph_parser/text_test.cljs | 17 ++++-- .../test/logseq/graph_parser_test.cljs | 13 +---- 4 files changed, 82 insertions(+), 46 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/property.cljs b/deps/graph-parser/src/logseq/graph_parser/property.cljs index 4c10669b5..0362f9be5 100644 --- a/deps/graph-parser/src/logseq/graph_parser/property.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/property.cljs @@ -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 diff --git a/deps/graph-parser/src/logseq/graph_parser/text.cljs b/deps/graph-parser/src/logseq/graph_parser/text.cljs index df899b3be..a02f0de23 100644 --- a/deps/graph-parser/src/logseq/graph_parser/text.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/text.cljs @@ -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')))))) diff --git a/deps/graph-parser/test/logseq/graph_parser/text_test.cljs b/deps/graph-parser/test/logseq/graph_parser/text_test.cljs index 7f921d969..51b6a232a 100644 --- a/deps/graph-parser/test/logseq/graph_parser/text_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser/text_test.cljs @@ -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) @@ -102,10 +102,19 @@ (are [k v y] (= (parse-property k v {}) y) :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 "[[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) diff --git a/deps/graph-parser/test/logseq/graph_parser_test.cljs b/deps/graph-parser/test/logseq/graph_parser_test.cljs index 1c8bba302..f8df0d9bb 100644 --- a/deps/graph-parser/test/logseq/graph_parser_test.cljs +++ b/deps/graph-parser/test/logseq/graph_parser_test.cljs @@ -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) From 306886834795a3f81c7e08f59c47b65ed23874ef Mon Sep 17 00:00:00 2001 From: charlie Date: Thu, 13 Oct 2022 12:21:31 +0800 Subject: [PATCH 3/8] fix(electron): open custom protocol links as default condition --- resources/js/preload.js | 2 +- src/electron/electron/window.cljs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/js/preload.js b/resources/js/preload.js index c00029642..795e95348 100644 --- a/resources/js/preload.js +++ b/resources/js/preload.js @@ -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) { diff --git a/src/electron/electron/window.cljs b/src/electron/electron/window.cljs index 44f83f6bd..f872761e2 100644 --- a/src/electron/electron/window.cljs +++ b/src/electron/electron/window.cljs @@ -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] From 6fbe1f437b2eb67ce8c3372dfecf1099a7b6dd74 Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Thu, 13 Oct 2022 11:26:14 +0300 Subject: [PATCH 4/8] chore: add confirmation dialog --- src/electron/electron/window.cljs | 49 +++++++++++++++++++------------ 1 file changed, 30 insertions(+), 19 deletions(-) diff --git a/src/electron/electron/window.cljs b/src/electron/electron/window.cljs index f872761e2..285c2d1fe 100644 --- a/src/electron/electron/window.cljs +++ b/src/electron/electron/window.cljs @@ -4,9 +4,10 @@ [electron.configs :as cfgs] [electron.context-menu :as context-menu] [electron.logger :as logger] - ["electron" :refer [BrowserWindow app session shell] :as electron] + ["electron" :refer [BrowserWindow app session shell dialog] :as electron] ["path" :as path] ["url" :as URL] + [promesa.core :as p] [electron.state :as state] [clojure.core.async :as async] [clojure.string :as string])) @@ -24,23 +25,23 @@ ([url] (let [win-state (windowStateKeeper (clj->js {:defaultWidth 980 :defaultHeight 700})) win-opts (cond-> - {:width (.-width win-state) - :height (.-height win-state) - :frame true - :titleBarStyle "hiddenInset" - :trafficLightPosition {:x 16 :y 16} - :autoHideMenuBar (not mac?) - :webPreferences - {:plugins true ; pdf - :nodeIntegration false - :nodeIntegrationInWorker false - :webSecurity (not dev?) - :contextIsolation true - :spellcheck ((fnil identity true) (cfgs/get-item :spell-check)) + {:width (.-width win-state) + :height (.-height win-state) + :frame true + :titleBarStyle "hiddenInset" + :trafficLightPosition {:x 16 :y 16} + :autoHideMenuBar (not mac?) + :webPreferences + {:plugins true ; pdf + :nodeIntegration false + :nodeIntegrationInWorker false + :webSecurity (not dev?) + :contextIsolation true + :spellcheck ((fnil identity true) (cfgs/get-item :spell-check)) ;; Remove OverlayScrollbars and transition `.scrollbar-spacing` ;; to use `scollbar-gutter` after the feature is implemented in browsers. - :enableBlinkFeatures 'OverlayScrollbars' - :preload (path/join js/__dirname "js/preload.js")}} + :enableBlinkFeatures 'OverlayScrollbars' + :preload (path/join js/__dirname "js/preload.js")}} linux? (assoc :icon (path/join js/__dirname "icons/logseq.png"))) win (BrowserWindow. (clj->js win-opts))] @@ -53,8 +54,8 @@ origin (.-origin urlObj) requestHeaders (.-requestHeaders details)] (if (and - (.hasOwnProperty requestHeaders "referer") - (not-empty (.-referer requestHeaders))) + (.hasOwnProperty requestHeaders "referer") + (not-empty (.-referer requestHeaders))) (callback #js {:cancel false :requestHeaders requestHeaders}) (do @@ -108,6 +109,15 @@ (not= (.-id win) (.-id window)))) windows)))) +(defn unknown-protocol-open! + [protocol url default-open] + (p/let [result (.showMessageBox dialog (clj->js {:title "Unknown protocol" + :type "warning" + :message (str url "\nYou are trying to open a() " protocol " url. Are you sure you want to continue?") + :buttons ["Yes","No"]}))] + (when (zero? (.-response result)) + (default-open url)))) + (defn- open-default-app! [url default-open] (let [URL (.-URL URL) @@ -115,7 +125,8 @@ (when parsed-url (condp contains? (.-protocol parsed-url) #{"https:" "http:" "mailto:"} (.openExternal shell url) - (default-open url))))) + #{"file:" "zotero:"} (when (empty? (.-host parsed-url)) (default-open url)) + (unknown-protocol-open! (.-protocol parsed-url) url default-open))))) (defn setup-window-listeners! [^js win] From 26c2c993921760cca55486b66a5043176cf29e24 Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Thu, 13 Oct 2022 11:33:11 +0300 Subject: [PATCH 5/8] fix: typo --- src/electron/electron/window.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/electron/electron/window.cljs b/src/electron/electron/window.cljs index 285c2d1fe..e47aedc77 100644 --- a/src/electron/electron/window.cljs +++ b/src/electron/electron/window.cljs @@ -113,7 +113,7 @@ [protocol url default-open] (p/let [result (.showMessageBox dialog (clj->js {:title "Unknown protocol" :type "warning" - :message (str url "\nYou are trying to open a() " protocol " url. Are you sure you want to continue?") + :message (str url "\nYou are trying to open a(n) " protocol " url. Are you sure you want to continue?") :buttons ["Yes","No"]}))] (when (zero? (.-response result)) (default-open url)))) From 46ef0b5451028f4cc9b018f39a312208a04f51fe Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Thu, 13 Oct 2022 12:43:51 +0300 Subject: [PATCH 6/8] Revert "fix: typo" This reverts commit f1923ac6f47b88562ebb969dd68930f2c5f99ce4. --- src/electron/electron/window.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/electron/electron/window.cljs b/src/electron/electron/window.cljs index e47aedc77..285c2d1fe 100644 --- a/src/electron/electron/window.cljs +++ b/src/electron/electron/window.cljs @@ -113,7 +113,7 @@ [protocol url default-open] (p/let [result (.showMessageBox dialog (clj->js {:title "Unknown protocol" :type "warning" - :message (str url "\nYou are trying to open a(n) " protocol " url. Are you sure you want to continue?") + :message (str url "\nYou are trying to open a() " protocol " url. Are you sure you want to continue?") :buttons ["Yes","No"]}))] (when (zero? (.-response result)) (default-open url)))) From 118a0dd10ccd3769c5d9d5656f6debb9ccd3dafa Mon Sep 17 00:00:00 2001 From: Konstantinos Kaloutas Date: Thu, 13 Oct 2022 12:43:58 +0300 Subject: [PATCH 7/8] Revert "chore: add confirmation dialog" This reverts commit 0389aeac43df5ea756658dfe040b485c8407216c. --- src/electron/electron/window.cljs | 49 ++++++++++++------------------- 1 file changed, 19 insertions(+), 30 deletions(-) diff --git a/src/electron/electron/window.cljs b/src/electron/electron/window.cljs index 285c2d1fe..f872761e2 100644 --- a/src/electron/electron/window.cljs +++ b/src/electron/electron/window.cljs @@ -4,10 +4,9 @@ [electron.configs :as cfgs] [electron.context-menu :as context-menu] [electron.logger :as logger] - ["electron" :refer [BrowserWindow app session shell dialog] :as electron] + ["electron" :refer [BrowserWindow app session shell] :as electron] ["path" :as path] ["url" :as URL] - [promesa.core :as p] [electron.state :as state] [clojure.core.async :as async] [clojure.string :as string])) @@ -25,23 +24,23 @@ ([url] (let [win-state (windowStateKeeper (clj->js {:defaultWidth 980 :defaultHeight 700})) win-opts (cond-> - {:width (.-width win-state) - :height (.-height win-state) - :frame true - :titleBarStyle "hiddenInset" - :trafficLightPosition {:x 16 :y 16} - :autoHideMenuBar (not mac?) - :webPreferences - {:plugins true ; pdf - :nodeIntegration false - :nodeIntegrationInWorker false - :webSecurity (not dev?) - :contextIsolation true - :spellcheck ((fnil identity true) (cfgs/get-item :spell-check)) + {:width (.-width win-state) + :height (.-height win-state) + :frame true + :titleBarStyle "hiddenInset" + :trafficLightPosition {:x 16 :y 16} + :autoHideMenuBar (not mac?) + :webPreferences + {:plugins true ; pdf + :nodeIntegration false + :nodeIntegrationInWorker false + :webSecurity (not dev?) + :contextIsolation true + :spellcheck ((fnil identity true) (cfgs/get-item :spell-check)) ;; Remove OverlayScrollbars and transition `.scrollbar-spacing` ;; to use `scollbar-gutter` after the feature is implemented in browsers. - :enableBlinkFeatures 'OverlayScrollbars' - :preload (path/join js/__dirname "js/preload.js")}} + :enableBlinkFeatures 'OverlayScrollbars' + :preload (path/join js/__dirname "js/preload.js")}} linux? (assoc :icon (path/join js/__dirname "icons/logseq.png"))) win (BrowserWindow. (clj->js win-opts))] @@ -54,8 +53,8 @@ origin (.-origin urlObj) requestHeaders (.-requestHeaders details)] (if (and - (.hasOwnProperty requestHeaders "referer") - (not-empty (.-referer requestHeaders))) + (.hasOwnProperty requestHeaders "referer") + (not-empty (.-referer requestHeaders))) (callback #js {:cancel false :requestHeaders requestHeaders}) (do @@ -109,15 +108,6 @@ (not= (.-id win) (.-id window)))) windows)))) -(defn unknown-protocol-open! - [protocol url default-open] - (p/let [result (.showMessageBox dialog (clj->js {:title "Unknown protocol" - :type "warning" - :message (str url "\nYou are trying to open a() " protocol " url. Are you sure you want to continue?") - :buttons ["Yes","No"]}))] - (when (zero? (.-response result)) - (default-open url)))) - (defn- open-default-app! [url default-open] (let [URL (.-URL URL) @@ -125,8 +115,7 @@ (when parsed-url (condp contains? (.-protocol parsed-url) #{"https:" "http:" "mailto:"} (.openExternal shell url) - #{"file:" "zotero:"} (when (empty? (.-host parsed-url)) (default-open url)) - (unknown-protocol-open! (.-protocol parsed-url) url default-open))))) + (default-open url))))) (defn setup-window-listeners! [^js win] From 6b3d92684c268e0e25683d07644ac3c8e7e81d07 Mon Sep 17 00:00:00 2001 From: charlie Date: Sat, 15 Oct 2022 11:57:56 +0800 Subject: [PATCH 8/8] fix(pdf): turn on annotations layer for built-in contents links --- src/main/frontend/extensions/pdf/highlights.cljs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/frontend/extensions/pdf/highlights.cljs b/src/main/frontend/extensions/pdf/highlights.cljs index 240a4e9a8..985407ea4 100644 --- a/src/main/frontend/extensions/pdf/highlights.cljs +++ b/src/main/frontend/extensions/pdf/highlights.cljs @@ -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)