diff --git a/collects/scribble/eval.rkt b/collects/scribble/eval.rkt index 96a8fab0..df9e8f8c 100644 --- a/collects/scribble/eval.rkt +++ b/collects/scribble/eval.rkt @@ -6,7 +6,8 @@ racket/pretty ;; attached into new namespace via anchor racket/sandbox racket/promise racket/port racket/gui/dynamic - (for-syntax racket/base)) + (for-syntax racket/base) + scribble/text/wrap) (provide interaction interaction0 @@ -102,19 +103,12 @@ (loop #f (cons v (or (add-string string-accum line-accum) null)) flow-accum)])))) -;; This is probably good to make into some library function at some -;; point (but in that case will need to improve, eg, wrapped lines -;; should start at the same indentation level, etc) (define (string->wrapped-lines str) - (define (wrap-line str) - (if ((string-length str) . <= . maxlen) - (if (equal? str "") '() (list str)) - (let* ([m (cond [(regexp-match-positions #px"^.*\\S(\\s+).*" str 0 maxlen) - => cadr] - [else (cons maxlen maxlen)])] - [r (wrap-line (substring str (cdr m)))]) - (if (= 0 (car m)) r (cons (substring str 0 (car m)) r))))) - (append-map wrap-line (regexp-split #px"\\s*\n" str))) + (wrap-line str maxlen + (λ (word fits) + (if ((string-length word) . > . maxlen) + (values (substring word 0 fits) (substring word fits) #f) + (values #f word #f))))) (define (interleave inset? title expr-paras val-list+outputs) (let ([lines diff --git a/collects/scribble/text/wrap.rkt b/collects/scribble/text/wrap.rkt index 6749a685..b7336856 100644 --- a/collects/scribble/text/wrap.rkt +++ b/collects/scribble/text/wrap.rkt @@ -21,7 +21,7 @@ ;; element is used for the rest. For example, (cons 72 70) indicates a width ;; of 72 characters for the first line, and 70 for the rest. ;; -;; `split-word' controls what happens when a word is split: it is ivoked with +;; `split-word' controls what happens when a word is split: it is invoked with ;; the word that is to be split, and an integer indicating how many characters ;; could fit on the first line. In most cases the string will be just a word, ;; but if it was the first/last word with only spaces before/after it, then the @@ -36,13 +36,13 @@ ;; words; spaces between a word that moves to the next line and the preceding ;; word are usually dropped, but they can be preserved too if the first result ;; is "" rather than #f (and same for the space between a word that stays on -;; the same line when the following word moves doen). If the first result is +;; the same line when the following word moves down). If the first result is ;; `#f' and it was the only word on the line, then the line that would ;; otherwise be empty is dropped. Note that depending on what `split-word' ;; chooses to do, the result may still have lines that are longer than `width' ;; characters. The default `split-word' returns (values #f the-word #t). ;; -;; Sidenote: never returns an empty list. +;; Side note: never returns an empty list. ;; ;; Caveats: considers only spaces as whitespace; not too efficient since it ;; constructs intermediate strings for its processing; the need for the third