Fixed a regression under which the old style of using :toc true would throw an exception because the tag was not properly cast to a :ul or :ol tag. Added unit testing for all cases.

This commit is contained in:
Jeff Rabinowitz 2015-11-08 20:29:37 -05:00
parent 6d50af6a7a
commit e34ea8c989
2 changed files with 17 additions and 2 deletions

View file

@ -99,7 +99,8 @@
contents, while :ul will result in an unordered list. The default is an contents, while :ul will result in an unordered list. The default is an
ordered list." ordered list."
[^String html & {:keys [list-type] :or {list-type :ol}}] [^String html & {:keys [list-type] :or {list-type :ol}}]
(-> html (let [list-type (if (true? list-type) :ol list-type)]
(-> html
(.getBytes "UTF-8") (.getBytes "UTF-8")
(java.io.ByteArrayInputStream.) (java.io.ByteArrayInputStream.)
(html/parse) (html/parse)
@ -107,4 +108,4 @@
(get-headings) (get-headings)
(build-toc-tree) (build-toc-tree)
(build-toc list-type) (build-toc list-type)
(hiccup/html))) (hiccup/html))))

View file

@ -93,3 +93,17 @@
"but outer headers cannot be less indented " "but outer headers cannot be less indented "
"than the original header."])) "than the original header."]))
)) ))
(deftest test-generate-toc
(let [htmlString "<div><h2><a name=\"test\"></a>Test</h2></div>"]
(is (= "<ol class=\"content\"><li><a href=\"#test\">Test</a></li></ol>"
(generate-toc htmlString)))
(is (= "<ol class=\"content\"><li><a href=\"#test\">Test</a></li></ol>"
(generate-toc htmlString :list-type true)))
(is (= "<ol class=\"content\"><li><a href=\"#test\">Test</a></li></ol>"
(generate-toc htmlString :list-type :ol)))
(is (= "<ul class=\"content\"><li><a href=\"#test\">Test</a></li></ul>"
(generate-toc htmlString :list-type :ul)))))