From a8231bc83f78d450558da18c3212ef4467709b5b Mon Sep 17 00:00:00 2001 From: Matthew Butterick Date: Tue, 22 Dec 2015 11:49:13 -0800 Subject: [PATCH] correct `merge-newlines` handling of empty input --- decode.rkt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/decode.rkt b/decode.rkt index 33dfdb4..501507c 100644 --- a/decode.rkt +++ b/decode.rkt @@ -365,12 +365,10 @@ (define paragraph-pattern (pregexp (format "^~a+$" sep))) (and (string? x) (regexp-match paragraph-pattern x))) - ;; Find adjacent newline characters in a list and merge them into one item ;; Scribble, by default, makes each newline a separate list item. (define+provide/contract (merge-newlines x) (txexpr-elements? . -> . txexpr-elements?) - (define (newlines? x) (and (string? x) (let ([newline-pat (regexp (format "^~a+$" (world:current-newline)))]) @@ -382,12 +380,14 @@ xs)) (let loop ([x x]) - (if (list? x) + (if (pair? x) (let ([xs (map loop x)]) (append-map merge-if-newlines (slicef xs newlines?))) x))) (module-test-external + (require racket/list) + (check-equal? (merge-newlines empty) empty) (check-equal? (merge-newlines '(p "\n" "\n" "foo" "\n" "\n\n" "bar" (em "\n" "\n" "\n"))) '(p "\n\n" "foo" "\n\n\n" "bar" (em "\n\n\n"))))