summaryrefslogtreecommitdiff
path: root/src/clarktown/correctors/code_block.clj
blob: e767390033aea5d19a8441d74d2f26640c7b196f (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]
  (and (= (string/trim line) "```")
       (> index 0)
       (->> (take index lines)
            (filter #(= (string/trim %) "```"))
            count
            odd?)
       (not (= (-> (nth lines (- index 1))
                   string/trim) ""))))


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