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
This commit is contained in:
Eli Barzilay 2012-05-06 07:42:28 -04:00
parent 6bec5dbd28
commit dcb28604ca
6 changed files with 53 additions and 38 deletions

View File

@ -1,8 +1,6 @@
#lang racket/base #lang racket/base
(require "core.rkt" (require "core.rkt" racket/class racket/port racket/list racket/string
racket/class scribble/text/wrap)
racket/port
racket/list)
(provide render-mixin) (provide render-mixin)
(define current-preserve-spaces (make-parameter #f)) (define current-preserve-spaces (make-parameter #f))
@ -17,13 +15,6 @@
(newline) (newline)
(indent)) (indent))
(define indent-pxs (make-hash))
(define (indent->paragraph-px amt)
(or (hash-ref indent-pxs amt #f)
(let ([px (pregexp (format "^ *(.{1,~a}(?<! ))(?: |$)" (- 72 amt)))])
(hash-set! indent-pxs amt px)
px)))
(define (render-mixin %) (define (render-mixin %)
(class % (class %
@ -134,26 +125,12 @@
(define o (open-output-string)) (define o (open-output-string))
(parameterize ([current-output-port o]) (parameterize ([current-output-port o])
(super render-paragraph p part ri)) (super render-paragraph p part ri))
(define i (open-input-string (define to-wrap (regexp-replace* #rx"\n" (get-output-string o) " "))
(regexp-replace* #rx"\n" (get-output-string o) " "))) (define lines (wrap-line (string-trim to-wrap) (- 72 (current-indent))))
(define px (indent->paragraph-px (current-indent))) (write-string (car lines))
(let loop ([indent? #f]) (for ([line (in-list (cdr lines))])
(cond (newline) (indent) (write-string line))
[(or (regexp-try-match px i)
(regexp-try-match #px"^ *(.+(?<! ))(?: |$)" i))
=> (lambda (m)
(when indent? (indent))
(write-bytes (cadr m))
(newline) (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))]))
null) null)
(define/override (render-content i part ri) (define/override (render-content i part ri)

View File

@ -23,9 +23,9 @@
(define (docs-tests) (define (docs-tests)
(when (or (file-exists? work-dir) (directory-exists? work-dir)) (when (or (file-exists? work-dir) (directory-exists? work-dir))
(delete-directory/files work-dir)) (delete-directory/files work-dir))
(make-directory work-dir) (dynamic-wind
(dynamic-wind void (λ() (make-directory work-dir))
(lambda () (λ()
(define files (map path-element->string (directory-list source-dir))) (define files (map path-element->string (directory-list source-dir)))
(test do (test do
(for ([scrbl (in-list files)] (for ([scrbl (in-list files)]
@ -44,4 +44,4 @@
"mismatch for: \"~a\", expected text in: \"~a\", got:\n~a" "mismatch for: \"~a\", expected text in: \"~a\", got:\n~a"
scrbl txt (contents generated-file)) scrbl txt (contents generated-file))
(string=? (contents expect-file) (contents generated-file)))))) (string=? (contents expect-file) (contents generated-file))))))
(lambda () (delete-directory/files work-dir)))) (λ() (delete-directory/files work-dir))))

View File

@ -12,7 +12,7 @@
#:location (dissertation-location #:institution "NEU") #:location (dissertation-location #:institution "NEU")
#:author (authors "Little" "Bo" "Peep") #:author (authors "Little" "Bo" "Peep")
#:date "2012")) #:date "2012"))
According to the following morons, According to the following people,
@cite[a] @cite[a]
@cite[b] @cite[b]
@citet[a] @citet[a]

View File

@ -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. 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 2012a,b)  (Little et al. 2012b,a) Little et al. (2012a,b) Little et
al. (2012b,a) al. (2012b,a)

View File

@ -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

View File

@ -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