;; Extension — plain-text render mode + excerpts.

(st-bootstrap-classes!)
(content/bootstrap!)
(content-bootstrap-text!)

;; ── per-block ──
(content-test
  "heading text"
  (asText (mk-heading "h" 2 "Title"))
  "Title")
(content-test "paragraph text" (asText (mk-text "p" "Body")) "Body")
(content-test "code text" (asText (mk-code "c" "sx" "(+ 1 2)")) "(+ 1 2)")
(content-test "quote text" (asText (mk-quote "q" "Ada" "to err")) "to err")
(content-test
  "image -> alt"
  (asText (mk-image "i" "/c.png" "a cat"))
  "a cat")
(content-test
  "embed -> empty"
  (asText (mk-embed "e" "https://v" "vimeo"))
  "")
(content-test "divider -> empty" (asText (mk-divider "d")) "")
(content-test
  "list -> joined"
  (asText (mk-list "l" false (list "a" "b" "c")))
  "a, b, c")
(content-test "empty list -> empty" (asText (mk-list "l" false (list))) "")

;; ── document joins non-empty child texts with a space ──
(define
  d
  (doc-append
    (doc-append
      (doc-append
        (doc-append (doc-empty "d") (mk-heading "h" 1 "Title"))
        (mk-text "p" "Hello world"))
      (mk-divider "dv"))
    (mk-list "l" true (list "x" "y"))))
(content-test "doc text skips empties" (asText d) "Title Hello world x, y")
(content-test "empty doc text" (asText (doc-empty "e")) "")

;; ── via facade ──
(content-test "render text" (content/render d "text") (asText d))
(content-test "render text keyword" (content/render d :text) (asText d))
(content-test "content/text alias" (content/text d) (asText d))
(content-test "block-text alias" (block-text (mk-text "p" "x")) "x")

;; ── excerpt ──
(content-test
  "excerpt under limit"
  (content/excerpt d 100)
  "Title Hello world x, y")
(content-test "excerpt truncates" (content/excerpt d 5) "Title…")
(content-test
  "excerpt exact length"
  (content/excerpt
    (doc-append (doc-empty "e") (mk-text "p" "12345"))
    5)
  "12345")
(content-test
  "excerpt one over"
  (content/excerpt
    (doc-append (doc-empty "e") (mk-text "p" "123456"))
    5)
  "12345…")

;; ── reflects edits ──
(content-test
  "text after update"
  (asText (doc-update d "p" "text" "Changed"))
  "Title Changed x, y")
