From 16c151a6a88d0e68930f34cc4c863ce1fa77dff1 Mon Sep 17 00:00:00 2001 From: Lee Adams Date: Sun, 29 Dec 2019 00:49:20 -0800 Subject: [PATCH] Don't consider indented blocks in a paragraph code blocks (#157) --- src/cljc/markdown/transformers.cljc | 5 ++++- test/markdown/md_test.cljc | 12 ++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cljc/markdown/transformers.cljc b/src/cljc/markdown/transformers.cljc index c3820fd..b50300f 100644 --- a/src/cljc/markdown/transformers.cljc +++ b/src/cljc/markdown/transformers.cljc @@ -162,7 +162,7 @@ (defn paragraph [text state] (apply close-paragraph (open-paragraph text state))) -(defn code [text {:keys [eof lists code codeblock] :as state}] +(defn code [text {:keys [eof lists code codeblock paragraph] :as state}] (cond (or lists codeblock) [text state] @@ -172,6 +172,9 @@ [(str "" text) (dissoc state :indented-code :code :last-line-empty?)] [(str "\n" (escape-code (string/replace-first text #" " ""))) state]) + paragraph + [text state] + (empty? (string/trim text)) [text state] diff --git a/test/markdown/md_test.cljc b/test/markdown/md_test.cljc index 88caa71..29fb56f 100644 --- a/test/markdown/md_test.cljc +++ b/test/markdown/md_test.cljc @@ -193,6 +193,18 @@ ``` ")))) +(deftest indented-codeblock + (is (= "
foo
" + (entry-function " foo"))) + (is (= "
foo

bar

" + (entry-function " foo\n\nbar"))) + (is (= "
foo
bar" + (entry-function " foo\nbar"))) + (is (= "

baz foo

bar

" + (entry-function "baz\n foo\n\nbar"))) + (is (= "

Element #1

" + (entry-function "
\n
\n

Element #1

\n
\n
")))) + (deftest strikethrough (is (= "

foo

" (entry-function "~~foo~~"))))