blob: 7cf931d4a69f60af3a844784c4492d329189d0df (
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 #"^\s{0,3}?\#{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)))
|