From e8d411b8375ef1d750adb51f60d5e77f4a9e30f8 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Fri, 27 Oct 2023 14:23:26 +0800 Subject: [PATCH] fix: typing markdown property results in a blank line Fixes LOG-2741 --- .../src/logseq/graph_parser/mldoc.cljc | 16 +++++++++++----- package.json | 2 +- src/main/frontend/format/block.cljs | 19 ++++++++++++++++--- src/main/frontend/handler/editor.cljs | 3 ++- yarn.lock | 8 ++++---- 5 files changed, 34 insertions(+), 14 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/mldoc.cljc b/deps/graph-parser/src/logseq/graph_parser/mldoc.cljc index 7bc4bf052..a3224b5d5 100644 --- a/deps/graph-parser/src/logseq/graph_parser/mldoc.cljc +++ b/deps/graph-parser/src/logseq/graph_parser/mldoc.cljc @@ -54,9 +54,9 @@ config (or references default-references))) -(defn default-config +(defn default-config-map ([format] - (default-config format {:export-heading-to-list? false})) + (default-config-map format {:export-heading-to-list? false})) ([format {:keys [export-heading-to-list? export-keep-properties? export-md-indent-style export-md-remove-options parse_outline_only?]}] (let [format (string/capitalize (name (or format :markdown)))] (->> {:toc false @@ -70,9 +70,15 @@ :export_md_remove_options (convert-export-md-remove-options export-md-remove-options)} (filter #(not (nil? (second %)))) - (into {}) - (bean/->js) - js/JSON.stringify)))) + (into {}))))) + +(defn default-config + ([format] + (default-config format {:export-heading-to-list? false})) + ([format opts] + (->> (default-config-map format opts) + bean/->js + js/JSON.stringify))) (defn remove-indentation-spaces "Remove the indentation spaces from the content. Only for markdown. diff --git a/package.json b/package.json index 068a25a4f..45bd87342 100644 --- a/package.json +++ b/package.json @@ -130,7 +130,7 @@ "jszip": "3.8.0", "katex": "^0.16.7", "marked": "^5.1.2", - "mldoc": "1.5.7", + "mldoc": "^1.5.8", "path": "0.12.7", "path-complete-extname": "1.0.0", "pdfjs-dist": "^3.9.179", diff --git a/src/main/frontend/format/block.cljs b/src/main/frontend/format/block.cljs index 2581c15e6..1862a1114 100644 --- a/src/main/frontend/format/block.cljs +++ b/src/main/frontend/format/block.cljs @@ -15,7 +15,8 @@ [lambdaisland.glogi :as log] [frontend.util :as util] [datascript.core :as d] - [logseq.db.frontend.property :as db-property])) + [logseq.db.frontend.property :as db-property] + [cljs-bean.core :as bean])) (defn- update-extracted-block-properties "Updates DB graph blocks to ensure that built-in properties are using uuids @@ -114,6 +115,16 @@ and handles unexpected failure." (remove nil?) (first))) +(defn- get-db-based-parse-config + [format] + (let [db-based? (config/db-based-graph? (state/get-current-repo))] + (->> + (cond-> (gp-mldoc/default-config-map format) + db-based? + (assoc :enable_drawers false)) + bean/->js + js/JSON.stringify))) + (defn parse-block ([block] (parse-block block nil)) @@ -122,7 +133,8 @@ and handles unexpected failure." (when-not (string/blank? content) (let [block (dissoc block :block/pre-block?) format (or format :markdown) - ast (format/to-edn content format nil) + parse-config (get-db-based-parse-config format) + ast (format/to-edn content format parse-config) blocks (extract-blocks ast content format {:with-id? with-id?}) new-block (first blocks) block (cond-> @@ -146,7 +158,8 @@ and handles unexpected failure." (str (config/get-block-pattern format) " " (string/triml content)))] (if-let [result (state/get-block-ast block-uuid content)] result - (let [ast (->> (format/to-edn content format (gp-mldoc/default-config format)) + (let [parse-config (get-db-based-parse-config format) + ast (->> (format/to-edn content format parse-config) (map first)) title (when (gp-block/heading-block? (first ast)) (:title (second (first ast)))) diff --git a/src/main/frontend/handler/editor.cljs b/src/main/frontend/handler/editor.cljs index 08cd2947f..dc1e2e3a6 100644 --- a/src/main/frontend/handler/editor.cljs +++ b/src/main/frontend/handler/editor.cljs @@ -2432,6 +2432,7 @@ current-node (outliner-core/block block) has-right? (-> (tree/-get-right current-node) (tree/satisfied-inode?)) + db-based? (config/db-based-graph? (state/get-current-repo)) thing-at-point ;intern is not supported in cljs, need a more elegant solution (or (when (thingatpt/get-setting :admonition&src?) (thingatpt/admonition&src-at-point input)) @@ -2441,7 +2442,7 @@ (thingatpt/block-ref-at-point input)) (when (thingatpt/get-setting :page-ref?) (thingatpt/page-ref-at-point input)) - (when (thingatpt/get-setting :properties?) + (when (and (not db-based?) (thingatpt/get-setting :properties?)) (thingatpt/properties-at-point input)) (when (thingatpt/get-setting :list?) (and (not (cursor/beginning-of-line? input)) diff --git a/yarn.lock b/yarn.lock index d7e9a1d0d..bccdc7f4c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5026,10 +5026,10 @@ mkdirp@^1.0.3: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== -mldoc@1.5.7: - version "1.5.7" - resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-1.5.7.tgz#9b316f633a3032ce217a339621b98e70bb229235" - integrity sha512-Ph9y8t195UWtkn0hK/VVNvi/wjZUJCLXAaUGVE80KmaE9Rwp9wWBMSEg4wPgjCac3edMjaONucD52fHOFTU9UA== +mldoc@^1.5.8: + version "1.5.8" + resolved "https://registry.yarnpkg.com/mldoc/-/mldoc-1.5.8.tgz#5433950c9124f8917075bafa4f1ed886959504c5" + integrity sha512-wNUGgwdgB/5c3GTp2qRPzWD8CpeTmA/HDlGJjTJUo2WXJttiBaz8cHQh2OdAshiLdVxteqIaSTXSPFRf7z1YRw== dependencies: yargs "^12.0.2"