diff options
| author | Asko Nõmm <84135165+askonomm@users.noreply.github.com> | 2022-05-01 19:53:46 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-05-01 19:53:46 +0300 |
| commit | ff2279150638b43aab4e65b2578a5dbd348e21d8 (patch) | |
| tree | 95439aa35bad656b36beede18a0ae424e2ce516b /src/clarktown/correctors | |
| parent | e8cb3717a66bf2bf3e5be815ad2c5311311c969e (diff) | |
| parent | 64fe2ecd153e6414cf33fc887604a31ee36e7952 (diff) | |
Merge pull request #28 from askonomm/27-implement-list-block-newline-correctors
Implement newline corrector for list block.
Diffstat (limited to 'src/clarktown/correctors')
| -rw-r--r-- | src/clarktown/correctors/list_block.clj | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/clarktown/correctors/list_block.clj b/src/clarktown/correctors/list_block.clj new file mode 100644 index 0000000..cf84bb1 --- /dev/null +++ b/src/clarktown/correctors/list_block.clj @@ -0,0 +1,36 @@ +(ns clarktown.correctors.list-block + (:require + [clojure.string :as string] + [clarktown.matchers.list-block :as matcher])) + + +(defn empty-line-above? + "Determines whether there's a need for an empty new line + above the `line` at the current `index`. In the list block + case that's when the above line is not a newline and is not + a list block line." + [lines line index] + (and (matcher/match? line) + (> index 0) + (nil? (-> (nth lines (- index 1)) + string/trim + matcher/match?)) + (not (= (-> (nth lines (- index 1)) + string/trim) + "")))) + + +(defn empty-line-below? + "Determines whether there's a need for an empty new line + above the `line` at the current `index`. In the list block + case that's when the below line is not a newline and is not + a list block line." + [lines line index] + (and (matcher/match? line) + (> (- (count lines) 1) index) + (nil? (-> (nth lines (+ index 1)) + string/trim + matcher/match?)) + (not (= (-> (nth lines (+ index 1)) + string/trim) + "")))) |
