From a93aac82d2f19a1eaccfe3799d09e0438fa357eb Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sun, 24 Apr 2022 16:00:27 +0300 Subject: Do not correct when in code block --- src/clarktown/correctors/atx_heading_block.clj | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'src/clarktown/correctors/atx_heading_block.clj') diff --git a/src/clarktown/correctors/atx_heading_block.clj b/src/clarktown/correctors/atx_heading_block.clj index 9ff789e..361b9b9 100644 --- a/src/clarktown/correctors/atx_heading_block.clj +++ b/src/clarktown/correctors/atx_heading_block.clj @@ -3,6 +3,15 @@ [clojure.string :as string])) +(defn- in-code-block? + "Determines whether the current `line` is within a code block." + [lines index] + (->> (take index lines) + (filter #(string/starts-with? (string/trim %) "```")) + count + odd?)) + + (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 @@ -13,8 +22,9 @@ (and (string/starts-with? (string/trim line) "#") (> index 0) (not (= (-> (nth lines (- index 1)) - string/trim) "")))) - + string/trim) "")) + (not (in-code-block? lines index)))) + (defn empty-line-below? "Determines whether there's a need for an empty new line @@ -26,4 +36,5 @@ (and (string/starts-with? (string/trim line) "#") (< index (- (count lines) 1)) (not (= (-> (nth lines (+ index 1)) - string/trim) "")))) + string/trim) "")) + (not (in-code-block? lines index)))) -- cgit v1.2.3