diff options
14 files changed, 65 insertions, 55 deletions
diff --git a/src/clarktown/correctors.clj b/src/clarktown/correctors.clj index 1a61f2d..6b7cc1c 100644 --- a/src/clarktown/correctors.clj +++ b/src/clarktown/correctors.clj @@ -1,6 +1,6 @@ (ns clarktown.correctors (:require - [clarktown.correctors.code-block :as code-block] + [clarktown.correctors.fenced-code-block :as fenced-code-block] [clarktown.correctors.atx-heading-block :as atx-heading-block] [clarktown.correctors.list-block :as list-block])) @@ -9,13 +9,13 @@ ^{:doc "The default block separation correctors."} default-block-separation-correctors {:newline-above - [code-block/empty-line-above? - atx-heading-block/empty-line-above? - list-block/empty-line-above?] + [fenced-code-block/newline-above? + atx-heading-block/newline-above? + list-block/newline-above?] :newline-below - [code-block/empty-line-below? - atx-heading-block/empty-line-below? - list-block/empty-line-below?]}) + [fenced-code-block/newline-below? + atx-heading-block/newline-below? + list-block/newline-below?]}) (def 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/fenced_code_block.clj index 73989fe..77bc023 100644 --- a/src/clarktown/correctors/code_block.clj +++ b/src/clarktown/correctors/fenced_code_block.clj @@ -1,9 +1,9 @@ -(ns clarktown.correctors.code-block +(ns clarktown.correctors.fenced-code-block (:require [clojure.string :as string])) -(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 code block, which starts with three backticks (```), if there's @@ -20,7 +20,7 @@ string/trim) "")))) -(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 code block, which ends with three backticks (```), if there's 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 diff --git a/src/clarktown/engine.clj b/src/clarktown/engine.clj index eaa0fb0..5eb22d5 100644 --- a/src/clarktown/engine.clj +++ b/src/clarktown/engine.clj @@ -3,7 +3,7 @@ [clojure.string :as string])) -(defn- stitch-code-blocks +(defn- stitch-fenced-code-blocks "Since code blocks can span multiple blocks (a block is separated by two line breaks from another block) , we need to stitch them together into one block in order for a block parser to be able to do anything @@ -144,6 +144,6 @@ [markdown given-parsers given-correctors] (let [blocks (-> (correct-markdown markdown given-correctors) (string/split #"\n\n") - stitch-code-blocks) + stitch-fenced-code-blocks) parsed-blocks (parse-blocks blocks given-parsers given-correctors)] (string/join "\n\n" parsed-blocks))) diff --git a/src/clarktown/matchers/code_block.clj b/src/clarktown/matchers/fenced_code_block.clj index 655c951..9bbcdca 100644 --- a/src/clarktown/matchers/code_block.clj +++ b/src/clarktown/matchers/fenced_code_block.clj @@ -1,4 +1,4 @@ -(ns clarktown.matchers.code-block +(ns clarktown.matchers.fenced-code-block (:require [clojure.string :as string])) @@ -7,4 +7,4 @@ "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 + (string/ends-with? block "```"))) diff --git a/src/clarktown/parsers.clj b/src/clarktown/parsers.clj index 77c9794..0d3b019 100644 --- a/src/clarktown/parsers.clj +++ b/src/clarktown/parsers.clj @@ -8,8 +8,8 @@ [clarktown.renderers.heading-block] [clarktown.matchers.quote-block] [clarktown.renderers.quote-block] - [clarktown.matchers.code-block] - [clarktown.renderers.code-block] + [clarktown.matchers.fenced-code-block] + [clarktown.renderers.fenced-code-block] [clarktown.matchers.list-block] [clarktown.renderers.list-block] [clarktown.renderers.paragraph-block] @@ -54,10 +54,10 @@ (def - ^{:doc "Detects, parses and renders a code block."} - code-block-parser - {:matcher clarktown.matchers.code-block/match? - :renderers [clarktown.renderers.code-block/render]}) + ^{:doc "Detects, parses and renders a fenced code block."} + fenced-code-block-parser + {:matcher clarktown.matchers.fenced-code-block/match? + :renderers [clarktown.renderers.fenced-code-block/render]}) (def @@ -90,6 +90,6 @@ horizontal-line-block-parser heading-block-parser quote-block-parser - code-block-parser + fenced-code-block-parser list-block-parser paragraph-block-parser]) diff --git a/src/clarktown/renderers/code_block.clj b/src/clarktown/renderers/fenced_code_block.clj index 184e90e..905c061 100644 --- a/src/clarktown/renderers/code_block.clj +++ b/src/clarktown/renderers/fenced_code_block.clj @@ -1,4 +1,4 @@ -(ns clarktown.renderers.code-block +(ns clarktown.renderers.fenced-code-block (:require [clojure.string :as string])) diff --git a/test/clarktown/correctors/atx_heading_block_test.clj b/test/clarktown/correctors/atx_heading_block_test.clj index 3ece304..f363ad0 100644 --- a/test/clarktown/correctors/atx_heading_block_test.clj +++ b/test/clarktown/correctors/atx_heading_block_test.clj @@ -9,22 +9,22 @@ (let [line "# Hello" lines ["Some text goes here" line] index 1] - (is (true? (corrector/empty-line-above? lines line index))))) + (is (true? (corrector/newline-above? lines line index))))) (testing "No empty line above" (let [line "# Hello" lines ["Some text goes here" "\n" line] index 2] - (is (false? (corrector/empty-line-above? lines line index))))) + (is (false? (corrector/newline-above? lines line index))))) (testing "Empty line below" (let [line "# Hello" lines [line "Some text goes here"] index 0] - (is (true? (corrector/empty-line-below? lines line index))))) + (is (true? (corrector/newline-below? lines line index))))) (testing "No empty line below" (let [line "# Hello" lines [line "\n" "Some text goes here"] index 0] - (is (false? (corrector/empty-line-below? lines line index)))))) + (is (false? (corrector/newline-below? lines line index)))))) diff --git a/test/clarktown/correctors/code_block_test.clj b/test/clarktown/correctors/fenced_code_block_test.clj index 16711da..a0f9a41 100644 --- a/test/clarktown/correctors/code_block_test.clj +++ b/test/clarktown/correctors/fenced_code_block_test.clj @@ -1,37 +1,37 @@ -(ns clarktown.correctors.code-block-test +(ns clarktown.correctors.fenced-code-block-test (:require [clojure.test :refer [deftest testing is]] - [clarktown.correctors.code-block :as corrector])) + [clarktown.correctors.fenced-code-block :as corrector])) -(deftest code-block-corrector +(deftest fenced-code-block-corrector-test (testing "Empty line above" (let [line "```clojure" lines ["Some text goes here" line "some code here" "```"] index 1] - (is (true? (corrector/empty-line-above? lines line index))))) + (is (true? (corrector/newline-above? lines line index))))) (testing "No empty line above" (let [line "```" lines ["Some text goes here" "\n" line "some code" "```"] index 2] - (is (false? (corrector/empty-line-above? lines line index))))) + (is (false? (corrector/newline-above? lines line index))))) (testing "Empty line below" (let [line "```" lines ["Some text goes here" line "some code" line "some text"] index 3] - (is (true? (corrector/empty-line-below? lines line index))))) + (is (true? (corrector/newline-below? lines line index))))) (testing "No empty line below" (let [line "```" lines ["Some text goes here" line "some code" line "\n" "some text"] index 3] - (is (false? (corrector/empty-line-below? lines line index))))) + (is (false? (corrector/newline-below? lines line index))))) (testing "No empty line below when ending with code block" (let [line "```" lines ["Some text goes here" line "some code" line] index 3] - (is (false? (corrector/empty-line-below? lines line index)))))) + (is (false? (corrector/newline-below? lines line index)))))) diff --git a/test/clarktown/correctors/list_block_test.clj b/test/clarktown/correctors/list_block_test.clj index d435caf..54ff94e 100644 --- a/test/clarktown/correctors/list_block_test.clj +++ b/test/clarktown/correctors/list_block_test.clj @@ -9,58 +9,58 @@ (let [line "1. Hello" lines ["Some text goes here" line] index 1] - (is (true? (corrector/empty-line-above? lines line index))))) + (is (true? (corrector/newline-above? lines line index))))) (testing "Empty line above II" (let [line "* Hello" lines ["Some text goes here" line] index 1] - (is (true? (corrector/empty-line-above? lines line index))))) + (is (true? (corrector/newline-above? lines line index))))) (testing "No empty line above" (let [line "1. Hello" lines ["Some text goes here" "\n" line] index 2] - (is (false? (corrector/empty-line-above? lines line index))))) + (is (false? (corrector/newline-above? lines line index))))) (testing "No empty line above II" (let [line "* Hello" lines ["Some text goes here" "\n" line] index 2] - (is (false? (corrector/empty-line-above? lines line index))))) + (is (false? (corrector/newline-above? lines line index))))) (testing "No empty line above III" (let [line "* Hello" lines ["Some text here" "* Asd" line] index 2] - (is (false? (corrector/empty-line-above? lines line index))))) + (is (false? (corrector/newline-above? lines line index))))) (testing "Empty line below" (let [line "1. Hello" lines [line "Some text goes here"] index 0] - (is (true? (corrector/empty-line-below? lines line index))))) + (is (true? (corrector/newline-below? lines line index))))) (testing "Empty line below II" (let [line "* Hello" lines [line "Some text goes here"] index 0] - (is (true? (corrector/empty-line-below? lines line index))))) + (is (true? (corrector/newline-below? lines line index))))) (testing "No empty line below" (let [line "1. Hello" lines [line "\n" "Some text goes here"] index 0] - (is (false? (corrector/empty-line-below? lines line index))))) + (is (false? (corrector/newline-below? lines line index))))) (testing "No empty line below II" (let [line "* Hello" lines [line "\n" "Some text goes here"] index 0] - (is (false? (corrector/empty-line-below? lines line index))))) + (is (false? (corrector/newline-below? lines line index))))) (testing "No empty line below III" (let [line "* Hello" lines [line "* Asd" "Some text goes here"] index 0] - (is (false? (corrector/empty-line-below? lines line index)))))) + (is (false? (corrector/newline-below? lines line index)))))) diff --git a/test/clarktown/matchers/fenced_code_block_test.clj b/test/clarktown/matchers/fenced_code_block_test.clj new file mode 100644 index 0000000..5961c6d --- /dev/null +++ b/test/clarktown/matchers/fenced_code_block_test.clj @@ -0,0 +1,10 @@ +(ns clarktown.matchers.fenced-code-block-test + (:require + [clojure.test :refer [deftest testing is]] + [clarktown.matchers.fenced-code-block :as code-block])) + + +(deftest fenced-code-block-matcher-test + (testing "Checking a fenced code block" + (is (true? (code-block/match? "```\nblabla```"))) + (is (true? (code-block/match? "```language-spec\nblabla```"))))) diff --git a/test/clarktown/matchers/quote_block_test.clj b/test/clarktown/matchers/quote_block_test.clj index 05288d6..d4c9067 100644 --- a/test/clarktown/matchers/quote_block_test.clj +++ b/test/clarktown/matchers/quote_block_test.clj @@ -4,7 +4,7 @@ [clarktown.matchers.quote-block :as quote-block])) -(deftest quote-block-block-matcher-test +(deftest quote-block-matcher-test (testing "Checking a quote block" (is (true? (quote-block/match? "> Test"))) (is (true? (quote-block/match? " > Test"))) diff --git a/test/clarktown/renderers/code_block_test.clj b/test/clarktown/renderers/fenced_code_block_test.clj index c5779be..9a7f4cc 100644 --- a/test/clarktown/renderers/code_block_test.clj +++ b/test/clarktown/renderers/fenced_code_block_test.clj @@ -1,15 +1,15 @@ -(ns clarktown.renderers.code-block-test +(ns clarktown.renderers.fenced-code-block-test (:require [clojure.test :refer [deftest testing is]] [clojure.java.io :as io] - [clarktown.renderers.code-block :as code-block])) + [clarktown.renderers.fenced-code-block :as code-block])) -(deftest code-block-renderer-test - (testing "Code block with language specification" +(deftest fenced-code-block-renderer-test + (testing "Fenced code block with language specification" (is (= (slurp (io/file (io/resource "test/parsers/code_block_result.html"))) (code-block/render (slurp (io/file (io/resource "test/parsers/code_block.md"))) nil nil)))) - (testing "Code block with NO language specification" + (testing "Fenced code block with NO language specification" (is (= (slurp (io/file (io/resource "test/parsers/code_block_no_language_result.html"))) - (code-block/render (slurp (io/file (io/resource "test/parsers/code_block_no_language.md"))) nil nil)))))
\ No newline at end of file + (code-block/render (slurp (io/file (io/resource "test/parsers/code_block_no_language.md"))) nil nil))))) |
