;; Extension — table block. (st-bootstrap-classes!) (content/bootstrap!) (content-bootstrap-markdown!) (content-bootstrap-text!) (content-bootstrap-table!) (define nl (str "\n")) (define t (mk-table "t" (list "Name" "Age") (list (list "Ada" "36") (list "Al" "40")))) ;; ── identity ── (content-test "table is block" (block? t) true) (content-test "table? yes" (table? t) true) (content-test "table type" (blk-type t) "table") (content-test "table headers" (table-headers t) (list "Name" "Age")) (content-test "table rows" (len (table-rows t)) 2) ;; ── html ── (content-test "table html" (asHTML t) "
NameAge
Ada36
Al40
") (content-test "table html escapes cells" (asHTML (mk-table "t" (list "AA<Bx&y") ;; ── sx ── (content-test "table sx" (asSx t) "(table (thead (tr (th \"Name\")(th \"Age\"))) (tbody (tr (td \"Ada\")(td \"36\"))(tr (td \"Al\")(td \"40\"))))") ;; ── text ── (content-test "table text" (asText t) "Name Age Ada 36 Al 40") ;; ── markdown ── (content-test "table markdown" (asMarkdown t) (str "| Name | Age |" nl "| --- | --- |" nl "| Ada | 36 |" nl "| Al | 40 |")) ;; ── in a document ── (define d (doc-append (doc-append (doc-empty "d") (mk-heading "h" 1 "Data")) t)) (content-test "doc with table html" (asHTML d) "

Data

NameAge
Ada36
Al40
") (content-test "doc ids" (doc-ids d) (list "h" "t")) ;; ── empty rows ── (content-test "table no rows html" (asHTML (mk-table "t" (list "H") (list))) "
H
") ;; ── validation ── (content-test "valid table" (content/valid? (doc-append (doc-empty "d") t)) true) (content-test "bad headers flagged" (content/issue-kinds (doc-append (doc-empty "d") (mk-table "t" "nope" (list)))) (list "field"))