From ee7ab7fd1163a1a8444e16017793eb32a0eb08ee Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Sat, 30 Apr 2022 12:09:32 +0300 Subject: Close #22, Close #23 --- src/clarktown/engine.clj | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/clarktown/engine.clj') diff --git a/src/clarktown/engine.clj b/src/clarktown/engine.clj index deca176..eaa0fb0 100644 --- a/src/clarktown/engine.clj +++ b/src/clarktown/engine.clj @@ -69,13 +69,20 @@ lines))) +(defn- remove-excess-newlines + "Replaces all occurences of 3 or more concecutive newlines into + two newlines." + [markdown] + (string/replace markdown #"\n{3,}" "\n\n")) + + (defn- correct-markdown "Corrects invalid Markdown for the parser." [markdown given-correctors] - (let [lines (string/split-lines markdown)] - (->> lines - (correct-block-separations (:block-separations given-correctors)) - (string/join \newline)))) + (->> (string/split-lines markdown) + (correct-block-separations (:block-separations given-correctors)) + (string/join \newline) + (remove-excess-newlines))) (defn- find-parser-by-block -- cgit v1.2.3