summaryrefslogtreecommitdiff
path: root/src/clarktown/parsers/heading_block.clj
diff options
context:
space:
mode:
authorAsko Nõmm <84135165+askonomm@users.noreply.github.com>2022-04-23 02:43:49 +0300
committerGitHub <noreply@github.com>2022-04-23 02:43:49 +0300
commit70d88384ea788f7b2ad5ebb725762f7d27300504 (patch)
treeb371f12617949daf2b40538ba9a2e4457b657d0f /src/clarktown/parsers/heading_block.clj
parent059bfa7bd9bfdde0c75646bf1dfc20d23da8a02c (diff)
parentdc921cbe1c786995a8670efd9f5556ee9df064f9 (diff)
Merge pull request #17 from askonomm/16-improve-architecture
Improve architecture
Diffstat (limited to 'src/clarktown/parsers/heading_block.clj')
-rw-r--r--src/clarktown/parsers/heading_block.clj72
1 files changed, 0 insertions, 72 deletions
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 "<h" size ">" value "</h" size ">")))
-
-
-(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 "<h1>" value "</h1>")
- (str "<h2>" value "</h2>"))))
-
-
-(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)))