add xml-attribute-encode function
This commit is contained in:
parent
62f5b2c4e4
commit
63d0f79847
|
@ -540,6 +540,10 @@ END
|
|||
|
||||
(test-suite
|
||||
"xml->xexpr"
|
||||
|
||||
(test-equal? "xml-attribute-encode"
|
||||
(xml-attribute-encode "ab\"cd?e;;<i> %"f")
|
||||
"ab"cd?e;;<i> %&quot;f")
|
||||
(test-xml->xexpr
|
||||
"<doc><bold>hi</bold> there!</doc>"
|
||||
'(doc () (bold () "hi") " there!"))
|
||||
|
|
|
@ -166,7 +166,7 @@
|
|||
[(#\") """]
|
||||
[else c]))
|
||||
|
||||
;; escape : String -> String
|
||||
;; escape : String Regexp -> String
|
||||
(define (escape x table)
|
||||
(regexp-replace* table x replace-escaped))
|
||||
|
||||
|
|
|
@ -101,6 +101,7 @@
|
|||
[xml->xexpr (content/c . -> . xexpr/c)]
|
||||
[xexpr->xml (xexpr/c . -> . content/c)]
|
||||
[xexpr-drop-empty-attributes (parameter/c boolean?)]
|
||||
[xml-attribute-encode (string? . -> . string?)]
|
||||
[write-xexpr (->* (xexpr/c)
|
||||
(output-port?
|
||||
#:insert-newlines? any/c)
|
||||
|
@ -168,3 +169,9 @@
|
|||
[(p-i? x)
|
||||
(write-xml-p-i x 0 void out)]))
|
||||
(void))
|
||||
|
||||
;; given a string, encode it in the style required for attributes. Specifically,
|
||||
;; double-quote must be encoded as well as <, >, and &, because the double-quote
|
||||
;; would otherwise end the attribute.
|
||||
(define (xml-attribute-encode str)
|
||||
(escape str escape-attribute-table))
|
||||
|
|
Loading…
Reference in New Issue
Block a user