diff options
| author | Asko Nõmm <asko@bien.ee> | 2022-04-15 19:56:01 +0200 |
|---|---|---|
| committer | Asko Nõmm <asko@bien.ee> | 2022-04-15 19:56:01 +0200 |
| commit | ce96dd264fd2385303f48259e5e8d1431d22b91d (patch) | |
| tree | 70b08a04aa7261c64ccb4f21f1b4bc34d86b1a2a /src/clarktown/parsers/code_block.clj | |
| parent | 58970486f0c0fdb9470ef28e510f5c90060e2ced (diff) | |
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.
Diffstat (limited to 'src/clarktown/parsers/code_block.clj')
| -rw-r--r-- | src/clarktown/parsers/code_block.clj | 16 |
1 files changed, 9 insertions, 7 deletions
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 "<pre><code class=\"language-" language "\">" code "</code></pre>") (str "<pre><code>" code "</code></pre>")))) |
