From b97891cc45b9a087a372767e25aa36788bc979bf Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 8 May 2022 12:23:35 +0300 Subject: Naming improvements, code block matcher test --- src/clarktown/correctors/atx_heading_block.clj | 4 +-- src/clarktown/correctors/code_block.clj | 37 -------------------------- src/clarktown/correctors/fenced_code_block.clj | 37 ++++++++++++++++++++++++++ src/clarktown/correctors/list_block.clj | 4 +-- 4 files changed, 41 insertions(+), 41 deletions(-) delete mode 100644 src/clarktown/correctors/code_block.clj create mode 100644 src/clarktown/correctors/fenced_code_block.clj (limited to 'src/clarktown/correctors') diff --git a/src/clarktown/correctors/atx_heading_block.clj b/src/clarktown/correctors/atx_heading_block.clj index a2a948b..6668700 100644 --- a/src/clarktown/correctors/atx_heading_block.clj +++ b/src/clarktown/correctors/atx_heading_block.clj @@ -13,7 +13,7 @@ odd?)) -(defn empty-line-above? +(defn newline-above? "Determines whether there's a need for an empty new line above the `line` at the current `index`. In the case of a ATX heading block that starts with the `#` character, if @@ -27,7 +27,7 @@ (not (in-code-block? lines index)))) -(defn empty-line-below? +(defn newline-below? "Determines whether there's a need for an empty new line below the `line` at the current `index`. In the case of a ATX heading block that starts with the `#` character, if diff --git a/src/clarktown/correctors/code_block.clj b/src/clarktown/correctors/code_block.clj deleted file mode 100644 index 73989fe..0000000 --- a/src/clarktown/correctors/code_block.clj +++ /dev/null @@ -1,37 +0,0 @@ -(ns clarktown.correctors.code-block - (:require - [clojure.string :as string])) - - -(defn empty-line-above? - "Determines whether there's a need for an empty new line - above the `line` at the current `index`. In the case of a - code block, which starts with three backticks (```), if there's - no empty newline above, we need to create one, and so this - function must then return `true`." - [lines line index] - (and (string/starts-with? (string/trim line) "```") - (> index 0) - (->> (take index lines) - (filter #(string/starts-with? (string/trim %) "```")) - count - even?) - (not (= (-> (nth lines (- index 1)) - string/trim) "")))) - - -(defn empty-line-below? - "Determines whether there's a need for an empty new line - below the `line` at the current `index`. In the case of a - code block, which ends with three backticks (```), if there's - no empty newline above, we need to create one, and so this - function must then return `true`." - [lines line index] - (and (string/starts-with? (string/trim line) "```") - (< index (- (count lines) 1)) - (->> (take index lines) - (filter #(string/starts-with? (string/trim %) "```")) - count - odd?) - (not (= (-> (nth lines (+ index 1)) - string/trim) "")))) diff --git a/src/clarktown/correctors/fenced_code_block.clj b/src/clarktown/correctors/fenced_code_block.clj new file mode 100644 index 0000000..77bc023 --- /dev/null +++ b/src/clarktown/correctors/fenced_code_block.clj @@ -0,0 +1,37 @@ +(ns clarktown.correctors.fenced-code-block + (:require + [clojure.string :as string])) + + +(defn newline-above? + "Determines whether there's a need for an empty new line + above the `line` at the current `index`. In the case of a + code block, which starts with three backticks (```), if there's + no empty newline above, we need to create one, and so this + function must then return `true`." + [lines line index] + (and (string/starts-with? (string/trim line) "```") + (> index 0) + (->> (take index lines) + (filter #(string/starts-with? (string/trim %) "```")) + count + even?) + (not (= (-> (nth lines (- index 1)) + string/trim) "")))) + + +(defn newline-below? + "Determines whether there's a need for an empty new line + below the `line` at the current `index`. In the case of a + code block, which ends with three backticks (```), if there's + no empty newline above, we need to create one, and so this + function must then return `true`." + [lines line index] + (and (string/starts-with? (string/trim line) "```") + (< index (- (count lines) 1)) + (->> (take index lines) + (filter #(string/starts-with? (string/trim %) "```")) + count + odd?) + (not (= (-> (nth lines (+ index 1)) + string/trim) "")))) diff --git a/src/clarktown/correctors/list_block.clj b/src/clarktown/correctors/list_block.clj index cf84bb1..4525ff7 100644 --- a/src/clarktown/correctors/list_block.clj +++ b/src/clarktown/correctors/list_block.clj @@ -4,7 +4,7 @@ [clarktown.matchers.list-block :as matcher])) -(defn empty-line-above? +(defn newline-above? "Determines whether there's a need for an empty new line above the `line` at the current `index`. In the list block case that's when the above line is not a newline and is not @@ -20,7 +20,7 @@ "")))) -(defn empty-line-below? +(defn newline-below? "Determines whether there's a need for an empty new line above the `line` at the current `index`. In the list block case that's when the below line is not a newline and is not -- cgit v1.2.3