Browse Source

fix: convert - to * for repeated task states

Tienson Qin 4 years ago
parent
commit
969be00a4a

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

@@ -14,6 +14,9 @@
        [:h1.title "Export"]
 
        [:ul.mr-1
+        [:li.mb-4
+         [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)}
+          (t :convert-markdown)]]
         (when (util/electron?)
           [:li.mb-4
            [:a.font-medium {:on-click #(export/export-repo-as-html! current-repo)}
@@ -21,9 +24,6 @@
         [:li.mb-4
          [:a.font-medium {:on-click #(export/export-repo-as-markdown! current-repo)}
           (t :export-markdown)]]
-        [:li.mb-4
-         [:a.font-medium {:on-click #(export/convert-repo-markdown-v2! current-repo)}
-          (t :convert-markdown)]]
         [:li.mb-4
          [:a.font-medium {:on-click #(export/export-repo-as-edn! current-repo)}
           (t :export-edn)]]]

+ 1 - 1
src/main/frontend/dicts.cljs

@@ -243,7 +243,7 @@
         :publishing "Publishing"
         :export "Export"
         :export-json "Export as JSON"
-        :export-markdown "Export as Markdown"
+        :export-markdown "Export as standard Markdown (no block properties)"
         :export-public-pages "Export public pages"
         :export-edn "Export as EDN"
         :convert-markdown "Convert Markdown headings to unordered lists (# -> -)"

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

@@ -163,7 +163,8 @@
               (let [path (string/lower-case path)]
                 (or (string/ends-with? path ".md")
                     (string/ends-with? path ".markdown"))))
-            (get-file-contents repo {:init-level 1 :heading-to-list? true}))))
+            (get-file-contents repo {:init-level 1
+                                     :heading-to-list? true}))))
 
 (defn- get-embed-and-refs-blocks-pages-aux []
   (let [mem (atom {})]

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

@@ -28,8 +28,6 @@
          (map string/lower-case)
          (distinct))))
 
-
-
 (defn get-page-name
   [file ast]
   ;; headline
@@ -191,7 +189,9 @@
                        (fn [{:file/keys [path content]} contents]
                          (println "Parsing : " path)
                          (when content
-                           (let [utf8-content (utf8/encode content)]
+                           ;; TODO: remove `text/scheduled-deadline-dash->star` once migration is done
+                           (let [content (text/scheduled-deadline-dash->star content)
+                                 utf8-content (utf8/encode content)]
                              (extract-blocks-pages repo-url path content utf8-content)))))
                       (remove empty?))]
       (when (seq result)

+ 46 - 44
src/main/frontend/modules/file/core.cljs

@@ -21,68 +21,70 @@
     (string/join (str "\n" spaces-tabs) lines)))
 
 (defn transform-content
-  [{:block/keys [format pre-block? title content unordered body heading-level left page]} level heading-to-list?]
+  [{:block/keys [format pre-block? title content unordered body heading-level left page scheduled deadline]} level {:keys [heading-to-list?]}]
   (let [content (or content "")
         heading-with-title? (seq title)
         first-block? (= left page)
         pre-block? (and first-block? pre-block?)
-        markdown-heading? (and (= format :markdown) (not unordered) (not heading-to-list?))]
-    (cond
-      (and first-block? pre-block?)
-      (let [content (-> (string/trim content)
-                        ;; FIXME: should only works with :filters
-                        (string/replace "\"" "\\\""))]
-        (str content "\n"))
+        markdown-heading? (and (= format :markdown) (not unordered) (not heading-to-list?))
+        content (cond
+                  (and first-block? pre-block?)
+                  (let [content (-> (string/trim content)
+                                    ;; FIXME: should only works with :filters
+                                    (string/replace "\"" "\\\""))]
+                    (str content "\n"))
 
-      :else
-      (let [[prefix spaces-tabs]
-            (cond
-              (= format :org)
-              [(->>
-                (repeat level "*")
-                (apply str)) ""]
+                  :else
+                  (let [[prefix spaces-tabs]
+                        (cond
+                          (= format :org)
+                          [(->>
+                            (repeat level "*")
+                            (apply str)) ""]
 
-              markdown-heading?
-              ["" ""]
+                          markdown-heading?
+                          ["" ""]
 
-              :else
-              (let [level (if (and heading-to-list? heading-level)
-                            (if (> heading-level 1)
-                              (dec heading-level)
-                              heading-level)
-                            level)
-                    spaces-tabs (->>
-                                 (repeat (dec level) (state/get-export-bullet-indentation))
-                                 (apply str))]
-                [(str spaces-tabs "-") (str spaces-tabs "  ")]))
-            content (if heading-to-list?
-                      (-> (string/replace content #"^\s?#+\s+" "")
-                          (string/replace #"^\s?#+\s?$" ""))
-                      content)
-            new-content (indented-block-content (string/trim content) spaces-tabs)
-            sep (cond
-                  markdown-heading?
-                  ""
+                          :else
+                          (let [level (if (and heading-to-list? heading-level)
+                                        (if (> heading-level 1)
+                                          (dec heading-level)
+                                          heading-level)
+                                        level)
+                                spaces-tabs (->>
+                                             (repeat (dec level) (state/get-export-bullet-indentation))
+                                             (apply str))]
+                            [(str spaces-tabs "-") (str spaces-tabs "  ")]))
+                        content (if heading-to-list?
+                                  (-> (string/replace content #"^\s?#+\s+" "")
+                                      (string/replace #"^\s?#+\s?$" ""))
+                                  content)
+                        new-content (indented-block-content (string/trim content) spaces-tabs)
+                        sep (cond
+                              markdown-heading?
+                              ""
 
-                  heading-with-title?
-                  " "
+                              heading-with-title?
+                              " "
 
-                  (string/blank? new-content)
-                  ""
+                              (string/blank? new-content)
+                              ""
 
-                  :else
-                  (str "\n" spaces-tabs))]
-        (str prefix sep new-content)))))
+                              :else
+                              (str "\n" spaces-tabs))]
+                    (str prefix sep new-content)))]
+    content))
 
 (defn tree->file-content
   [tree {:keys [init-level heading-to-list?]
-         :or {heading-to-list? false}}]
+         :or {heading-to-list? false}
+         :as opts}]
   (loop [block-contents []
          [f & r] tree
          level init-level]
     (if (nil? f)
       (string/join "\n" block-contents)
-      (let [content (transform-content f level heading-to-list?)
+      (let [content (transform-content f level opts)
             new-content
             (if-let [children (seq (:block/children f))]
               [content (tree->file-content children {:init-level (inc level)})]

+ 8 - 0
src/main/frontend/text.cljs

@@ -145,3 +145,11 @@
 (defn image-link?
   [img-formats s]
   (some (fn [fmt] (util/safe-re-find (re-pattern (str "(?i)\\." fmt "(?:\\?([^#]*))?(?:#(.*))?$")) s)) img-formats))
+
+(defn scheduled-deadline-dash->star
+  [content]
+  (-> content
+      (string/replace "- TODO -> DONE [" "* TODO -> DONE [")
+      (string/replace "- DOING -> DONE [" "* DOING -> DONE [")
+      (string/replace "- LATER -> DONE [" "* LATER -> DONE [")
+      (string/replace "- NOW -> DONE [" "* NOW -> DONE [")))