;; lib/host/tests/htmlsx.sx — the pure-SX HTML → SX converter (host/html->sx). Covers text, ;; entities, void/nested tags, attributes, figure/iframe, and an end-to-end import round-trip. (define host-ht-pass 0) (define host-ht-fail 0) (define host-ht-fails (list)) (define host-ht-test (fn (name actual expected) (if (= actual expected) (set! host-ht-pass (+ host-ht-pass 1)) (begin (set! host-ht-fail (+ host-ht-fail 1)) (append! host-ht-fails {:name name :actual actual :expected expected}))))) ;; a paragraph with inline formatting — kept nested (decompose flattens to text later). (host-ht-test "a

with inline parses to (p \"…\" (strong \"…\") \"…\")" (str (host/html->sx "

Hello world now

")) "(article (p \"Hello \" (strong \"world\") \" now\"))") ;; HTML entities decode to UTF-8 (not \\uXXXX). (host-ht-test "entities decode (& £ ’)" (str (host/html->sx "

Tom & Jerry cost £5 ’n up

")) "(article (p \"Tom & Jerry cost £5 ’n up\"))") ;; a void keeps its attributes as keyword attrs. (host-ht-test "a void keeps :src/:alt attrs" (str (host/html->sx "\"a")) "(article (img :alt \"a photo\" :src \"a.jpg\"))") ;; a
with an +
nests correctly. (host-ht-test "a
nests an and a
" (str (host/html->sx "
\"y\"
a caption
")) "(article (figure (img :alt \"y\" :src \"y.jpg\") (figcaption \"a caption\")))") ;; an ")) "(article (iframe :src \"https://youtube.com/embed/x\"))") ;; comments + doctype are skipped; whitespace-only text is dropped. (host-ht-test "comments/doctype are skipped, blank text dropped" (str (host/html->sx "

x

\n

y

")) "(article (p \"x\") (p \"y\"))") ;; headings map through (decompose then turns h2 into card-heading). (host-ht-test "headings + paragraphs come through in order" (str (host/html->sx "

Title

body

")) "(article (h2 \"Title\") (p \"body\"))") ;; ── END TO END: HTML → SX → decompose → typed card objects ────────── (host/blog-use-store! (persist/open)) (host/blog-seed-types!) (host-ht-test "html->sx feeds decompose: a real snippet becomes typed cards" (begin (host/blog-put! "htdoc" "HT" "(p)" "published") (host/blog--decompose! "htdoc" (host/html->sx "

Heading

Some bold text.

\"a\"
cap
")) (list (host/blog-is-a? "htdoc__body__b0" "card-heading") (host/blog-is-a? "htdoc__body__b1" "card-text") (get (host/blog-field-values-of "htdoc__body__b1") "text") ;; strong flattened to text (host/blog-is-a? "htdoc__body__b2" "card-image") (get (host/blog-field-values-of "htdoc__body__b2") "caption") (host/blog-is-a? "htdoc__body__b3" "card-embed"))) (list true true "Some bold text." true "cap" true)) (define host-ht-tests-run! (fn () {:total (+ host-ht-pass host-ht-fail) :passed host-ht-pass :failed host-ht-fail :fails host-ht-fails}))