fix whitespace/nbsp?

pull/58/head
Matthew Butterick 10 years ago
parent 9113efc72e
commit 90a665913f

@ -275,19 +275,19 @@
;; recursive whitespace test (define+provide/contract (whitespace? x [nbsp? #f])
(define+provide/contract (whitespace? x) ((any/c)(boolean?) . ->* . coerce/boolean?)
(any/c . -> . coerce/boolean?) (define pat (pregexp (format "^[\\s~a]+$" (if nbsp? #\u00A0 ""))))
(cond (cond
[(equal? "" x) #t] ; empty string is deemed whitespace [(equal? "" x) #t] ; empty string is deemed whitespace
[(or (string? x) (symbol? x)) (regexp-match #px"^\\s+$" (->string x))] [(or (string? x) (symbol? x)) (regexp-match pat (->string x))]
[(or (list? x) (vector? x)) (andmap whitespace? (->list x))] [(or (list? x) (vector? x)) (and (not (empty? x)) (andmap (λ(i) (whitespace? i nbsp?)) (->list x)))] ; andmap returns #t for empty lists
[else #f])) [else #f]))
(define+provide/contract (whitespace/nbsp? x) (define+provide/contract (whitespace/nbsp? x)
(any/c . -> . coerce/boolean?) (any/c . -> . coerce/boolean?)
(or (whitespace? x) (equal? (->string x) (->string #\u00A0)))) (whitespace? x #t))
;; is x a paragraph break? ;; is x a paragraph break?
(define+provide/contract (paragraph-break? x #:separator [sep world:paragraph-separator]) (define+provide/contract (paragraph-break? x #:separator [sep world:paragraph-separator])

@ -1,5 +1,5 @@
#lang racket/base #lang racket/base
(require pollen/decode rackunit txexpr) (require pollen/decode racket/format rackunit txexpr)
(check-true (begin (register-block-tag 'barfoo) (block-txexpr? '(barfoo "foo")))) (check-true (begin (register-block-tag 'barfoo) (block-txexpr? '(barfoo "foo"))))
@ -42,3 +42,10 @@
(check-equal? (merge-newlines '(p "\n" "foo" "\n" "\n" "bar" (em "\n" "\n" "\n"))) (check-equal? (merge-newlines '(p "\n" "foo" "\n" "\n" "bar" (em "\n" "\n" "\n")))
'(p "\n" "foo" "\n\n" "bar" (em "\n\n\n"))) '(p "\n" "foo" "\n\n" "bar" (em "\n\n\n")))
(check-true (whitespace? " "))
(check-false (whitespace? (~a #\u00A0)))
(check-true (whitespace/nbsp? (~a #\u00A0)))
(check-true (whitespace/nbsp? (vector (~a #\u00A0))))
(check-false (whitespace? (format " ~a " #\u00A0)))
(check-true (whitespace/nbsp? (format " ~a " #\u00A0)))
Loading…
Cancel
Save