commit d1fc7f41daacf7316f7a8093791be5bae9e090e1
parent a9d7b36e4d4432f29d0fec932a0a2cbb483486fe
Author: Matthew Flatt <mflatt@racket-lang.org>
Date: Fri, 15 Feb 2013 20:06:50 -0700
scribble: improve HTML handling of 'unnumbered and 'toc-hidden
A part with style property 'toc-hidden no longer
hides child sections, which makes it consistent with Latex/PDF
rendering.
A part with style 'grouper and 'unnumbered does not make its
child parts render as more nested, which is consistent with
'gruper without 'unnumbered. An unnumbered grouper is represented
as "" in a section-number list (while #f is still used for
unnumbered non-grouper layers).
original commit: 23d0627acc36998dc76ebd840276c80f47cab459
Diffstat:
4 files changed, 41 insertions(+), 17 deletions(-)
diff --git a/collects/scribble/base-render.rkt b/collects/scribble/base-render.rkt
@@ -72,7 +72,8 @@
(define/public (format-number number sep)
(if (or (null? number)
- (andmap not number)
+ (andmap (lambda (x) (or (not x) (equal? x "")))
+ number)
(and (not (car number))
(not (ormap number? number))))
null
@@ -81,7 +82,10 @@
string-append
(map (lambda (n) (if (number? n) (format "~a." n) ""))
(reverse (cdr number))))
- (if (car number) (format "~a." (car number)) ""))])
+ (if (and (car number)
+ (not (equal? "" (car number))))
+ (format "~a." (car number))
+ ""))])
(substring s 0 (sub1 (string-length s))))
sep)))
@@ -520,7 +524,9 @@
(define next-sub-pos
(collect-part s d p-ci
(cons (if hidden-number?
- #f
+ (if sub-grouper?
+ ""
+ #f)
(if sub-grouper?
(number->roman pos)
pos))
@@ -972,9 +978,8 @@
(not (= base-len (sub1 (length number))))))
(positive? depth))
(apply append (map (lambda (p)
- (if (part-style? p 'toc-hidden)
- null
- (generate-toc p ri base-len #f quiet (sub1 depth) prefixes)))
+ (generate-toc p ri base-len (part-style? p 'toc-hidden)
+ quiet (sub1 depth) prefixes))
(part-parts part)))
null)])
(if skip?
diff --git a/collects/scribble/html-render.rkt b/collects/scribble/html-render.rkt
@@ -517,10 +517,22 @@
(define/public (nearly-top? d ri top)
#f)
+ (define hidden-memo (make-weak-hasheq))
+ (define/public (all-toc-hidden? p)
+ (hash-ref hidden-memo
+ p
+ (lambda ()
+ (define h? (and (part-style? p 'toc-hidden)
+ (andmap (lambda (s) (all-toc-hidden? s))
+ (part-parts p))))
+ (hash-set! hidden-memo p h?)
+ h?)))
+
(define/private (render-onthispage-contents d ri top box-class sections-in-toc?)
- (if (ormap (lambda (p) (or (part-whole-page? p ri)
- (part-style? p 'toc-hidden)))
- (part-parts d))
+ (if (andmap (lambda (p) (or (part-whole-page? p ri)
+ (and (part-style? p 'toc-hidden)
+ (all-toc-hidden? p))))
+ (part-parts d))
null
(let ([nearly-top? (lambda (d)
;; If ToC would be collapsed, then
@@ -560,18 +572,22 @@
(table-blockss table)))
(define ps
((if (nearly-top? d) values cdr)
- (let flatten ([d d][prefixes null][top? #t])
+ (let flatten ([d d] [prefixes null] [top? #t])
(let ([prefixes (if (and (not top?) (part-tag-prefix d))
(cons (part-tag-prefix d) prefixes)
prefixes)])
(append*
;; don't include the section if it's in the TOC
- (if (nearly-top? d) null (list (cons d prefixes)))
+ (if (or (nearly-top? d)
+ (part-style? d 'toc-hidden))
+ null
+ (list (cons d prefixes)))
;; get internal targets:
(map (lambda (v) (cons v prefixes)) (append-map block-targets (part-blocks d)))
(map (lambda (p) (if (or (part-whole-page? p ri)
- (part-style? p 'toc-hidden))
- null
+ (and (part-style? p 'toc-hidden)
+ (all-toc-hidden? p)))
+ null
(flatten p prefixes #f)))
(part-parts d)))))))
(define any-parts? (ormap (compose part? car) ps))
@@ -1464,7 +1480,8 @@
part-whole-page?
format-number
install-extra-files
- report-output?)
+ report-output?
+ all-toc-hidden?)
(define/override (get-suffix) #"")
diff --git a/collects/scribble/latex-render.rkt b/collects/scribble/latex-render.rkt
@@ -166,6 +166,7 @@
[else
(define no-number? (and (pair? number)
(or (not (car number))
+ (equal? "" (car number))
((length number) . > . 3))))
(define no-toc? (part-style? d 'toc-hidden))
(define (show-number)
diff --git a/collects/scribblings/scribble/core.scrbl b/collects/scribblings/scribble/core.scrbl
@@ -1016,9 +1016,10 @@ Computed for each part by the @techlink{collect pass}.
The length of the @racket[number] list indicates the section's nesting
depth. Numbers in @racket[number] correspond to the section's number,
-it's parent's number, etc. A string is used for a @racket['grouping]
-section, and @racket[#f] is used in place of all numbers for an
-unnumbered section.}
+it's parent's number, etc. A non-empty string is used for a
+@racket['grouping] section. For an unnumbered section, @racket[#f] is
+used in place of all numbers and @racket[""] in place of all non-empty
+strings.}
@defstruct[target-url ([addr path-string?])]{