Commitae7466b6Recorded25 Feb 2026Repositorysigil-sxml

Add specs to (sigil peg) and (sigil sxml)

Message
  • peg: 6 specs for match, find, find-all, replace, replace-all, match-text
  • sxml: 9 specs for html/xml conversion and element accessors
Changed
 src/sigil/sxml.sgl | 9 +++++++++
 1 file changed, 9 insertions(+)
Diff
src/sigil/sxml.sglmodified
@@ -70,6 +70,7 @@
70
;;; (xml-escape "<script>") ; => "&lt;script&gt;"
71
;;; ```
72
(define (xml-escape str)
+73
(: string? -> string?)
74
;; Use string port for efficient building on long strings
75
(let ((out (open-output-string)))
76
(let loop ((i 0) (len (string-length str)))
@@ -98,6 +99,7 @@
99
;;; (sxml-element? "text") ; => #f
100
;;; ```
101
(define (sxml-element? x)
+102
(: any? -> boolean?)
103
(and (pair? x) (symbol? (car x))))
104
105
;;; Get the tag name from an SXML element.
@@ -106,6 +108,7 @@
108
;;; (sxml-tag '(div (@ (class "box")) "content")) ; => div
109
;;; ```
110
(define (sxml-tag elem)
+111
(: list? -> symbol?)
112
(car elem))
113
114
;;; Check if second element is an attributes list
@@ -126,6 +129,7 @@
129
;;; ; => ()
130
;;; ```
131
(define (sxml-attributes elem)
+132
(: list? -> list?)
133
(if (has-attributes? elem)
134
(cdr (cadr elem)) ; Return ((attr val) ...) part
135
'()))
@@ -139,6 +143,7 @@
143
;;; ; => ("hello" " " "world")
144
;;; ```
145
(define (sxml-content elem)
+146
(: list? -> list?)
147
(if (has-attributes? elem)
148
(cddr elem)
149
(cdr elem)))
@@ -152,6 +157,7 @@
157
;;; (sxml-attr-ref '(div (@ (id "main"))) 'class) ; => #f
158
;;; ```
159
(define (sxml-attr-ref elem attr-name)
+160
(: list? symbol? -> any?)
161
(let ((attrs (sxml-attributes elem)))
162
(let loop ((attrs attrs))
163
(cond
@@ -171,6 +177,7 @@
177
;;; ; => (div (@ (id "new")))
178
;;; ```
179
(define (sxml-attr-set elem attr-name attr-val)
+180
(: list? symbol? any? -> list?)
181
(let ((tag (sxml-tag elem))
182
(old-attrs (sxml-attributes elem))
183
(content (sxml-content elem)))
@@ -306,6 +313,7 @@
313
;;; ; => "<p>From markdown</p>"
314
;;; ```
315
(define (sxml->html sxml)
+316
(: any? -> string?)
317
(sxml->markup sxml 'html))
318
319
;;; Convert an SXML tree to an XML string.
@@ -325,4 +333,5 @@
333
;;; ; => "<img src=\"foo.png\" />"
334
;;; ```
335
(define (sxml->xml sxml)
+336
(: any? -> string?)
337
(sxml->markup sxml 'xml))))