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


(defn is-atx-heading?
  "Determines whether the given block is a atx heading."
  [block]
  (re-matches #"^\#{1,6}\s.*" block))


(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)))