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:
parent
6d50af6a7a
commit
e34ea8c989
2 changed files with 17 additions and 2 deletions
|
@ -99,6 +99,7 @@
|
||||||
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}}]
|
||||||
|
(let [list-type (if (true? list-type) :ol list-type)]
|
||||||
(-> html
|
(-> html
|
||||||
(.getBytes "UTF-8")
|
(.getBytes "UTF-8")
|
||||||
(java.io.ByteArrayInputStream.)
|
(java.io.ByteArrayInputStream.)
|
||||||
|
@ -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))))
|
||||||
|
|
|
@ -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)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue