From dcb28604caaed822e5f05a0e553713d0e206b682 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Sun, 6 May 2012 07:42:28 -0400 Subject: [PATCH] Use the new `wrap-line' in the scribble text renderer. Looks like it's not making any changes in the current tests (which use the text renderer), but with words that are longer than the width the old version would stop wrapping afetr these words. Added a test file that fails with that and succeeds with the new one. If anyone cares about this, it's easy to make hyphenate words that are too long for a line. (Also fixed some redundant frustration in the bib test...) original commit: 084f1dcea7707adc83d180f79e6c68149dc03644 --- collects/scribble/text-render.rkt | 39 ++++--------------- collects/tests/scribble/docs.rkt | 8 ++-- .../docs/autobib-disambiguation.scrbl | 4 +- .../scribble/docs/autobib-disambiguation.txt | 2 +- collects/tests/scribble/docs/wrap.scrbl | 20 ++++++++++ collects/tests/scribble/docs/wrap.txt | 18 +++++++++ 6 files changed, 53 insertions(+), 38 deletions(-) create mode 100644 collects/tests/scribble/docs/wrap.scrbl create mode 100644 collects/tests/scribble/docs/wrap.txt diff --git a/collects/scribble/text-render.rkt b/collects/scribble/text-render.rkt index e415d4d5..025b0843 100644 --- a/collects/scribble/text-render.rkt +++ b/collects/scribble/text-render.rkt @@ -1,8 +1,6 @@ #lang racket/base -(require "core.rkt" - racket/class - racket/port - racket/list) +(require "core.rkt" racket/class racket/port racket/list racket/string + scribble/text/wrap) (provide render-mixin) (define current-preserve-spaces (make-parameter #f)) @@ -17,13 +15,6 @@ (newline) (indent)) -(define indent-pxs (make-hash)) -(define (indent->paragraph-px amt) - (or (hash-ref indent-pxs amt #f) - (let ([px (pregexp (format "^ *(.{1,~a}(?paragraph-px (current-indent))) - (let loop ([indent? #f]) - (cond - [(or (regexp-try-match px i) - (regexp-try-match #px"^ *(.+(? (lambda (m) - (when indent? (indent)) - (write-bytes (cadr m)) - (newline) - (loop #t))] - [else - (regexp-try-match "^ +" i) - (define b (read-byte i)) - (unless (eof-object? b) - (when indent? (indent)) - (write-byte b) - (copy-port i (current-output-port)) - (newline))])) + (define to-wrap (regexp-replace* #rx"\n" (get-output-string o) " ")) + (define lines (wrap-line (string-trim to-wrap) (- 72 (current-indent)))) + (write-string (car lines)) + (for ([line (in-list (cdr lines))]) + (newline) (indent) (write-string line)) + (newline) null) (define/override (render-content i part ri) diff --git a/collects/tests/scribble/docs.rkt b/collects/tests/scribble/docs.rkt index f8814c13..e902165e 100644 --- a/collects/tests/scribble/docs.rkt +++ b/collects/tests/scribble/docs.rkt @@ -23,9 +23,9 @@ (define (docs-tests) (when (or (file-exists? work-dir) (directory-exists? work-dir)) (delete-directory/files work-dir)) - (make-directory work-dir) - (dynamic-wind void - (lambda () + (dynamic-wind + (λ() (make-directory work-dir)) + (λ() (define files (map path-element->string (directory-list source-dir))) (test do (for ([scrbl (in-list files)] @@ -44,4 +44,4 @@ "mismatch for: \"~a\", expected text in: \"~a\", got:\n~a" scrbl txt (contents generated-file)) (string=? (contents expect-file) (contents generated-file)))))) - (lambda () (delete-directory/files work-dir)))) + (λ() (delete-directory/files work-dir)))) diff --git a/collects/tests/scribble/docs/autobib-disambiguation.scrbl b/collects/tests/scribble/docs/autobib-disambiguation.scrbl index 0bcdc597..c7930ff2 100644 --- a/collects/tests/scribble/docs/autobib-disambiguation.scrbl +++ b/collects/tests/scribble/docs/autobib-disambiguation.scrbl @@ -12,7 +12,7 @@ #:location (dissertation-location #:institution "NEU") #:author (authors "Little" "Bo" "Peep") #:date "2012")) -According to the following morons, +According to the following people, @cite[a] @cite[b] @citet[a] @@ -22,4 +22,4 @@ According to the following morons, @citet[a b] @citet[b a] -@gen-bib[] \ No newline at end of file +@gen-bib[] diff --git a/collects/tests/scribble/docs/autobib-disambiguation.txt b/collects/tests/scribble/docs/autobib-disambiguation.txt index ef90e083..a2e61248 100644 --- a/collects/tests/scribble/docs/autobib-disambiguation.txt +++ b/collects/tests/scribble/docs/autobib-disambiguation.txt @@ -1,4 +1,4 @@ -According to the following morons,  (Little et al. 2012a)  (Little et +According to the following people,  (Little et al. 2012a)  (Little et al. 2012b) Little et al. (2012a) Little et al. (2012b)  (Little et al. 2012a,b)  (Little et al. 2012b,a) Little et al. (2012a,b) Little et al. (2012b,a) diff --git a/collects/tests/scribble/docs/wrap.scrbl b/collects/tests/scribble/docs/wrap.scrbl new file mode 100644 index 00000000..4df4cbac --- /dev/null +++ b/collects/tests/scribble/docs/wrap.scrbl @@ -0,0 +1,20 @@ +#lang scribble/manual +@(require (for-label racket/base)) + +@title{Document} + +@itemlist[ + @item{WHEN Zarathustra was thirty years old, he left his home and the + lake of his home, and went into the mountains. There he enjoyed his + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + spirit and his solitude, and for ten years did not weary of it. But + at last his heart changed, - and rising one morning with the rosy + dawn, he went before the sun, and spake thus unto it: Thou great + star! What would be thy happiness if thou hadst not those for whom + thou shinest!}] + +Some text xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@; +xxxxxxxxxxxxxxx some more text + + x xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@; +xxxxxxxxxxxxxxx blah blah diff --git a/collects/tests/scribble/docs/wrap.txt b/collects/tests/scribble/docs/wrap.txt new file mode 100644 index 00000000..9686a568 --- /dev/null +++ b/collects/tests/scribble/docs/wrap.txt @@ -0,0 +1,18 @@ +Document + +* WHEN Zarathustra was thirty years old, he left his home and the lake + of his home, and went into the mountains. There he enjoyed his + xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx + spirit and his solitude, and for ten years did not weary of it. But + at last his heart changed, - and rising one morning with the rosy + dawn, he went before the sun, and spake thus unto it: Thou great star! + What would be thy happiness if thou hadst not those for whom thou + shinest! + +Some text +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +some more text + +x +xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx +blah blah