commit 449670964dab0fed0aa69eb64068d62d80dbad22
parent 5f941495b665305caea08bde945c90994864d717
Author: Matthew Flatt <mflatt@racket-lang.org>
Date: Mon, 19 May 2008 13:14:10 +0000
better clean-up of index strings derved from body text
svn: r9886
original commit: 35d8fc32595922acbf91ddb89de13c95b163e1cc
Diffstat:
2 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/collects/scribble/basic.ss b/collects/scribble/basic.ss
@@ -161,15 +161,22 @@
;; ----------------------------------------
-(provide section-index index index* as-index index-section index-blocks)
+(provide section-index index index* as-index index-section index-blocks
+ clean-up-index-string)
(define (section-index . elems)
(make-part-index-decl (map element->string elems) elems))
-(define (clean-up s)
- ;; Remove leading spaces, which might appear there due to images or something
- ;; else that gets dropped in string form.
- (regexp-replace #rx"^ +" s ""))
+(define (clean-up-index-string s)
+ ;; Remove leading spaces or trailing, which might appear there due
+ ;; to images or something else that gets dropped in string form.
+ ;; Then collapse whitespace.
+ (regexp-replace* #px"\\s+"
+ (regexp-replace #rx"^ +"
+ (regexp-replace #rx" +$"
+ s
+ ""))
+ " "))
(define (record-index word-seq element-seq tag content)
(make-index-element #f
@@ -190,7 +197,7 @@
(define (as-index . s)
(let ([key (make-generated-tag)]
[content (decode-content s)])
- (record-index (list (clean-up (content->string content)))
+ (record-index (list (clean-up-index-string (content->string content)))
(if (= 1 (length content))
content
(list (make-element #f content)))
diff --git a/collects/scribble/manual.ss b/collects/scribble/manual.ss
@@ -292,7 +292,9 @@
(define (indexed-file . str)
(let* ([f (apply filepath str)]
[s (element->string f)])
- (index* (list (substring s 1 (sub1 (string-length s)))) (list f) f)))
+ (index* (list (clean-up-index-string (substring s 1 (sub1 (string-length s)))))
+ (list f)
+ f)))
(define (exec . str)
(if (andmap string? str)
(make-element 'tt str)