|
|
@ -4,12 +4,21 @@
|
|
|
|
;; (string->symbol (format "~a" #\u200B))
|
|
|
|
;; (string->symbol (format "~a" #\u200B))
|
|
|
|
(define splice-signal-tag '@)
|
|
|
|
(define splice-signal-tag '@)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (attrs? x)
|
|
|
|
|
|
|
|
(and (list? x)
|
|
|
|
|
|
|
|
(andmap (λ(xi)
|
|
|
|
|
|
|
|
(and (list? xi)
|
|
|
|
|
|
|
|
(= (length xi) 2)
|
|
|
|
|
|
|
|
(symbol? (car xi))
|
|
|
|
|
|
|
|
(string? (cadr xi)))) x)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (splice x [splicing-tag splice-signal-tag])
|
|
|
|
(define (splice x [splicing-tag splice-signal-tag])
|
|
|
|
; (listof txexpr-elements?) . -> . (listof txexpr-elements?))
|
|
|
|
; (listof txexpr-elements?) . -> . (listof txexpr-elements?))
|
|
|
|
(define spliceable? (λ(x) (and (pair? x) (eq? (car x) splicing-tag))))
|
|
|
|
(define spliceable? (λ(x) (and (pair? x) (eq? (car x) splicing-tag))))
|
|
|
|
(define not-null-string? (λ(x) (not (and (string? x) (= (string-length x) 0)))))
|
|
|
|
(define not-null-string? (λ(x) (not (and (string? x) (= (string-length x) 0)))))
|
|
|
|
(let loop ([x x])
|
|
|
|
(let loop ([x x])
|
|
|
|
(if (list? x)
|
|
|
|
(if (and (list? x) (not (attrs? x))) ; don't splice null strings inside attrs
|
|
|
|
(apply append (map (λ(x) ((if (spliceable? x)
|
|
|
|
(apply append (map (λ(x) ((if (spliceable? x)
|
|
|
|
cdr
|
|
|
|
cdr
|
|
|
|
list) (loop x))) (filter not-null-string? x)))
|
|
|
|
list) (loop x))) (filter not-null-string? x)))
|
|
|
@ -22,7 +31,8 @@
|
|
|
|
(check-equal? (splice `((,splice-signal-tag 1 (,splice-signal-tag 2 "" (,splice-signal-tag 3 (div 4 (,splice-signal-tag 5))) 6) "" 7)))
|
|
|
|
(check-equal? (splice `((,splice-signal-tag 1 (,splice-signal-tag 2 "" (,splice-signal-tag 3 (div 4 (,splice-signal-tag 5))) 6) "" 7)))
|
|
|
|
'(1 2 3 (div 4 5) 6 7))
|
|
|
|
'(1 2 3 (div 4 5) 6 7))
|
|
|
|
(check-equal? (splice `((,splice-signal-tag "foo" "" "bar"))) '("foo" "bar"))
|
|
|
|
(check-equal? (splice `((,splice-signal-tag "foo" "" "bar"))) '("foo" "bar"))
|
|
|
|
(check-equal? (splice null) null))
|
|
|
|
(check-equal? (splice null) null)
|
|
|
|
|
|
|
|
(check-equal? (splice '(a ((href "")(foo "bar")) "zam")) '(a ((href "")(foo "bar")) "zam")))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define (strip-empty-attrs x)
|
|
|
|
(define (strip-empty-attrs x)
|
|
|
|