mirror of https://github.com/logseq/logseq
test: more remove indent test
parent
e50e129fba
commit
bea081c5b0
|
@ -75,12 +75,21 @@
|
|||
js/JSON.stringify))))
|
||||
|
||||
(defn remove-indentation-spaces
|
||||
"Remove the indentation spaces from the content. Only for markdown."
|
||||
"Remove the indentation spaces from the content. Only for markdown.
|
||||
level - ast level + 1 (2 for the first level, 3 for the second level, etc., as the non-first line of multi-line block has 2 more space
|
||||
Ex.
|
||||
- level 1 multiline block first line
|
||||
level 1 multiline block second line
|
||||
\t- level 2 multiline block first line
|
||||
\t level 2 multiline block second line
|
||||
remove-first-line? - apply the indentation removal to the first line or not"
|
||||
[s level remove-first-line?]
|
||||
(let [lines (string/split-lines s)
|
||||
[f & r] lines
|
||||
body (map (fn [line]
|
||||
;; Check if the indentation area only contains white spaces
|
||||
;; Level = ast level + 1, 1-based indentation level
|
||||
;; For markdown in Logseq, the indentation area for the non-first line of multi-line block is (ast level - 1) * "\t" + 2 * "(space)"
|
||||
(if (string/blank? (gp-util/safe-subs line 0 level))
|
||||
;; If valid, then remove the indentation area spaces. Keep the rest of the line (might contain leading spaces)
|
||||
(gp-util/safe-subs line level)
|
||||
|
|
|
@ -121,12 +121,21 @@ body"
|
|||
|
||||
(deftest remove-indentation-spaces
|
||||
(testing "Remove indentations for every line"
|
||||
(let [s "block 1.1
|
||||
(is (= "block 1.1\n line 1\n line 2\nline 3\nline 4"
|
||||
(let [s "block 1.1
|
||||
line 1
|
||||
line 2
|
||||
line 3
|
||||
line 4"]
|
||||
(= (gp-mldoc/remove-indentation-spaces s 2 false) "block 1.1\n line 1\n line 2\nline 3\nline 4"))))
|
||||
(gp-mldoc/remove-indentation-spaces s 2 false))))
|
||||
(is (= "\t- block 1.1\n line 1\n line 2\nline 3\nline 4"
|
||||
(let [s "\t- block 1.1
|
||||
\t line 1
|
||||
\t line 2
|
||||
\t line 3
|
||||
\tline 4"]
|
||||
(gp-mldoc/remove-indentation-spaces s 3 false))))))
|
||||
|
||||
|
||||
(deftest ^:integration test->edn
|
||||
(let [graph-dir "test/docs-0.9.2"
|
||||
|
|
Loading…
Reference in New Issue