Skip to content

Commit

Permalink
test: more remove indent test
Browse files Browse the repository at this point in the history
  • Loading branch information
cnrpman authored and tiensonqin committed Jun 15, 2023
1 parent e50e129 commit bea081c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
11 changes: 10 additions & 1 deletion deps/graph-parser/src/logseq/graph_parser/mldoc.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 11 additions & 2 deletions deps/graph-parser/test/logseq/graph_parser/mldoc_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit bea081c

Please sign in to comment.