summaryrefslogtreecommitdiff
path: root/src/clarktown/matchers/heading_block.clj
blob: 2295f26c9594257cebc43ecd068faba5a01812d2 (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
(ns clarktown.matchers.heading-block
  (:require
    [clojure.string :as string]))


(defn is-atx-heading?
  "Determines whether the given block is a atx heading."
  [block]
  (-> (string/replace block #"\n" "")
      string/trim
      (string/starts-with? "#")))


(defn is-settext-heading?
  "Determines whether the given block is a settext heading."
  [block]
  (let [lines (-> (string/split-lines block))
        chars (-> (last lines)
                  string/trim
                  (string/split #""))]
    (and (> (count lines) 1)
         (every? #{"-" "="} chars))))


(defn match?
  "Determines whether the given block is a heading block."
  [block]
  (or (is-atx-heading? block)
      (is-settext-heading? block)))