summaryrefslogtreecommitdiff
path: root/src/clarktown/correctors/code_block.clj
blob: fcda19b6e6ba46b5f8b8c34c8d526f748a0a1e97 (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
(ns clarktown.correctors.code-block
  (:require
    [clojure.string :as string]))


(defn empty-line-above?
  [lines line index]
  (let [occurences (->> (take index lines)
                        (filter #(string/starts-with? (string/trim %) "```"))
                        count)] 
    (and (string/starts-with? (string/trim line) "```")
         (> index 0)
         (even? occurences)
         (not (= (-> (nth lines (- index 1))
                     string/trim) "")))))


(defn empty-line-below?
  [lines line index]
  (and (string/starts-with? (string/trim line) "```")
       (< index (- (count lines) 1))
       (->> (take index lines)
            (filter #(string/starts-with? (string/trim %) "```"))
            count
            odd?)
       (not (= (-> (nth lines (+ index 1))
                   string/trim) ""))))