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:
parent
6bec5dbd28
commit
dcb28604ca
|
@ -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}(?<! ))(?: |$)" (- 72 amt)))])
|
||||
(hash-set! indent-pxs amt px)
|
||||
px)))
|
||||
|
||||
(define (render-mixin %)
|
||||
(class %
|
||||
|
||||
|
@ -134,26 +125,12 @@
|
|||
(define o (open-output-string))
|
||||
(parameterize ([current-output-port o])
|
||||
(super render-paragraph p part ri))
|
||||
(define i (open-input-string
|
||||
(regexp-replace* #rx"\n" (get-output-string o) " ")))
|
||||
(define px (indent->paragraph-px (current-indent)))
|
||||
(let loop ([indent? #f])
|
||||
(cond
|
||||
[(or (regexp-try-match px i)
|
||||
(regexp-try-match #px"^ *(.+(?<! ))(?: |$)" i))
|
||||
=> (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)
|
||||
|
|
|
@ -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))))
|
||||
|
|
|
@ -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[]
|
||||
@gen-bib[]
|
||||
|
|
|
@ -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)
|
||||
|
|
20
collects/tests/scribble/docs/wrap.scrbl
Normal file
20
collects/tests/scribble/docs/wrap.scrbl
Normal 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
|
18
collects/tests/scribble/docs/wrap.txt
Normal file
18
collects/tests/scribble/docs/wrap.txt
Normal 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
|
Loading…
Reference in New Issue
Block a user