From e34ea8c989e55fd16bfd68c08e8c856f6be6727b Mon Sep 17 00:00:00 2001 From: Jeff Rabinowitz Date: Sun, 8 Nov 2015 20:29:37 -0500 Subject: [PATCH] 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. --- src/cryogen_core/toc.clj | 5 +++-- test/cryogen_core/toc_test.clj | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/cryogen_core/toc.clj b/src/cryogen_core/toc.clj index e7bc348..f40cd35 100644 --- a/src/cryogen_core/toc.clj +++ b/src/cryogen_core/toc.clj @@ -99,7 +99,8 @@ contents, while :ul will result in an unordered list. The default is an ordered list." [^String html & {:keys [list-type] :or {list-type :ol}}] - (-> html + (let [list-type (if (true? list-type) :ol list-type)] + (-> html (.getBytes "UTF-8") (java.io.ByteArrayInputStream.) (html/parse) @@ -107,4 +108,4 @@ (get-headings) (build-toc-tree) (build-toc list-type) - (hiccup/html))) + (hiccup/html)))) diff --git a/test/cryogen_core/toc_test.clj b/test/cryogen_core/toc_test.clj index 4554205..4a608e9 100644 --- a/test/cryogen_core/toc_test.clj +++ b/test/cryogen_core/toc_test.clj @@ -93,3 +93,17 @@ "but outer headers cannot be less indented " "than the original header."])) )) + + +(deftest test-generate-toc + (let [htmlString "

Test

"] + (is (= "
  1. Test
" + (generate-toc htmlString))) + (is (= "
  1. Test
" + (generate-toc htmlString :list-type true))) + (is (= "
  1. Test
" + (generate-toc htmlString :list-type :ol))) + (is (= "" + (generate-toc htmlString :list-type :ul))))) + +