Skip to content

Commit

Permalink
feat(export): add `export-heading-to-list?' option in config.edn
Browse files Browse the repository at this point in the history
  • Loading branch information
RCmerci committed Mar 18, 2021
1 parent e72c4c1 commit 9ac0498
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 23 deletions.
6 changes: 4 additions & 2 deletions src/main/frontend/format.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
19 changes: 11 additions & 8 deletions src/main/frontend/format/mldoc.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions src/main/frontend/handler/export.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)))))))

0 comments on commit 9ac0498

Please sign in to comment.