diff options
Diffstat (limited to 'src/clarktown/matchers')
| -rw-r--r-- | src/clarktown/matchers/code_block.clj | 10 | ||||
| -rw-r--r-- | src/clarktown/matchers/empty_block.clj | 11 | ||||
| -rw-r--r-- | src/clarktown/matchers/heading_block.clj | 29 | ||||
| -rw-r--r-- | src/clarktown/matchers/horizontal_line_block.clj | 10 | ||||
| -rw-r--r-- | src/clarktown/matchers/list_block.clj | 10 | ||||
| -rw-r--r-- | src/clarktown/matchers/quote_block.clj | 11 |
6 files changed, 81 insertions, 0 deletions
diff --git a/src/clarktown/matchers/code_block.clj b/src/clarktown/matchers/code_block.clj new file mode 100644 index 0000000..655c951 --- /dev/null +++ b/src/clarktown/matchers/code_block.clj @@ -0,0 +1,10 @@ +(ns clarktown.matchers.code-block + (:require + [clojure.string :as string])) + + +(defn match? + "Determines whether we're dealing with a code block." + [block] + (and (string/starts-with? block "```") + (string/ends-with? block "```")))
\ No newline at end of file diff --git a/src/clarktown/matchers/empty_block.clj b/src/clarktown/matchers/empty_block.clj new file mode 100644 index 0000000..cc7b7f4 --- /dev/null +++ b/src/clarktown/matchers/empty_block.clj @@ -0,0 +1,11 @@ +(ns clarktown.matchers.empty-block + (:require + [clojure.string :as string])) + + +(defn match? + "Determines if the current block is an empty block or not." + [block] + (-> (string/replace block #"\n" "") + string/trim + string/blank?))
\ No newline at end of file diff --git a/src/clarktown/matchers/heading_block.clj b/src/clarktown/matchers/heading_block.clj new file mode 100644 index 0000000..2295f26 --- /dev/null +++ b/src/clarktown/matchers/heading_block.clj @@ -0,0 +1,29 @@ +(ns clarktown.matchers.heading-block + (:require + [clojure.string :as string])) + + +(defn is-atx-heading? + "Determines whether the given block is a atx 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 match? + "Determines whether the given block is a heading block." + [block] + (or (is-atx-heading? block) + (is-settext-heading? block)))
\ No newline at end of file diff --git a/src/clarktown/matchers/horizontal_line_block.clj b/src/clarktown/matchers/horizontal_line_block.clj new file mode 100644 index 0000000..a2dde6e --- /dev/null +++ b/src/clarktown/matchers/horizontal_line_block.clj @@ -0,0 +1,10 @@ +(ns clarktown.matchers.horizontal-line-block + (:require + [clojure.string :as string])) + + +(defn match? + "Determines whether the given block is a horizontal line block." + [block] + (or (= "***" (string/trim block)) + (= "---" (string/trim block))))
\ No newline at end of file diff --git a/src/clarktown/matchers/list_block.clj b/src/clarktown/matchers/list_block.clj new file mode 100644 index 0000000..a37b06e --- /dev/null +++ b/src/clarktown/matchers/list_block.clj @@ -0,0 +1,10 @@ +(ns clarktown.matchers.list-block + (:require + [clojure.string :as string])) + + +(defn match? + "Determines whether we're dealing with a list block or not." + [block] + (->> (string/trim block) + (re-matches #"(?s)^(\d\.\s|\*{1}\s|\-{1}\s).*$")))
\ No newline at end of file diff --git a/src/clarktown/matchers/quote_block.clj b/src/clarktown/matchers/quote_block.clj new file mode 100644 index 0000000..230b561 --- /dev/null +++ b/src/clarktown/matchers/quote_block.clj @@ -0,0 +1,11 @@ +(ns clarktown.matchers.quote-block + (:require + [clojure.string :as string])) + + +(defn match? + "Determines whether the given block is a quote block." + [block] + (-> (string/replace block #"\n" "") + string/trim + (string/starts-with? ">")))
\ No newline at end of file |
