From 9ac04980bd98a935c0e4bb4c2c0ce276317b9406 Mon Sep 17 00:00:00 2001 From: rcmerci Date: Thu, 18 Mar 2021 15:43:28 +0800 Subject: [PATCH] feat(export): add `export-heading-to-list?' option in config.edn --- src/main/frontend/format.cljs | 6 ++++-- src/main/frontend/format/mldoc.cljs | 19 +++++++++++-------- src/main/frontend/handler/export.cljs | 26 +++++++++++++------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/src/main/frontend/format.cljs b/src/main/frontend/format.cljs index 18e45b031e2..25382b418bd 100644 --- a/src/main/frontend/format.cljs +++ b/src/main/frontend/format.cljs @@ -33,8 +33,10 @@ ;; html (defn get-default-config - [format] - (mldoc/default-config format)) + ([format] + (mldoc/default-config format)) + ([format heading-to-list?] + (mldoc/default-config format heading-to-list?))) (defn to-html ([content format] diff --git a/src/main/frontend/format/mldoc.cljs b/src/main/frontend/format/mldoc.cljs index 4ee463d8556..fe7eaf75c24 100644 --- a/src/main/frontend/format/mldoc.cljs +++ b/src/main/frontend/format/mldoc.cljs @@ -17,14 +17,17 @@ (defonce parseAndExportMarkdown (gobj/get Mldoc "parseAndExportMarkdown")) (defn default-config - [format] - (let [format (string/capitalize (name (or format :markdown)))] - (js/JSON.stringify - (bean/->js - (assoc {:toc false - :heading_number false - :keep_line_break true} - :format format))))) + ([format] + (default-config format false)) + ([format export-heading-to-list?] + (let [format (string/capitalize (name (or format :markdown)))] + (js/JSON.stringify + (bean/->js + (assoc {:toc false + :heading_number false + :keep_line_break true} + :format format + :heading_to_list export-heading-to-list?)))))) (def default-references (js/JSON.stringify diff --git a/src/main/frontend/handler/export.cljs b/src/main/frontend/handler/export.cljs index 94575776e44..ca21d3593fc 100644 --- a/src/main/frontend/handler/export.cljs +++ b/src/main/frontend/handler/export.cljs @@ -103,13 +103,13 @@ (or (string/ends-with? path ".md"))) (db/get-file-contents repo)) (mapv (fn [[path content]] {:path path :content content - :names (d/q '[:find [?n ?n2] - :in $ ?p - :where [?e :file/path ?p] - [?e2 :page/file ?e] - [?e2 :page/name ?n] - [?e2 :page/original-name ?n2]] conn path) - :format (f/get-format path)}))))) + :names (d/q '[:find [?n ?n2] + :in $ ?p + :where [?e :file/path ?p] + [?e2 :page/file ?e] + [?e2 :page/name ?n] + [?e2 :page/original-name ?n2]] conn path) + :format (f/get-format path)}))))) (defn- get-embed-and-refs-blocks-pages-aux [repo page-or-block is-block? exclude-blocks exclude-pages] @@ -191,19 +191,19 @@ [repo] (when-let [repo (state/get-current-repo)] (when-let [files (get-file-contents-with-suffix repo)] - (let [files + (let [heading-to-list? + (boolean (:export-heading-to-list? (state/get-config))) + files (->> files (mapv (fn [{:keys [path content names format]}] (when (first names) [path (fp/exportMarkdown f/mldoc-record content - (f/get-default-config format) + (f/get-default-config format heading-to-list?) (js/JSON.stringify - (clj->js (get-embed-and-refs-blocks-pages repo (first names)))))]) - ) ) + (clj->js (get-embed-and-refs-blocks-pages repo (first names)))))]))) (remove nil?))] (p/let [zipfile (zip/make-zip repo files)] (when-let [anchor (gdom/getElement "export-as-markdown")] (.setAttribute anchor "href" (js/window.URL.createObjectURL zipfile)) (.setAttribute anchor "download" (.-name zipfile)) - (.click anchor))) - )))) + (.click anchor)))))))