blob: a2a948be2b660a8670ff9b210126393994e53206 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
(ns clarktown.correctors.atx-heading-block
(:require
[clojure.string :as string]
[clarktown.matchers.heading-block :refer [is-atx-heading?]]))
(defn- in-code-block?
"Determines whether the current `line` is within a code block."
[lines index]
(->> (take index lines)
(filter #(string/starts-with? (string/trim %) "```"))
count
odd?))
(defn empty-line-above?
"Determines whether there's a need for an empty new line
above the `line` at the current `index`. In the case of a
ATX heading block that starts with the `#` character, if
there's no empty newline above, we need to create one, and
so this function must then return `true`."
[lines line index]
(and (is-atx-heading? (string/trim line))
(> index 0)
(not (= (-> (nth lines (- index 1))
string/trim) ""))
(not (in-code-block? lines index))))
(defn empty-line-below?
"Determines whether there's a need for an empty new line
below the `line` at the current `index`. In the case of a
ATX heading block that starts with the `#` character, if
there's no empty newline below, we need to create one, and
so this function must then return `true`."
[lines line index]
(and (is-atx-heading? line)
(< index (- (count lines) 1))
(not (= (-> (nth lines (+ index 1))
string/trim) ""))
(not (in-code-block? lines index))))
|