|
|
@ -254,7 +254,7 @@
|
|
|
|
(define matches null)
|
|
|
|
(define matches null)
|
|
|
|
(define (extract! x)
|
|
|
|
(define (extract! x)
|
|
|
|
(match x
|
|
|
|
(match x
|
|
|
|
[(? pred) ;; store matched item and return processed value
|
|
|
|
[(? pred)
|
|
|
|
(set! matches (cons x matches))
|
|
|
|
(set! matches (cons x matches))
|
|
|
|
(proc x)]
|
|
|
|
(proc x)]
|
|
|
|
[(? txexpr?) (let-values ([(tag attrs elements) (txexpr->values x)])
|
|
|
|
[(? txexpr?) (let-values ([(tag attrs elements) (txexpr->values x)])
|
|
|
@ -266,20 +266,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide+safe (findf*-txexpr tx pred)
|
|
|
|
(define+provide+safe (findf*-txexpr tx pred)
|
|
|
|
(txexpr? procedure? . -> . (or/c #f txexpr-elements?))
|
|
|
|
(txexpr? procedure? . -> . (or/c #f txexpr-elements?))
|
|
|
|
(define-values (_ matches) (splitf-txexpr tx pred))
|
|
|
|
(match/values (splitf-txexpr tx pred)
|
|
|
|
(and (pair? matches) matches))
|
|
|
|
[(_ (? pair? matches)) matches]
|
|
|
|
|
|
|
|
[(_ _) #false]))
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide+safe (findf-txexpr tx pred)
|
|
|
|
(define+provide+safe (findf-txexpr tx pred)
|
|
|
|
(txexpr? procedure? . -> . (or/c #f txexpr-element?))
|
|
|
|
(txexpr? procedure? . -> . (or/c #f txexpr-element?))
|
|
|
|
(define matches (findf*-txexpr tx pred))
|
|
|
|
(match (findf*-txexpr tx pred)
|
|
|
|
(and matches (car matches)))
|
|
|
|
[(cons match _) match]
|
|
|
|
|
|
|
|
[_ #false]))
|
|
|
|
|
|
|
|
|
|
|
|
;; don't use "![CDATA[...]]" wrapper in HTML, it's not consistent with the spec
|
|
|
|
;; don't use "![CDATA[...]]" wrapper in HTML, it's not consistent with the spec
|
|
|
|
(define (->cdata x) (if (string? x) (cdata #f #f x) x))
|
|
|
|
(define (->cdata x) (if (string? x) (cdata #f #f x) x))
|
|
|
|
|
|
|
|
|
|
|
|
;; but treat CDATA strings correctly anyhow, because that's friendly
|
|
|
|
;; but treat CDATA strings correctly anyhow, because that's friendly
|
|
|
|
(define (cdata-string? x)
|
|
|
|
(define (cdata-string? x)
|
|
|
|
(and (string? x) (regexp-match #rx"^<!\\[CDATA\\[.*\\]\\]>$" x) #t))
|
|
|
|
(and (string? x) (regexp-match #rx"^<!\\[CDATA\\[.*\\]\\]>$" x) #true))
|
|
|
|
|
|
|
|
|
|
|
|
(define+provide+safe (xexpr->html x)
|
|
|
|
(define+provide+safe (xexpr->html x)
|
|
|
|
(xexpr? . -> . string?)
|
|
|
|
(xexpr? . -> . string?)
|
|
|
@ -287,11 +289,9 @@
|
|
|
|
(let loop ([x x])
|
|
|
|
(let loop ([x x])
|
|
|
|
(match x
|
|
|
|
(match x
|
|
|
|
[(? txexpr?)
|
|
|
|
[(? txexpr?)
|
|
|
|
(let*-values ([(tag attrs elements) (txexpr->values x)]
|
|
|
|
(define-values (tag attrs elements) (txexpr->values x))
|
|
|
|
[(proc) (if (memq tag '(script style))
|
|
|
|
(define proc (if (memq tag '(script style)) ->cdata loop))
|
|
|
|
->cdata
|
|
|
|
;; a little faster than `txexpr` since we know the pieces are valid
|
|
|
|
loop)])
|
|
|
|
(txexpr-unsafe tag attrs (map proc elements))]
|
|
|
|
;; a little faster than `txexpr` since we know the pieces are valid
|
|
|
|
|
|
|
|
(txexpr-unsafe tag attrs (map proc elements)))]
|
|
|
|
|
|
|
|
[(? cdata-string?) (->cdata x)]
|
|
|
|
[(? cdata-string?) (->cdata x)]
|
|
|
|
[_ x]))))
|
|
|
|
[_ x]))))
|
|
|
|