From ce96dd264fd2385303f48259e5e8d1431d22b91d Mon Sep 17 00:00:00 2001 From: Asko Nõmm Date: Fri, 15 Apr 2022 19:56:01 +0200 Subject: Implement Markdown correction mechanism This fixes the issue for ATX headings and code blocks where if there were no empty lines below and above of them it couldn't correctly identify those blocks as what they were. There's now a Markdown correction function where we can add more of these corrections in the future, making the whole thing a lot easier. --- src/clarktown/parsers/code_block.clj | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'src/clarktown/parsers') diff --git a/src/clarktown/parsers/code_block.clj b/src/clarktown/parsers/code_block.clj index 388776f..c6ecfea 100644 --- a/src/clarktown/parsers/code_block.clj +++ b/src/clarktown/parsers/code_block.clj @@ -16,13 +16,15 @@ (let [language (->> block (re-find #"\`\`\`(\w+)") second) - code (as-> block n - (string/replace-first n #"\`\`\`(\w+)?\n" "") - (subs n 0 (- (count n) 4)) - (string/replace n #"&" "&") - (string/replace n #"<" "<") - (string/replace n #">" ">") - (string/trim n))] + lines (string/split-lines block) + block* (->> (next lines) + (take (- (count lines) 2)) + (string/join \newline)) + code (-> block* + (string/replace #"&" "&") + (string/replace #"<" "<") + (string/replace #">" ">") + string/trim)] (if language (str "
" code "
") (str "
" code "
")))) -- cgit v1.2.3