Debian Codegraph @

ru/stylesheets/hhautoc.dsl

raw
1 ;; $Id$
2 ;;
3 ;; This file is part of the Modular DocBook Stylesheet distribution.
4 ;; See ../README or http://www.berkshire.net/~norm/dsssl/
5 ;;
6
7 ;; ========================== TABLE OF CONTENTS =========================
8
9 ;; Returns the depth of auto TOC that should be made at the nd-level
10 (define (toc-depth nd)
11 (cond ((string=? (gi nd) (normalize "set")) 4)
12 ((string=? (gi nd) (normalize "book")) 3)
13 ((string=? (gi nd) (normalize "chapter")) 2)
14 ((string=? (gi nd) (normalize "appendix")) 2)
15 ((string=? (gi nd) (normalize "preface")) 2)
16 (else 1)))
17
18 (define (build-tocentry tocentry)
19 (make-element gi: "OBJECT"
20 attributes: (list (list "type" "text/sitemap"))
21 (let* ((label (if (equal? (element-label tocentry) "")
22 ""
23 (string-append
24 (element-label tocentry)
25 (gentext-label-title-sep
26 (gi tocentry)))))
27 (title (element-title-string tocentry))
28 (name (if (equal? label "")
29 title
30 (string-append
31 label title)))
32 (href (href-to tocentry)))
33 (make sequence
34 (make-empty-element gi: "param"
35 attributes: (list (list "name" "Name")
36 (list "value" name)))
37 (make-empty-element gi: "param"
38 attributes: (list (list "name" "Local")
39 (list "value" href)))))))
40
41 (define (alpha toclist)
42 (if (node-list-empty? toclist)
43 toclist
44 (let* ((first-title (element-title-string (node-list-first toclist)))
45 (first-letter (case-fold-up (substring first-title 0 1))))
46 (let loop ((match (node-list-first toclist))
47 (rest (node-list-rest toclist)))
48 (if (node-list-empty? rest)
49 match
50 (let* ((next-title (element-title-string (node-list-first rest)))
51 (next-letter (case-fold-up (substring next-title 0 1))))
52 (if (equal? first-letter next-letter)
53 (loop (node-list match (node-list-first rest))
54 (node-list-rest rest))
55 match)))))))
56
57 (define (alpha-rest toclist)
58 (if (node-list-empty? toclist)
59 toclist
60 (let* ((first-title (element-title-string (node-list-first toclist)))
61 (first-letter (case-fold-up (substring first-title 0 1))))
62 (let loop ((match (node-list-first toclist))
63 (rest (node-list-rest toclist)))
64 (if (node-list-empty? rest)
65 rest
66 (let* ((next-title (element-title-string (node-list-first rest)))
67 (next-letter (case-fold-up (substring next-title 0 1))))
68 (if (equal? first-letter next-letter)
69 (loop (node-list match (node-list-first rest))
70 (node-list-rest rest))
71 rest)))))))
72
73 (define (build-toc-list nd depth toclist #!optional (chapter-toc? #f) (first? #t))
74 (if (and (equal? (gi nd) (normalize "reference"))
75 (equal? (attribute-string (normalize "role") nd)
76 "folders"))
77 (let alphaloop ((alist (alpha toclist))
78 (rest (alpha-rest toclist)))
79 (if (node-list-empty? alist)
80 (empty-sosofo)
81
82 (make sequence
83
84 (make-element gi: "LI"
85 (make-element gi: "OBJECT"
86 attributes: '(("type" "text/sitemap"))
87 (make-empty-element gi: "param"
88 attributes: (list (list "name" "Name")
89 (list "value" (case-fold-up (substring (element-title-string (node-list-first alist)) 0 1))))))
90
91 (make-element gi: "UL"
92 (let loop ((nl alist))
93 (if (node-list-empty? nl)
94 (empty-sosofo)
95 (make-element gi: "LI"
96 (build-tocentry (node-list-first nl))
97 (build-toc (node-list-first nl)
98 (- depth 1) chapter-toc? #f)
99 (loop (node-list-rest nl)))))))
100 (alphaloop (alpha rest) (alpha-rest rest)))))
101
102 (let loop ((nl toclist))
103 (if (node-list-empty? nl)
104 (empty-sosofo)
105 (make sequence
106 (make-element gi: "LI"
107 (build-tocentry (node-list-first nl))
108 (build-toc (node-list-first nl)
109 (- depth 1) chapter-toc? #f))
110 (loop (node-list-rest nl)))))))
111
112 (define (build-toc nd depth #!optional (chapter-toc? #f) (first? #t))
113 (let ((toclist (toc-list-filter
114 (node-list-filter-by-gi (children nd)
115 (append (book-element-list)
116 (division-element-list)
117 (component-element-list)
118 (section-element-list))))))
119 (if (or (<= depth 0)
120 (node-list-empty? toclist)
121 (and chapter-toc?
122 (not %force-chapter-toc%)
123 (<= (node-list-length toclist) 1)))
124 (empty-sosofo)
125 (if first?
126 (build-toc-list nd depth toclist chapter-toc? first?)
127 (make-element gi: "UL"
128 (build-toc-list nd depth toclist chapter-toc? first?))))))
129
130
131
132
133