Skip to content

Commit

Permalink
Don't consider indented blocks in a paragraph code blocks (yogthos#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lee Adams committed Dec 29, 2019
1 parent af70fa4 commit 16c151a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/cljc/markdown/transformers.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -172,6 +172,9 @@
[(str "</code></pre>" 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]

Expand Down
12 changes: 12 additions & 0 deletions test/markdown/md_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,18 @@
```
"))))

(deftest indented-codeblock
(is (= "<pre><code>foo</code></pre>"
(entry-function " foo")))
(is (= "<pre><code>foo</code></pre><p>bar</p>"
(entry-function " foo\n\nbar")))
(is (= "<pre><code>foo</code></pre>bar"
(entry-function " foo\nbar")))
(is (= "<p>baz foo</p><p>bar</p>"
(entry-function "baz\n foo\n\nbar")))
(is (= "<p><div class=\"grid-container\"> <div class=\"child1\"> <p>Element #1</p> </div> </div></p>"
(entry-function "<div class=\"grid-container\">\n <div class=\"child1\">\n <p>Element #1</p>\n </div>\n</div>"))))

(deftest strikethrough
(is (= "<p><del>foo</del></p>"
(entry-function "~~foo~~"))))
Expand Down

0 comments on commit 16c151a

Please sign in to comment.