From d1fc7f41daacf7316f7a8093791be5bae9e090e1 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 15 Feb 2013 20:06:50 -0700 Subject: [PATCH] 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 --- collects/scribble/base-render.rkt | 17 +++++++----- collects/scribble/html-render.rkt | 33 ++++++++++++++++++------ collects/scribble/latex-render.rkt | 1 + collects/scribblings/scribble/core.scrbl | 7 ++--- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/collects/scribble/base-render.rkt b/collects/scribble/base-render.rkt index f0241ffe..ed76353a 100644 --- 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 index 3976cd66..6d89789c 100644 --- 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 index 4c39f9bd..196946e0 100644 --- 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 index 0594cdf6..09e7f8d4 100644 --- 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?])]{