summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/clarktown/core.clj2
-rw-r--r--src/clarktown/engine.clj56
2 files changed, 30 insertions, 28 deletions
diff --git a/src/clarktown/core.clj b/src/clarktown/core.clj
index a624275..2a3e3a1 100644
--- a/src/clarktown/core.clj
+++ b/src/clarktown/core.clj
@@ -27,4 +27,4 @@
([markdown given-parsers]
(render markdown given-parsers correctors/default-correctors))
([markdown given-parsers given-correctors]
- (engine/render markdown given-parsers given-correctors))) \ No newline at end of file
+ (engine/render markdown given-parsers given-correctors)))
diff --git a/src/clarktown/engine.clj b/src/clarktown/engine.clj
index 17e5867..2dc9089 100644
--- a/src/clarktown/engine.clj
+++ b/src/clarktown/engine.clj
@@ -39,32 +39,34 @@
"Corrects block separations and adds newlines above or
below a block where needed."
[correctors lines]
- (->> lines
- (map-indexed
- (fn [index line]
- (let [add-line-above? (some #(true? (% lines line index)) (:empty-line-above? correctors))
- add-line-below? (some #(true? (% lines line index)) (:empty-line-below? correctors))]
- (cond
- ; If code block starts but there is no empty newline
- ; above, let's fix that
- (and add-line-above?
- (not add-line-below?))
- (str \newline line)
-
- ; If the code block ends, but there is no empty newline
- ; below, let's fix that.
- (and add-line-below?
- (not add-line-above?))
- (str line \newline)
-
- ; If the code block needs a newline both above and below,
- ; let's fix that.
- (and add-line-above?
- add-line-below?)
- (str \newline line \newline)
-
- ; otherwise is what it is
- :else line))))))
+ (let [above-correctors (:empty-line-above? correctors)
+ below-correctors (:empty-line-below? correctors)]
+ (map-indexed
+ (fn [index line]
+ (let [add-line-above? (some #(true? (% lines line index)) above-correctors)
+ add-line-below? (some #(true? (% lines line index)) below-correctors)]
+ (cond
+ ; If code block starts but there is no empty newline
+ ; above, let's fix that
+ (and add-line-above?
+ (not add-line-below?))
+ (str \newline line)
+
+ ; If the code block ends, but there is no empty newline
+ ; below, let's fix that.
+ (and add-line-below?
+ (not add-line-above?))
+ (str line \newline)
+
+ ; If the code block needs a newline both above and below,
+ ; let's fix that.
+ (and add-line-above?
+ add-line-below?)
+ (str \newline line \newline)
+
+ ; otherwise is what it is
+ :else line)))
+ lines)))
(defn- correct-markdown
@@ -137,4 +139,4 @@
(string/split #"\n\n")
stitch-code-blocks)
parsed-blocks (parse-blocks blocks given-parsers given-correctors)]
- (string/join "\n\n" parsed-blocks))) \ No newline at end of file
+ (string/join "\n\n" parsed-blocks)))