Browse Source

feat: md export add indent-style

rcmerci 4 years ago
parent
commit
b674cda211

+ 4 - 5
src/main/frontend/components/export.cljs

@@ -68,14 +68,14 @@
 
 (def *export-block-type (atom :text))
 
-(def text-indent-style-options [{:label "dash"
+(def text-indent-style-options [{:label "dashes"
                                  :selected false}
-                                {:label "space"
+                                {:label "spaces"
                                  :selected false}
                                 {:label "no-indent"
                                  :selected false}])
 
-(def *export-block-text-indent-style (atom "dash"))
+(def *export-block-text-indent-style (atom "dashes"))
 
 (rum/defcs export-blocks
   < rum/reactive
@@ -96,8 +96,7 @@
      (ui/button "OPML"
                 :on-click #(reset! *export-block-type :opml))
      [:textarea.overflow-y-auto.h-96 {:value content}]
-     (when (and (:not-impl-yet 0)
-                (= :text type))
+     (when (= :text type)
        (let [options (->> text-indent-style-options
                           (mapv (fn [opt]
                                   (if (= text-indent-style (:label opt))

+ 2 - 4
src/main/frontend/format.cljs

@@ -35,10 +35,8 @@
 (defn get-default-config
   ([format]
    (mldoc/default-config format))
-  ([format heading-to-list?]
-   (mldoc/default-config format heading-to-list?))
-  ([format heading-to-list? exporting-keep-properties?]
-   (mldoc/default-config format heading-to-list? exporting-keep-properties?)))
+  ([format options]
+   (mldoc/default-config format options)))
 
 (defn to-html
   ([content format]

+ 13 - 19
src/main/frontend/format/mldoc.cljs

@@ -22,26 +22,20 @@
 
 (defn default-config
   ([format]
-   (default-config format false))
-  ([format export-heading-to-list?]
+   (default-config format {:export-heading-to-list? false}))
+  ([format {:keys [export-heading-to-list? export-keep-properties? export-md-indent-style]}]
    (let [format (string/capitalize (name (or format :markdown)))]
-     (js/JSON.stringify
-      (bean/->js
-       {:toc false
-        :heading_number false
-        :keep_line_break true
-        :format format
-        :heading_to_list export-heading-to-list?}))))
-  ([format export-heading-to-list? exporting-keep-properties?]
-   (let [format (string/capitalize (name (or format :markdown)))]
-     (js/JSON.stringify
-      (bean/->js
-       {:toc false
-        :heading_number false
-        :keep_line_break true
-        :format format
-        :heading_to_list export-heading-to-list?
-        :exporting_keep_properties exporting-keep-properties?})))))
+     (->> {:toc false
+           :heading_number false
+           :keep_line_break true
+           :format format
+           :heading_to_list (or export-heading-to-list? false)
+           :exporting_keep_properties export-keep-properties?
+           :export_md_indent_style export-md-indent-style}
+          (filter #(not(nil? (second %))))
+          (into {})
+          (bean/->js)
+          (js/JSON.stringify)))))
 
 (def default-references
   (js/JSON.stringify

+ 3 - 3
src/main/frontend/handler/export.cljs

@@ -423,7 +423,7 @@
          (mapv (fn [{:keys [path content names format]}]
                  (when (first names)
                    [path (fp/exportMarkdown f/mldoc-record content
-                                            (f/get-default-config format heading-to-list?)
+                                            (f/get-default-config format {:export-heading-to-list? heading-to-list?})
                                             (js/JSON.stringify
                                              (clj->js (f (first names)))))])))
          (remove nil?))))
@@ -473,7 +473,7 @@
         format (or (:block/format root-block) (state/get-preferred-format))]
     (def aa refs)
     (fp/exportMarkdown f/mldoc-record content
-                       (f/get-default-config format)
+                       (f/get-default-config format {:export-md-indent-style indent-style})
                        (js/JSON.stringify (clj->js refs)))))
 
 
@@ -484,7 +484,7 @@
        (mapv (fn [{:keys [path content names format]}]
                (when (first names)
                  [path (fp/exportMarkdown f/mldoc-record content
-                                          (f/get-default-config format heading-to-list? true)
+                                          (f/get-default-config format {:export-heading-to-list? heading-to-list? :export-keep-properties? true})
                                           nil)])))
        (remove nil?)))
 

+ 1 - 1
src/main/frontend/handler/plugin.cljs

@@ -91,7 +91,7 @@
                            (string/replace matched link (util/node-path.join url link))
                            matched)))
                       content)]
-        (format/to-html content :markdown (mldoc/default-config :markdown false))))
+        (format/to-html content :markdown (mldoc/default-config :markdown))))
     (catch js/Error e
       (log/error :parse-user-md-exception e)
       content)))