(ns markdown.md-test (:require #?(:cljs [goog.string]) [clojure.test :refer [deftest is]] [markdown.core :as markdown] [markdown.tables :as tables])) (def entry-function #?(:clj markdown/md-to-html-string :cljs markdown/md->html)) (deftest heading1 (is (= "
with_an_underscoresome text
" (entry-function "###foo bar BAz\nsome text" :heading-anchors true))) (is (= "some text
" (entry-function "###foo bar BAz##\nsome text" :heading-anchors true)))) (deftest br (is (= "foo
foo
" (entry-function "*foo*")))) (deftest italics (is (= "foo
" (entry-function "_foo_")))) (deftest strong (is (= "foo
" (entry-function "**foo**")))) (deftest bold-italics (is (= "foo
" (entry-function "***foo***")))) (deftest bold (is (= "foo
" (entry-function "__foo__")))) (deftest strong-inside-em (is (= "foobarbaz
" (entry-function "*foo**bar**baz*")))) (deftest bold-inside-a-list (is (= "See more: Cluck Cluck
" (entry-function "1. chickens. \n\n **See more: [Cluck Cluck](http://cluck.cluck.com)** \n\n")))) (deftest em-inside-strong (is (= "foobarbaz
" (entry-function "**foo*bar*baz**")))) (deftest paragraph (is (= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
" (entry-function "\nLorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore")))) (deftest paragraph-multiline (is (= "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore
" (entry-function "\nLorem ipsum dolor\nsit amet, consectetur adipisicing elit,\nsed do eiusmod tempor incididunt ut labore")))) (deftest paragraph-before-codeblock (is (= "foo
bar\nbaz
" (entry-function "foo\n```\nbar\n```\nbaz"))) (is (= "foo \nbar" (entry-function "```\nfoo \nbar```")))
(is (= "" (entry-function "```\n```")))
(is (= "" (entry-function "```go\n```")))
(is (= "<html>\n</html>\n" (entry-function "```\n\n\n``` "))))
(deftest paragraph-after-codeblock
(is (= "foo\nbar baz
" (entry-function "```\nfoo\n```\nbar\nbaz")))) (deftest mulitple-paragraphs (is (= "foo bar baz
foo bar baz
" (entry-function "\nfoo bar baz\n\n\nfoo bar baz")))) (deftest ul (is (= "list:\n- 1\n- 2\n"
(entry-function "```yaml\nlist:\n- 1\n- 2\n```"))))
(deftest ul-followed-by-paragraph
(is (= "paragraph next line
" (entry-function "* foo\n* bar\n* baz\n\nparagraph\nnext line")))) (deftest ul-with-codeblock (is (= " (defn foo []\n bar)\n (defn foo []\n bar)\n textparagraph
" (entry-function "* foo\n* bar\n* baz\n\nparagraph")))) (deftest ul-nested (is (= "foo bar baz x = y + z; foo
bar foo --- -- bar foo
<?xml version='1.0' encoding='UTF-8'?><channel></channel>
foo bar baz (fn [x & xs] (str "x:" x)) foo
```\nfoo\n```"
(entry-function " ```\n foo\n ```"))))
(deftest multiline-code
(is (= "x = 5\ny = 6\nz = x + y"
(entry-function " x = 5\n y = 6\n z = x + y")))
(is (= "x = 5\ny = 6\nz = x + y\n(fn [x & xs] (str "x"))"
(entry-function " x = 5\n y = 6\n z = x + y\n (fn [x & xs] (str \"x\"))"))))
(deftest codeblock
(is (= "(defn- write^ [writer text]\n (doseq [c text]\n (.write writer (int c))))\n"
(entry-function "```\n(defn- write^ [writer text]\n (doseq [c text]\n (.write writer (int c))))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n"
(entry-function "```\n(fn [x & xs]\n (str \"x\"))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n"
(entry-function "```\n(fn [x & xs]\n (str \"x\"))\n```")))
(is (= "(fn [x & xs]\n (str "x"))\n"
(entry-function "```clojure\n(fn [x & xs]\n (str \"x\"))\n```")))
(is (= "------------\n============\n ------------\n ============\n"
(entry-function
"
```nohighlight
------------
============
------------
============
```
"))))
(deftest indented-codeblock
(is (= "foo"
(entry-function " foo")))
(is (= "foobar
" (entry-function " foo\n\nbar"))) (is (= "foobar"
(entry-function " foo\nbar")))
(is (= "baz foo
bar
" (entry-function "baz\n foo\n\nbar"))) (is (= "Element #1
Element #1
\nfoo
foobar baz
" (entry-function "foo^bar baz")))) (deftest link (is (= "" (entry-function "underscores_are_fine"))) (is (= "" (entry-function "[github](http://github.com)"))) (is (= "" (entry-function "[github](http://github.com/~)"))) (is (= "" (entry-function "[github](http://github.com/^)"))) (is (= "" (entry-function "[github](http://github.com/*)"))) (is (= "" (entry-function "* [github](http://github.com/*)"))) (is (= "


[github](http://github.comfooo
" (entry-function "[github](http://github.comfooo"))) (is (= "[github] no way (http://github.com)
" (entry-function "[github] no way (http://github.com)")))) (deftest bad-link-title (is (= "[github(http://github.comfooo)
" (entry-function "[github(http://github.comfooo)")))) (deftest blockquote (is (= "" (entry-function ">Foo bar baz")))) (deftest blockquote-footer (is (= "Foo bar baz
" (entry-function "> Foo bar baz\n>- Leo Tolstoy")))) (deftest blockquote-empty-footer (is (= "Foo bar baz
" (entry-function "> Foo bar baz\n>-")))) (deftest blockquote-multiline-without-leading-angle-bracket (is (= "Foo bar baz
" (entry-function "> Foo bar\nbaz")))) (deftest blockquote-multiple-paragraphs (is (= "Foo bar baz
" (entry-function "> Foo bar\n>\n> baz")))) (deftest blockquote-bullets (is (= "Foo bar
baz
list:
- foo
- bar
end.
" (entry-function "> list:\n>* foo\n>* bar\n\nend."))) (is (= "" (entry-function ">* foo\n>* bar\n>* baz")))) (deftest blockquote-headings (is (= "
- foo
- bar
- baz
" (entry-function "> ## Foo\n>bar baz"))) (is (= "Foo
bar baz
" (entry-function "> Foo\n>## bar\n> baz")))) (deftest escaped-characters (is (= "Foo
bar
baz
^*‘_{}[]footestbar{x}[y]
test bold and italic
" (entry-function "1. a\n2. b\n\ntest **bold** and *italic*")))) (deftest paragraph-close-before-list (is (= "in paragraph
Some content with a http://www.google.com/abc__123__efg link it in
" (entry-function "Some content with ahttp://foo https://bar/baz foo bar
" (entry-function "The fish was 192.8 lbs and was amazing to see.
" (entry-function "The fish was\n192.8 lbs and was amazing to see.")))) (deftest dont-encode-chars-in-hrefs (is (= "example_link with tilde ~ and carat ^ and splat *
" (entry-function "[example_link with tilde ~ and carat ^ and splat *](http://www.google.com/example_link_foo~_^*)")))) (deftest complex-link-with-terminal-encoding-inside-header (is (= "You can have a link followed by an image 
You can have an image
followed by a link
| Header 1 | Header 2 | Header 3 | Header 4 |
|---|---|---|---|
| contents 1 | contents 2 | contents 3 | contents 4 |
boo – bar
" (entry-function "boo -- bar")))) (deftest m-dash (is (= "boo — bar
" (entry-function "boo --- bar")))) (deftest inhibit-simple (is (= "_abc_
" (entry-function "$_abc_$" :inhibit-separator "$")))) (deftest inhibit-simple-seq (is (= "_abc_
" (entry-function "$_abc_$" :inhibit-separator [\$])))) (deftest inhibit-inline-code (is (= "`abc`
" (entry-function "$`abc`$" :inhibit-separator [\$])))) (deftest inhibit-inside-code (is (= "a*b* & dc
one` `two
$
" (entry-function "$$" :inhibit-separator [\$])))) (deftest inhibit-escape-twice (is (= "$$
" (entry-function "$$$$" :inhibit-separator "$")))) (deftest img-reprocess (is (= "
and Edit
$abc$
" (entry-function "$$*abc*$$" :inhibit-separator "$")))) (deftest inhibit-escape-inside-code (is (= "$
foo
bar
" (entry-function "foo\n \nbar"))))