more consistent cleaning of index strings; fix for 'get-module-code' when no file (source, bytecode, or extension) is available

svn: r10002
This commit is contained in:
Matthew Flatt 2008-05-28 17:40:23 +00:00
parent 3d4761f027
commit fdd99b83dc
9 changed files with 53 additions and 34 deletions

View File

@ -161,24 +161,11 @@
;; ---------------------------------------- ;; ----------------------------------------
(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) (define (section-index . elems)
(make-part-index-decl (map element->string elems) elems)) (make-part-index-decl (map element->string elems) elems))
(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) (define (record-index word-seq element-seq tag content)
(make-index-element #f (make-index-element #f
(list (make-target-element #f content `(idx ,tag))) (list (make-target-element #f content `(idx ,tag)))
@ -189,11 +176,11 @@
(define (index* word-seq content-seq . s) (define (index* word-seq content-seq . s)
(let ([key (make-generated-tag)]) (let ([key (make-generated-tag)])
(record-index word-seq content-seq key (decode-content s)))) (record-index (map clean-up-index-string word-seq) content-seq key (decode-content s))))
(define (index word-seq . s) (define (index word-seq . s)
(let ([word-seq (if (string? word-seq) (list word-seq) word-seq)]) (let ([word-seq (if (string? word-seq) (list word-seq) word-seq)])
(apply index* word-seq word-seq s))) (apply index* (map clean-up-index-string word-seq) word-seq s)))
(define (as-index . s) (define (as-index . s)
(let ([key (make-generated-tag)] (let ([key (make-generated-tag)]

View File

@ -12,7 +12,8 @@
decode-content decode-content
(rename-out [decode-content decode-elements]) (rename-out [decode-content decode-elements])
decode-string decode-string
whitespace?) whitespace?
clean-up-index-string)
(provide-structs (provide-structs
[title-decl ([tag-prefix (or/c false/c string?)] [title-decl ([tag-prefix (or/c false/c string?)]
@ -31,6 +32,18 @@
[part-collect-decl ([element (or/c element? part-relative-element?)])] [part-collect-decl ([element (or/c element? part-relative-element?)])]
[part-tag-decl ([tag tag?])]) [part-tag-decl ([tag tag?])])
(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 (decode-string s) (define (decode-string s)
(let loop ([l '((#rx"---" mdash) (let loop ([l '((#rx"---" mdash)
(#rx"--" ndash) (#rx"--" ndash)
@ -88,9 +101,10 @@
(and (list? style) (memq 'hidden style))))) (and (list? style) (memq 'hidden style)))))
(cons (make-index-element (cons (make-index-element
#f null (car tags) #f null (car tags)
(list (regexp-replace (list (clean-up-index-string
#px"^\\s+(?:(?:A|An|The)\\s)?" (regexp-replace
(content->string title) "")) #px"^\\s+(?:(?:A|An|The)\\s)?"
(content->string title) "")))
(list (make-element #f title)) (list (make-element #f title))
(make-part-index-desc)) (make-part-index-desc))
l) l)

View File

@ -585,7 +585,7 @@
(make-index-element #f (make-index-element #f
(list t) (list t)
(target-element-tag t) (target-element-tag t)
(list (element->string e)) (list (clean-up-index-string (element->string e)))
(list e) (list e)
'tech))) 'tech)))

View File

@ -124,6 +124,10 @@
(blockquote? p) (blockquote? p)
(delayed-block? p))) (delayed-block? p)))
(define (string-without-newline? s)
(and (string? s)
(not (regexp-match? #rx"\n" s))))
(provide-structs (provide-structs
[part ([tag-prefix (or/c false/c string?)] [part ([tag-prefix (or/c false/c string?)]
[tags (listof tag?)] [tags (listof tag?)]
@ -156,7 +160,7 @@
[alt-anchor string?])] [alt-anchor string?])]
[(link-element element) ([tag tag?])] [(link-element element) ([tag tag?])]
[(index-element element) ([tag tag?] [(index-element element) ([tag tag?]
[plain-seq (listof string?)] [plain-seq (and/c pair? (listof string-without-newline?))]
[entry-seq list?] [entry-seq list?]
[desc any/c])] [desc any/c])]
[(aux-element element) ()] [(aux-element element) ()]

View File

@ -81,8 +81,9 @@ The @scheme[vers] argument is propagated to the @scheme[title-decl]
structure. structure.
The section title is automatically indexed by The section title is automatically indexed by
@scheme[decode-part]. For the index key, a leading ``A'', ``An'', or @scheme[decode-part]. For the index key, leading whitespace and a
``The'' (followed by whitespace) is removed.} leading ``A'', ``An'', or ``The'' (followed by more whitespace) is
removed.}
@def-section-like[section part-start?]{ Like @scheme[title], but @def-section-like[section part-start?]{ Like @scheme[title], but
@ -171,10 +172,11 @@ Wraps the @tech{decode}d @scheme[pre-content] as an element with style
Creates an index element given a plain-text string---or list of Creates an index element given a plain-text string---or list of
strings for a hierarchy, such as @scheme['("strings" "plain")] for a strings for a hierarchy, such as @scheme['("strings" "plain")] for a
``plain'' entry below a more general ``strings'' entry. The strings ``plain'' entry below a more general ``strings'' entry. As index keys,
also serve as the text to render in the index. The @tech{decode}d the strings are ``cleaned'' using @scheme[clean-up-index-strings]. The
@scheme[pre-content] is the text to appear inline as the index strings (without clean-up) also serve as the text to render in the
target.} index. The @tech{decode}d @scheme[pre-content] is the text to appear
inline as the index target.}
@defproc[(index* [words (listof string?)] @defproc[(index* [words (listof string?)]

View File

@ -159,3 +159,8 @@ See @scheme[decode], @scheme[decode-part], and @scheme[decode-flow].
} }
@defproc[(clean-up-index-string [str string?]) string?]{
Trims leading and trailing whitespace, and converts non-empty
sequences of whitespace to a single space character.}

View File

@ -441,7 +441,7 @@ Hyperlinks the content to @scheme[tag].
@defstruct[(index-element element) ([tag tag?] @defstruct[(index-element element) ([tag tag?]
[plain-seq (and/c (listof string?) cons?)] [plain-seq (and/c pair? (listof string?))]
[entry-seq list?] [entry-seq list?]
[desc any/c])]{ [desc any/c])]{
@ -453,7 +453,8 @@ former would be represented by @scheme[plain-seq] @scheme['("night"
"things that go bump in")], and the latter by @scheme['("night" "things that go bump in")], and the latter by @scheme['("night"
"defender of the")]. Naturally, single-@tech{element} "defender of the")]. Naturally, single-@tech{element}
@scheme[plain-seq] lists are the common case, and at least one word is @scheme[plain-seq] lists are the common case, and at least one word is
required, but there is no limit to the word-list length. required, but there is no limit to the word-list length. The strings in
@scheme[plain-seq] must not contain a newline character.
The @scheme[entry-seq] list must have the same length as The @scheme[entry-seq] list must have the same length as
@scheme[plain-seq]. It provides the form of each key to render in the @scheme[plain-seq]. It provides the form of each key to render in the

View File

@ -353,7 +353,14 @@
(make-info (make-info
doc doc
(list-ref v-out 1) ; sci (list-ref v-out 1) ; sci
(list-ref v-out 2) ; provides (let ([v (list-ref v-out 2)]) ; provides
(if (not (and (pair? v) ; temporary compatibility; used to be not serialized
(pair? (car v))
(integer? (caar v))))
v
(with-my-namespace
(lambda ()
(deserialize v)))))
(let ([v (list-ref v-in 1)]) ; undef (let ([v (list-ref v-in 1)]) ; undef
(if (not (and (pair? v) ; temporary compatibility; used to be not serialized (if (not (and (pair? v) ; temporary compatibility; used to be not serialized
(pair? (car v)) (pair? (car v))
@ -535,7 +542,7 @@
(sel (lambda () (sel (lambda ()
(list (list (info-vers info) (doc-flags doc)) (list (list (info-vers info) (doc-flags doc))
(info-sci info) (info-sci info)
(info-provides info))) (serialize (info-provides info))))
(lambda () (lambda ()
(list (list (info-vers info) (doc-flags doc)) (list (list (info-vers info) (doc-flags doc))
(serialize (info-undef info)) (serialize (info-undef info))

View File

@ -111,8 +111,7 @@
;; Maybe there's an .so? Use it only if we don't prefer source. ;; Maybe there's an .so? Use it only if we don't prefer source.
[(or (eq? prefer 'so) [(or (eq? prefer 'so)
(and (not prefer) (and (not prefer)
(or (not path-d) (date>=? so path-d)))
(date>=? so path-d))))
(if extension-handler (if extension-handler
(begin (begin
(notify so) (notify so)