fix: Extra space and tab characters will be inserted into the file

close #2108
close #2057
This commit is contained in:
Tienson Qin
2021-06-07 14:35:21 +08:00
parent 7915cf41b4
commit 7ef9150e08
3 changed files with 29 additions and 8 deletions

View File

@@ -401,14 +401,33 @@
(let [content (when content
(let [content (text/remove-level-spaces content format)]
(if (or (:pre-block? block)
(= (:format block) :org)
(src-block? block))
(= (:format block) :org))
content
(remove-indentation-spaces content (:level block)))))]
(if (= format :org)
content
(property/->new-properties content)))))
(defn- remove-indentations
[format level element]
(if (or (= level 1) (= format :org))
element
(case (first element)
"Paragraph"
["Paragraph"
(let [level (if (= (ffirst (second element)) "Plain")
(count (re-find #"^[\s\t]+" (second (first (second element)))))
level)]
(->> (partition-by #(= ["Break_Line"] %) (second element))
(map (fn [c]
(if (and (= (ffirst c) "Plain")
(>= (count (re-find #"^[\s\t]+" (second (first c)))) level))
(cons ["Plain" (subs (second (first c)) level)] (rest c))
c)))
(apply concat)))]
element)))
(defn extract-blocks
[blocks content with-id? format]
(let [encoded-content (utf8/encode content)
@@ -475,7 +494,9 @@
block (-> (assoc block
:uuid id
:body (vec (reverse block-body))
:body (vec
(->> (reverse block-body)
(map #(remove-indentations format (:level block) %))))
:properties (:properties properties)
:refs ref-pages-in-properties
:children (or current-block-children [])