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
This commit is contained in:
Matthew Flatt 2013-02-15 20:06:50 -07:00
parent a9d7b36e4d
commit d1fc7f41da
4 changed files with 41 additions and 17 deletions

View File

@ -72,7 +72,8 @@
(define/public (format-number number sep) (define/public (format-number number sep)
(if (or (null? number) (if (or (null? number)
(andmap not number) (andmap (lambda (x) (or (not x) (equal? x "")))
number)
(and (not (car number)) (and (not (car number))
(not (ormap number? number)))) (not (ormap number? number))))
null null
@ -81,7 +82,10 @@
string-append string-append
(map (lambda (n) (if (number? n) (format "~a." n) "")) (map (lambda (n) (if (number? n) (format "~a." n) ""))
(reverse (cdr number)))) (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)))) (substring s 0 (sub1 (string-length s))))
sep))) sep)))
@ -520,7 +524,9 @@
(define next-sub-pos (define next-sub-pos
(collect-part s d p-ci (collect-part s d p-ci
(cons (if hidden-number? (cons (if hidden-number?
#f (if sub-grouper?
""
#f)
(if sub-grouper? (if sub-grouper?
(number->roman pos) (number->roman pos)
pos)) pos))
@ -972,9 +978,8 @@
(not (= base-len (sub1 (length number)))))) (not (= base-len (sub1 (length number))))))
(positive? depth)) (positive? depth))
(apply append (map (lambda (p) (apply append (map (lambda (p)
(if (part-style? p 'toc-hidden) (generate-toc p ri base-len (part-style? p 'toc-hidden)
null quiet (sub1 depth) prefixes))
(generate-toc p ri base-len #f quiet (sub1 depth) prefixes)))
(part-parts part))) (part-parts part)))
null)]) null)])
(if skip? (if skip?

View File

@ -517,9 +517,21 @@
(define/public (nearly-top? d ri top) (define/public (nearly-top? d ri top)
#f) #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?) (define/private (render-onthispage-contents d ri top box-class sections-in-toc?)
(if (ormap (lambda (p) (or (part-whole-page? p ri) (if (andmap (lambda (p) (or (part-whole-page? p ri)
(part-style? p 'toc-hidden))) (and (part-style? p 'toc-hidden)
(all-toc-hidden? p))))
(part-parts d)) (part-parts d))
null null
(let ([nearly-top? (lambda (d) (let ([nearly-top? (lambda (d)
@ -566,11 +578,15 @@
prefixes)]) prefixes)])
(append* (append*
;; don't include the section if it's in the TOC ;; 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: ;; get internal targets:
(map (lambda (v) (cons v prefixes)) (append-map block-targets (part-blocks d))) (map (lambda (v) (cons v prefixes)) (append-map block-targets (part-blocks d)))
(map (lambda (p) (if (or (part-whole-page? p ri) (map (lambda (p) (if (or (part-whole-page? p ri)
(part-style? p 'toc-hidden)) (and (part-style? p 'toc-hidden)
(all-toc-hidden? p)))
null null
(flatten p prefixes #f))) (flatten p prefixes #f)))
(part-parts d))))))) (part-parts d)))))))
@ -1464,7 +1480,8 @@
part-whole-page? part-whole-page?
format-number format-number
install-extra-files install-extra-files
report-output?) report-output?
all-toc-hidden?)
(define/override (get-suffix) #"") (define/override (get-suffix) #"")

View File

@ -166,6 +166,7 @@
[else [else
(define no-number? (and (pair? number) (define no-number? (and (pair? number)
(or (not (car number)) (or (not (car number))
(equal? "" (car number))
((length number) . > . 3)))) ((length number) . > . 3))))
(define no-toc? (part-style? d 'toc-hidden)) (define no-toc? (part-style? d 'toc-hidden))
(define (show-number) (define (show-number)

View File

@ -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 The length of the @racket[number] list indicates the section's nesting
depth. Numbers in @racket[number] correspond to the section's number, 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] it's parent's number, etc. A non-empty string is used for a
section, and @racket[#f] is used in place of all numbers for an @racket['grouping] section. For an unnumbered section, @racket[#f] is
unnumbered section.} used in place of all numbers and @racket[""] in place of all non-empty
strings.}
@defstruct[target-url ([addr path-string?])]{ @defstruct[target-url ([addr path-string?])]{