content: TOC rendering (toc.sx) + 8 tests (594/594)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
63
lib/content/tests/toc.sx
Normal file
63
lib/content/tests/toc.sx
Normal file
@@ -0,0 +1,63 @@
|
||||
;; Extension — table-of-contents rendering.
|
||||
|
||||
(st-bootstrap-classes!)
|
||||
(content/bootstrap!)
|
||||
(content-bootstrap-section!)
|
||||
|
||||
(define nl (str "\n"))
|
||||
|
||||
(define
|
||||
d
|
||||
(doc-append
|
||||
(doc-append
|
||||
(doc-append
|
||||
(doc-append (doc-empty "d") (mk-heading "intro" 1 "Intro"))
|
||||
(mk-text "p" "x"))
|
||||
(mk-heading "bg" 2 "Background"))
|
||||
(mk-section "s" (list (mk-heading "deep" 2 "Details")))))
|
||||
|
||||
;; ── markdown TOC (indented by level) ──
|
||||
(content-test
|
||||
"toc markdown"
|
||||
(content/toc-markdown d)
|
||||
(str
|
||||
"- [Intro](#intro)"
|
||||
nl
|
||||
" - [Background](#bg)"
|
||||
nl
|
||||
" - [Details](#deep)"))
|
||||
|
||||
;; ── html TOC (anchor links) ──
|
||||
(content-test
|
||||
"toc html"
|
||||
(content/toc-html d)
|
||||
"<ul><li><a href=\"#intro\">Intro</a></li><li><a href=\"#bg\">Background</a></li><li><a href=\"#deep\">Details</a></li></ul>")
|
||||
|
||||
;; ── html escapes heading text ──
|
||||
(content-test
|
||||
"toc html escapes"
|
||||
(content/toc-html
|
||||
(doc-append (doc-empty "d") (mk-heading "h" 1 "A < B")))
|
||||
"<ul><li><a href=\"#h\">A < B</a></li></ul>")
|
||||
|
||||
;; ── empty / no headings ──
|
||||
(content-test "toc html empty" (content/toc-html (doc-empty "e")) "")
|
||||
(content-test "toc markdown empty" (content/toc-markdown (doc-empty "e")) "")
|
||||
(content-test
|
||||
"toc no headings"
|
||||
(content/toc-html (doc-append (doc-empty "d") (mk-text "p" "just text")))
|
||||
"")
|
||||
|
||||
;; ── single heading ──
|
||||
(content-test
|
||||
"toc single md"
|
||||
(content/toc-markdown
|
||||
(doc-append (doc-empty "d") (mk-heading "h" 1 "Only")))
|
||||
"- [Only](#h)")
|
||||
|
||||
;; ── deep level indentation ──
|
||||
(content-test
|
||||
"toc deep indent"
|
||||
(content/toc-markdown
|
||||
(doc-append (doc-empty "d") (mk-heading "h" 3 "Deep")))
|
||||
" - [Deep](#h)")
|
||||
Reference in New Issue
Block a user