浏览代码

feat(copy-as/export): add option: remove-properties

rcmerci 2 年之前
父节点
当前提交
24bca5883f

+ 14 - 3
src/main/frontend/components/export.cljs

@@ -168,10 +168,10 @@
                                     (reset! *content (export-helper root-block-uuids-or-page-name)))})
                                     (reset! *content (export-helper root-block-uuids-or-page-name)))})
 
 
          [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
          [:div {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
-          "remove #tags"]
+          "remove #tags"]]
 
 
+        [:div.flex.items-center
          (ui/checkbox {:style {:margin-right 6
          (ui/checkbox {:style {:margin-right 6
-                               :margin-left "1em"
                                :visibility (if (#{:text} tp) "visible" "hidden")}
                                :visibility (if (#{:text} tp) "visible" "hidden")}
                        :checked (boolean (:newline-after-block @*text-other-options))
                        :checked (boolean (:newline-after-block @*text-other-options))
                        :on-change (fn [e]
                        :on-change (fn [e]
@@ -180,7 +180,18 @@
                                     (reset! *text-other-options (state/get-export-block-text-other-options))
                                     (reset! *text-other-options (state/get-export-block-text-other-options))
                                     (reset! *content (export-helper root-block-uuids-or-page-name)))})
                                     (reset! *content (export-helper root-block-uuids-or-page-name)))})
          [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
          [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
-          "newline after block"]]
+          "newline after block"]
+
+         (ui/checkbox {:style {:margin-right 6
+                               :margin-left "1em"
+                               :visibility (if (#{:text} tp) "visible" "hidden")}
+                       :checked (contains? @*text-remove-options :property)
+                       :on-change (fn [e]
+                                    (state/update-export-block-text-remove-options! e :property)
+                                    (reset! *text-remove-options (state/get-export-block-text-remove-options))
+                                    (reset! *content (export-helper root-block-uuids-or-page-name)))})
+         [:div {:style {:visibility (if (#{:text} tp) "visible" "hidden")}}
+          "remove properties"]]
 
 
         [:div.flex.items-center
         [:div.flex.items-center
          [:label.mr-2 {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}
          [:label.mr-2 {:style {:visibility (if (#{:text :html :opml} tp) "visible" "hidden")}}

+ 1 - 0
src/main/frontend/handler/export/common.cljs

@@ -49,6 +49,7 @@
     :remove-page-ref-brackets? false
     :remove-page-ref-brackets? false
     :remove-emphasis? false
     :remove-emphasis? false
     :remove-tags? false
     :remove-tags? false
+    :remove-properties? true
     :keep-only-level<=N :all
     :keep-only-level<=N :all
     :newline-after-block false}})
     :newline-after-block false}})
 
 

+ 1 - 2
src/main/frontend/handler/export/html.cljs

@@ -406,8 +406,7 @@
         (h/render-html hiccup)))))
         (h/render-html hiccup)))))
 
 
 (defn export-blocks-as-html
 (defn export-blocks-as-html
-  "options:
-  :remove-options [:emphasis :page-ref :tag]"
+  "options: see also `export-blocks-as-markdown`"
   [repo root-block-uuids-or-page-name options]
   [repo root-block-uuids-or-page-name options]
   {:pre [(or (coll? root-block-uuids-or-page-name)
   {:pre [(or (coll? root-block-uuids-or-page-name)
              (string? root-block-uuids-or-page-name))]}
              (string? root-block-uuids-or-page-name))]}

+ 1 - 2
src/main/frontend/handler/export/opml.cljs

@@ -426,8 +426,7 @@
         (zip-loc->opml hiccup "untitled")))))
         (zip-loc->opml hiccup "untitled")))))
 
 
 (defn export-blocks-as-opml
 (defn export-blocks-as-opml
-  "options:
-  :remove-options [:emphasis :page-ref :tag]"
+  "options: see also `export-blocks-as-markdown`"
   [repo root-block-uuids-or-page-name options]
   [repo root-block-uuids-or-page-name options]
   {:pre [(or (coll? root-block-uuids-or-page-name)
   {:pre [(or (coll? root-block-uuids-or-page-name)
              (string? root-block-uuids-or-page-name))]}
              (string? root-block-uuids-or-page-name))]}

+ 16 - 6
src/main/frontend/handler/export/text.cljs

@@ -81,6 +81,16 @@
                         (not in-list?))
                         (not in-list?))
                [(newline* 2)]))))
                [(newline* 2)]))))
 
 
+(defn- block-property-drawer
+  [properties]
+  (when-not (get-in *state* [:export-options :remove-properties?])
+    (let [level (dec (get *state* :current-level 1))
+          indent (indent-with-2-spaces level)]
+      (reduce
+       (fn [r [k v]]
+         (conj r indent (raw-text k "::") space (raw-text v) (newline* 1)))
+       [] properties))))
+
 (defn- block-example
 (defn- block-example
   [l]
   [l]
   (let [level (dec (get *state* :current-level 1))]
   (let [level (dec (get *state* :current-level 1))]
@@ -335,7 +345,7 @@
          (block-heading ast-content)
          (block-heading ast-content)
          "List"
          "List"
          (block-list ast-content)
          (block-list ast-content)
-         ("Directive" "Results" "Property_Drawer" "Export" "CommentBlock" "Custom")
+         ("Directive" "Results" "Export" "CommentBlock" "Custom")
          nil
          nil
          "Example"
          "Example"
          (block-example ast-content)
          (block-example ast-content)
@@ -351,9 +361,8 @@
          (block-displayed-math ast-content)
          (block-displayed-math ast-content)
          "Drawer"
          "Drawer"
          (block-drawer (rest block))
          (block-drawer (rest block))
-       ;; TODO: option: toggle Property_Drawer
-       ;; "Property_Drawer"
-       ;; (block-property-drawer ast-content)
+         "Property_Drawer"
+         (block-property-drawer ast-content)
          "Footnote_Definition"
          "Footnote_Definition"
          (block-footnote-definition (rest block))
          (block-footnote-definition (rest block))
          "Horizontal_Rule"
          "Horizontal_Rule"
@@ -434,6 +443,7 @@
                                :remove-emphasis? (contains? remove-options :emphasis)
                                :remove-emphasis? (contains? remove-options :emphasis)
                                :remove-page-ref-brackets? (contains? remove-options :page-ref)
                                :remove-page-ref-brackets? (contains? remove-options :page-ref)
                                :remove-tags? (contains? remove-options :tag)
                                :remove-tags? (contains? remove-options :tag)
+                               :remove-properties? (contains? remove-options :property)
                                :keep-only-level<=N (:keep-only-level<=N other-options)
                                :keep-only-level<=N (:keep-only-level<=N other-options)
                                :newline-after-block (:newline-after-block other-options)}})]
                                :newline-after-block (:newline-after-block other-options)}})]
       (let [ast (gp-mldoc/->edn content (gp-mldoc/default-config format))
       (let [ast (gp-mldoc/->edn content (gp-mldoc/default-config format))
@@ -465,8 +475,8 @@
 (defn export-blocks-as-markdown
 (defn export-blocks-as-markdown
   "options:
   "options:
   :indent-style \"dashes\" | \"spaces\" | \"no-indent\"
   :indent-style \"dashes\" | \"spaces\" | \"no-indent\"
-  :remove-options [:emphasis :page-ref :tag]
-  :other-options {:keep-only-level<=N int}"
+  :remove-options [:emphasis :page-ref :tag :property]
+  :other-options {:keep-only-level<=N int :newline-after-block bool}"
   [repo root-block-uuids-or-page-name options]
   [repo root-block-uuids-or-page-name options]
   {:pre [(or (coll? root-block-uuids-or-page-name)
   {:pre [(or (coll? root-block-uuids-or-page-name)
              (string? root-block-uuids-or-page-name))]}
              (string? root-block-uuids-or-page-name))]}