(ns clarktown.parsers.heading-block
(:require
[clojure.string :as string]))
(defn is-hashbang-heading?
"Determines whether the given block is a hashbang 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 is?
"Determines whether the given block is a heading block."
[block]
(or (is-hashbang-heading? block)
(is-settext-heading? block)))
(defn render-hashbang-heading
"Renders the hashbang heading block."
[block]
(let [single-line-block (-> (string/replace block #"\n" "")
string/trim)
size (-> (string/split single-line-block #" ")
first
string/trim
count)
value (->> (string/split single-line-block #" ")
next
(string/join " ")
string/trim)]
(str "