Files
rose-ash/lib/content/tests/toc.sx
giles fe2475c49d
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 31s
content: TOC rendering (toc.sx) + 8 tests (594/594)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-07 04:04:03 +00:00

64 lines
1.7 KiB
Plaintext

;; 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 &lt; 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)")