diff options
| -rw-r--r-- | resources/test/core.md | 7 | ||||
| -rw-r--r-- | resources/test/core_result.html | 3 | ||||
| -rw-r--r-- | src/clarktown/correctors/atx_heading_block.clj | 17 |
3 files changed, 23 insertions, 4 deletions
diff --git a/resources/test/core.md b/resources/test/core.md index f65b20e..eefc4f7 100644 --- a/resources/test/core.md +++ b/resources/test/core.md @@ -79,6 +79,11 @@ This is ___bold italic text___ and ***this is also***. *What about italic text t 2. Continuing sub list item * Continuing list item +``` +code goes here. +# This is a heading. +``` + This is a H1 heading with settext ================================= @@ -90,4 +95,4 @@ Testing paragraph right before a code block code goes here ``` # Heading goes here -Paragraph right after heading
\ No newline at end of file +Paragraph right after heading diff --git a/resources/test/core_result.html b/resources/test/core_result.html index 39e8562..54273e0 100644 --- a/resources/test/core_result.html +++ b/resources/test/core_result.html @@ -56,6 +56,9 @@ function markdownToHTML(markdown) { <ul><li>List item</li><li>Another list item<ul><li>Sub list item</li><li>Another sub list item<ol><li>Sub sub list item</li><li>Continuing sub list item</li></ol></li></ul></li><li>Continuing list item</li></ul> +<pre><code>code goes here. +# This is a heading.</code></pre> + <h1>This is a H1 heading with settext</h1> <h2>And this is a H2 heading with settext</h2> 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)))) |
