diff options
| author | Asko Nõmm <84135165+askonomm@users.noreply.github.com> | 2022-04-24 16:50:08 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-04-24 16:50:08 +0300 |
| commit | eafb50c2cdf7acab4d70ec81d5f30e5b8080c257 (patch) | |
| tree | aa7f6403ce50a2f6d033bea80a87b7afcceaceed /src/clarktown | |
| parent | dcb21ec0104cdec3ca9976374868c5837ad9d0b9 (diff) | |
| parent | a93aac82d2f19a1eaccfe3799d09e0438fa357eb (diff) | |
Merge pull request #19 from askonomm/18-atx-heading-block-corrector-should-check-for-code-block-presence
Do not correct ATX heading block when in code block
Diffstat (limited to 'src/clarktown')
| -rw-r--r-- | src/clarktown/correctors/atx_heading_block.clj | 17 |
1 files changed, 14 insertions, 3 deletions
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)))) |
