From 52203a49aa544b2c11c96445d8732893160c436b Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Tue, 19 Apr 2022 17:50:19 +0300 Subject: WIP #16 Pretty much done. Needs more testing. And new documentation. --- src/clarktown/parsers/heading_block.clj | 72 --------------------------------- 1 file changed, 72 deletions(-) delete mode 100644 src/clarktown/parsers/heading_block.clj (limited to 'src/clarktown/parsers/heading_block.clj') diff --git a/src/clarktown/parsers/heading_block.clj b/src/clarktown/parsers/heading_block.clj deleted file mode 100644 index def2394..0000000 --- a/src/clarktown/parsers/heading_block.clj +++ /dev/null @@ -1,72 +0,0 @@ -(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 "" value ""))) - - -(defn render-settext-heading - "Renders the settext heading block." - [block] - (let [lines (string/split-lines block) - value (->> (split-at (- (count lines) 1) lines) - first - (string/join "\n")) - h1? (= "=" (-> (last lines) - string/trim - (string/split #"") - first))] - (if h1? - (str "

" value "

") - (str "

" value "

")))) - - -(render-settext-heading "Hello world\nAnd you too\n===") - - -(defn render - "Renders the heading block." - [block _] - (if (is-hashbang-heading? block) - (render-hashbang-heading block) - (render-settext-heading block))) -- cgit v1.2.3