diff --git a/package.json b/package.json index 1ff79c3ca0..8e6e528e74 100644 --- a/package.json +++ b/package.json @@ -82,7 +82,7 @@ "ignore": "^5.1.8", "is-svg": "4.2.2", "jszip": "^3.5.0", - "mldoc": "0.9.1", + "mldoc": "0.9.2", "path": "^0.12.7", "pixi-graph-fork": "^0.1.3", "posthog-js": "^1.10.2", diff --git a/src/main/frontend/components/export.cljs b/src/main/frontend/components/export.cljs index 6981c9e0cd..9f00c6f366 100644 --- a/src/main/frontend/components/export.cljs +++ b/src/main/frontend/components/export.cljs @@ -32,10 +32,7 @@ (t :export-json)]] [:li.mb-4 [:a.font-medium {:on-click #(export/export-repo-as-roam-json! current-repo)} - (t :export-roam-json)]] - [:li.mb-4 - [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)} - (t :convert-markdown)]]] + (t :export-roam-json)]]] [:a#download-as-edn-v2.hidden] [:a#download-as-json-v2.hidden] [:a#download-as-roam-json.hidden] diff --git a/src/main/frontend/components/header.cljs b/src/main/frontend/components/header.cljs index 08c7f38aaa..b3b02f0946 100644 --- a/src/main/frontend/components/header.cljs +++ b/src/main/frontend/components/header.cljs @@ -22,8 +22,7 @@ [frontend.handler.web.nfs :as nfs] [frontend.mixins :as mixins] [goog.dom :as gdom] - [goog.object :as gobj] - [frontend.handler.migrate :as migrate])) + [goog.object :as gobj])) (rum/defc logo < rum/reactive [{:keys [white? electron-mac?]}] @@ -138,12 +137,6 @@ :options {:href (rfe/href :import)} :icon svg/import-sm}) - (when (and current-repo - (not (:markdown/version (state/get-config)))) - {:title "Convert to more standard Markdown" - :options {:on-click (fn [] (migrate/show-convert-notification! current-repo))} - :icon svg/import-sm}) - {:title [:div.flex-row.flex.justify-between.items-center [:span (t :join-community)]] :options {:href "https://discord.gg/KpN4eHY" diff --git a/src/main/frontend/components/page.cljs b/src/main/frontend/components/page.cljs index 9e25a431ae..a00ea62de9 100644 --- a/src/main/frontend/components/page.cljs +++ b/src/main/frontend/components/page.cljs @@ -415,18 +415,20 @@ page)] (page-blocks-cp repo page {:sidebar? sidebar?}))]] + (when-not block? + (today-queries repo today? sidebar?)) + + (when-not block? + (tagged-pages repo page-name)) + + ;; referenced blocks + [:div {:key "page-references"} + (rum/with-key + (reference/references route-page-name false) + (str route-page-name "-refs"))] + (when-not block? [:div - (today-queries repo today? sidebar?) - - (tagged-pages repo page-name) - - ;; referenced blocks - [:div {:key "page-references"} - (rum/with-key - (reference/references route-page-name false) - (str route-page-name "-refs"))] - (when (text/namespace-page? route-page-name) (hierarchy/structures route-page-name)) diff --git a/src/main/frontend/config.cljs b/src/main/frontend/config.cljs index c2ded4d99b..bf7a861f1e 100644 --- a/src/main/frontend/config.cljs +++ b/src/main/frontend/config.cljs @@ -83,7 +83,7 @@ (set))] (set/union config-formats - #{:gif :svg :jpeg :ico :png :jpg :bmp}))) + #{:gif :svg :jpeg :ico :png :jpg :bmp :webp}))) (def html-render-formats #{:adoc :asciidoc}) @@ -167,7 +167,7 @@ (defn get-highlight [format] - "^^") + "==") (defn get-code [format] diff --git a/src/main/frontend/date.cljs b/src/main/frontend/date.cljs index b27d1ba4af..aa375902f0 100644 --- a/src/main/frontend/date.cljs +++ b/src/main/frontend/date.cljs @@ -26,7 +26,7 @@ [] (conj #{"do MMM yyyy" - "do MMMM yyyy" + "do MMMM yyyy" "MMM do, yyyy" "MMMM do, yyyy" "E, dd-MM-yyyy" @@ -54,6 +54,10 @@ "yyyy年MM月dd日"} (state/get-date-formatter))) +;; (tf/parse (tf/formatter "dd.MM.yyyy") "2021Q4") => 20040120T000000 +(def safe-journal-title-formatters + (set ["yyyy-MM-dd" "yyyy_MM_dd" (state/get-date-formatter)])) + (defn get-date-time-string ([] (get-date-time-string (t/now))) @@ -180,12 +184,12 @@ [journal-title then-fn] (when-not (string/blank? journal-title) (when-let [time (->> (map - (fn [formatter] - (try - (tf/parse (tf/formatter formatter) (util/capitalize-all journal-title)) - (catch js/Error _e - nil))) - (journal-title-formatters)) + (fn [formatter] + (try + (tf/parse (tf/formatter formatter) (util/capitalize-all journal-title)) + (catch js/Error _e + nil))) + safe-journal-title-formatters) (filter some?) first)] (then-fn time)))) diff --git a/src/main/frontend/db.cljs b/src/main/frontend/db.cljs index e88d79802d..57f12906d6 100644 --- a/src/main/frontend/db.cljs +++ b/src/main/frontend/db.cljs @@ -4,7 +4,6 @@ [frontend.db-schema :as db-schema] [frontend.db.conn :as conn] [frontend.db.default :as default-db] - [frontend.db.migrate :as migrate] [frontend.db.model] [frontend.db.query-custom] [frontend.db.query-react] @@ -135,9 +134,7 @@ (defn restore! [{:keys [repos] :as me} old-db-schema restore-config-handler] - (let [logged? (:name me) - ;; TODO: switch to use the db version - old-db? (and old-db-schema (not (:block/name old-db-schema)))] + (let [logged? (:name me)] (doall (for [{:keys [url]} repos] (let [repo url] @@ -148,7 +145,6 @@ stored (idb/get-item db-name) _ (if stored (let [stored-db (string->db stored) - stored-db (if old-db? (migrate/migrate url stored-db) stored-db) attached-db (d/db-with stored-db (concat [(me-tx stored-db me)] default-db/built-in-pages))] diff --git a/src/main/frontend/extensions/code.cljs b/src/main/frontend/extensions/code.cljs index f602ec31ac..6e2592fa2f 100644 --- a/src/main/frontend/extensions/code.cljs +++ b/src/main/frontend/extensions/code.cljs @@ -65,7 +65,7 @@ (let [block (db/pull [:block/uuid (:block/uuid config)]) format (:block/format block) content (property/remove-properties format (:block/content block)) - full-content (:full_content (last (:rum/args state)))] + full-content (property/remove-built-in-properties format (:full_content (last (:rum/args state))))] (when (and full-content (string/includes? content full-content)) (let [lines (string/split-lines full-content) fl (first lines) diff --git a/src/main/frontend/extensions/srs.cljs b/src/main/frontend/extensions/srs.cljs index 16b7480c13..76f0d39c8a 100644 --- a/src/main/frontend/extensions/srs.cljs +++ b/src/main/frontend/extensions/srs.cljs @@ -629,8 +629,10 @@ ;; handlers (defn make-block-a-card! [block-id] - (when-let [content (:block/content (db/entity [:block/uuid block-id]))] - (editor-handler/save-block! - (state/get-current-repo) - block-id - (str (string/trim content) " #" card-hash-tag)))) + (when-let [block (db/entity [:block/uuid block-id])] + (when-let [content (:block/content block)] + (let [content (property/remove-built-in-properties (:block/format block) content)] + (editor-handler/save-block! + (state/get-current-repo) + block-id + (str (string/trim content) " #" card-hash-tag)))))) diff --git a/src/main/frontend/handler.cljs b/src/main/frontend/handler.cljs index 83401d28e2..24195fbfff 100644 --- a/src/main/frontend/handler.cljs +++ b/src/main/frontend/handler.cljs @@ -34,11 +34,13 @@ (set! js/window.onerror (fn [message, source, lineno, colno, error] (when-not (error/ignored? message) - (notification/show! - (str "message=" message "\nsource=" source "\nlineno=" lineno "\ncolno=" colno "\nerror=" error) - :error - ;; Don't auto-hide - false))))) + (js/console.error error) + ;; (notification/show! + ;; (str "message=" message "\nsource=" source "\nlineno=" lineno "\ncolno=" colno "\nerror=" error) + ;; :error + ;; ;; Don't auto-hide + ;; false) + )))) (defn- watch-for-date! [] diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 2989e3b8ec..e6d6b75ac2 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -829,7 +829,7 @@ (when-let [sibling-block-id (dom/attr sibling-block "blockid")] (when-let [block (db/pull repo '[*] [:block/uuid (uuid sibling-block-id)])] (let [original-content (util/trim-safe (:block/content block)) - new-value (str original-content " " (string/triml value)) + new-value (str (property/remove-built-in-properties format original-content) " " (string/triml value)) tail-len (count (string/triml value)) pos (max (if original-content @@ -1498,8 +1498,8 @@ "*" "*" "_" "_" "^" "^" + "=" "=" ;; ":" ":" ; TODO: only properties editing and org mode tag - }) (def reversed-autopair-map @@ -1507,7 +1507,7 @@ (keys autopair-map))) (defonce autopair-when-selected - #{"^" "_"}) + #{"^" "_" "="}) (def delete-map (assoc autopair-map diff --git a/src/main/frontend/handler/events.cljs b/src/main/frontend/handler/events.cljs index 82d390be6f..199387d9c6 100644 --- a/src/main/frontend/handler/events.cljs +++ b/src/main/frontend/handler/events.cljs @@ -12,7 +12,6 @@ [frontend.components.encryption :as encryption] [frontend.fs.nfs :as nfs] [frontend.db.conn :as conn] - [frontend.handler.migrate :as migrate] [frontend.extensions.srs :as srs] [frontend.db-schema :as db-schema] [frontend.db :as db] @@ -60,21 +59,10 @@ ;; add ast/version to db (let [conn (conn/get-conn repo false) ast-version (d/datoms @conn :aevt :ast/version)] - (db/set-key-value repo :ast/version db-schema/ast-version)) - - ;; markdown convert notification - (js/setTimeout - (fn [] - (when (not (:markdown/version (state/get-config))) - (migrate/show-convert-notification! repo))) - 5000)) + (db/set-key-value repo :ast/version db-schema/ast-version))) (defmethod handle :graph/migrated [[_ repo]] - (js/setTimeout - (fn [] - (when (not (:markdown/version (state/get-config))) - (migrate/show-migrated-notification! repo))) - 5000)) + (js/alert "Graph migrated.")) (defn get-local-repo [] diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index e81bfb9c3c..dce3e6fb11 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -581,21 +581,6 @@ (.setAttribute anchor "download" path) (.click anchor)))))))))) -(defn convert-repo-markdown-v2! - [repo] - (when repo - (when-let [files (get-md-file-contents repo)] - (let [zip-file-name (-> (string/replace repo config/local-db-prefix "") - (string/replace #"^/+" "")) - zip-file-name (str zip-file-name - "_markdown_" - (quot (util/time-ms) 1000))] - (p/let [zipfile (zip/make-zip zip-file-name files repo)] - (when-let [anchor (gdom/getElement "convert-markdown-to-unordered-list-or-heading")] - (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile)) - (.setAttribute anchor "download" (.-name zipfile)) - (.click anchor))))))) - (defn- dissoc-properties [m ks] (if (:block/properties m) (update m :block/properties diff --git a/src/main/frontend/handler/extract.cljs b/src/main/frontend/handler/extract.cljs index 908b513b48..a75376ef6d 100644 --- a/src/main/frontend/handler/extract.cljs +++ b/src/main/frontend/handler/extract.cljs @@ -43,7 +43,10 @@ (string? title) title)) file-name (when-let [file-name (last (string/split file #"/"))] - (first (util/split-last "." file-name)))] + (let [result (first (util/split-last "." file-name))] + (if (config/mldoc-support? (string/lower-case (util/get-file-ext file))) + (string/replace result "." "/") + result)))] (or property-name (if (= (state/page-name-order) "heading") (or first-block-name file-name) diff --git a/src/main/frontend/handler/migrate.cljs b/src/main/frontend/handler/migrate.cljs deleted file mode 100644 index a18a87c614..0000000000 --- a/src/main/frontend/handler/migrate.cljs +++ /dev/null @@ -1,88 +0,0 @@ -(ns frontend.handler.migrate - (:require [frontend.handler.export :as export] - [frontend.handler.file :as file] - [frontend.handler.repo :as repo] - [frontend.handler.config :as config-handler] - [frontend.handler.notification :as notification] - [frontend.handler.web.nfs :as nfs-handler] - [frontend.handler.user :as user-handler] - [frontend.ui :as ui] - [frontend.state :as state] - [promesa.core :as p] - [clojure.string :as string])) - -(defn convert-md-files! - [repo] - (when repo - (let [files (export/get-md-file-contents repo)] - (when (seq files) - (-> (p/all (for [[path content] files] - (file/alter-file repo path content {:add-history? false - :reset? false}))) - (p/then (fn [] - (p/let [_ (repo/push repo {:commit-message "Converted to new Markdown syntax!"}) - _ (repo/re-index! nfs-handler/rebuild-index!)] - (js/setTimeout #(config-handler/set-config! :markdown/version 2) 2000) - - (notification/show! - [:div - [:p "All markdown files have been converted to the new Markdown syntax successfully!"]] - :success - false)))) - (p/catch (fn [e] - (throw e)))))))) - -(defn show-convert-notification! - [repo] - (notification/show! - [:div - [:h1 (str "Graph: " repo)] - - [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."] - - [:div - [:p.mt-2 "If you've converted this graph before, click on this button so that you won't see this notification again."] - (ui/button "Yes, it's already converted!" - :on-click (fn [] - (notification/clear-all!) - (config-handler/set-config! :markdown/version 2)))] - - [:hr] - - [:p "Let's make a backup first."] - [:p - (ui/button "Download this graph" - :on-click (fn [] - (export/export-repo-as-zip! repo)))] - - [:div - [:b "Make sure you've downloaded this graph! Now let's convert the Markdown files."] - [:p - (ui/button "Start to convert!" - :on-click (fn [] - (notification/clear-all!) - (convert-md-files! repo)))]]] - :warning - false)) - -(defn show-migrated-notification! - [repo] - (notification/show! - [:div - [:h1 (str "Graph: " repo)] - - [:p "Previously Logseq uses `#` Markdown heading as outliner bullets, since beta, we've changed to use more standard `-` unordered list as outliner bullets."] - - [:hr] - - [:p "1. Let's make a backup first."] - [:p - (ui/button "Download this graph" - :on-click (fn [] (export/export-git-repo-as-zip! repo)))] - - [:div - [:p [:b "2. Make sure you've downloaded this graph! Now click this button to logout and login again."]] - (ui/button "Logout" - :on-click user-handler/sign-out!)]] - :warning - false)) diff --git a/src/main/frontend/ui.cljs b/src/main/frontend/ui.cljs index 276b1ace7a..70b83579fb 100644 --- a/src/main/frontend/ui.cljs +++ b/src/main/frontend/ui.cljs @@ -614,11 +614,10 @@ (js/console.dir error) (assoc state ::error error))} [{error ::error, c :rum/react-component} error-view view] - (when error - (js/console.error error) - (log/error :ui/catch-error error)) - (if (and (not config/dev?) (some? error)) - error-view + (if (some? error) + (do + (log/error :exception error) + error-view) view)) (rum/defc select diff --git a/src/main/frontend/util.cljc b/src/main/frontend/util.cljc index 9c56c9bc22..f2c2352150 100644 --- a/src/main/frontend/util.cljc +++ b/src/main/frontend/util.cljc @@ -969,7 +969,7 @@ (let [user-agent js/navigator.userAgent vendor js/navigator.vendor] (and (safe-re-find #"Chrome" user-agent) - (safe-re-find #"Google Inc" user-agent))))) + (safe-re-find #"Google Inc" vendor))))) #?(:cljs (defn indexeddb-check? diff --git a/yarn.lock b/yarn.lock index 10edc8cb0a..c1db8e9051 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6165,10 +6165,10 @@ mkdirp@^0.5.0, mkdirp@^0.5.4, mkdirp@~0.5.1: dependencies: minimist "^1.2.5" -mldoc@0.9.1: - version "0.9.1" - resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.9.1.tgz#dfcdcf52614a27ce83b9318c551246398e13f0e7" - integrity sha512-4BL8Fu6+izd9iJ3JhqEU57K9W8MHUD29V51eOXa/pTpmkXi1GFSy0c9nYLkd8KjAPkI6nFVmjl7A9rcfbGe+/g== +mldoc@0.9.2: + version "0.9.2" + resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-0.9.2.tgz#0d88a049bb9564a1567134178b2dea9196f30148" + integrity sha512-e1JFKKkX6IYHFP8XwN0pqcEn2L8biVHWXGUyaUU8RHsCq2poN1fPIAZ5waosS4EffC+CQk68PycEhCobYwbndA== dependencies: yargs "^12.0.2"