File: dbindex.dsl

package info (click to toggle)
docbook-stylesheets 1.49-1
  • links: PTS
  • area: main
  • in suites: potato
  • size: 7,576 kB
  • ctags: 33
  • sloc: perl: 444; xml: 115; makefile: 98; sh: 27
file content (371 lines) | stat: -rw-r--r-- 11,159 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
;; $Id: dbindex.dsl,v 1.8 1998/11/19 15:43:43 nwalsh Exp $
;;
;; This file is part of the Modular DocBook Stylesheet distribution.
;; See ../README or http://www.berkshire.net/~norm/dsssl/
;;

;; ................... INDEX TERMS (EMBEDDED MARKERS) ...................

(element indexterm 
  (if html-index
      (let* ((id (if (attribute-string (normalize "id"))
		     (attribute-string (normalize "id"))
		     (generate-anchor))))
	(make element gi: "A"
	      attributes: (list (list "NAME" id))
	      (empty-sosofo)))
      (empty-sosofo)))

(element primary (empty-sosofo))
(element secondary (empty-sosofo))
(element tertiary (empty-sosofo))
(element see (empty-sosofo))
(element seealso (empty-sosofo))

;; =========================== INDEX ELEMENTS ===========================

(element (setindex title) (empty-sosofo))
(element setindex
  (let ((preamble (node-list-filter-by-not-gi 
		   (children (current-node))
		   (list (normalize "indexentry"))))
	(entries  (node-list-filter-by-gi
		   (children (current-node))
		   (list (normalize "indexentry")))))
    (html-document 
     (with-mode head-title-mode 
       (literal (element-title-string (current-node))))
     (make sequence
       ($component-separator$)
       ($component-title$)
       (process-node-list preamble)
       (if (node-list-empty? entries)
	   (empty-sosofo)
	   (make element gi: "DL"
		 (process-node-list entries)))))))

(element (index title) (empty-sosofo))
(element index 
  (let ((preamble (node-list-filter-by-not-gi 
		   (children (current-node))
		   (list (normalize "indexentry"))))
	(entries  (node-list-filter-by-gi
		   (children (current-node))
		   (list (normalize "indexentry")))))
    (html-document 
     (with-mode head-title-mode 
       (literal (element-title-string (current-node))))
     (make sequence
       ($component-separator$)
       ($component-title$)
       (process-node-list preamble)
       (if (node-list-empty? entries)
	   (empty-sosofo)
	   (make element gi: "DL"
		 (process-node-list entries)))))))


(element (indexdiv title) (empty-sosofo))
(element indexdiv
  (let ((preamble (node-list-filter-by-not-gi 
		   (children (current-node))
		   (list (normalize "indexentry"))))
	(entries  (node-list-filter-by-gi
		   (children (current-node))
		   (list (normalize "indexentry")))))
    (html-document
     (with-mode head-title-mode
       (literal (element-title-string (current-node))))
     (make sequence
       ($section-separator$)
       ($section-title$)
       (process-node-list preamble)
       (if (node-list-empty? entries)
	   (empty-sosofo)
	   (make element gi: "DL"
		 (process-node-list entries)))))))

(define (break-node-list nodes breakatgi)
  ;; Given a _node_ list "PRIM SEC TERT SEC SEC TERT PRIM SEC PRIM PRIM"
  ;; and the breakatgi of "PRIM", returns the _list_ of _node_ lists:
  ;; '("PRIM SEC TERT SEC SEC TERT" "PRIM SEC" "PRIM" "PRIM")
  (let loop ((nl nodes) (result '()) (curlist (empty-node-list)))
    (if (node-list-empty? nl)
	(if (node-list-empty? curlist)
	    result
	    (append result (list curlist)))
	(if (equal? (gi (node-list-first nl)) breakatgi)
	    (loop (node-list-rest nl)
		  (if (node-list-empty? curlist)
		      result
		      (append result (list curlist)))
		  (node-list-first nl))
	    (loop (node-list-rest nl)
		  result
		  (node-list curlist (node-list-first nl)))))))

(define (process-primary primnode secnl)
  (let ((see?     (equal? (gi (node-list-first secnl)) 
			  (normalize "seeie")))
	(seealso? (equal? (gi (node-list-first secnl))
			  (normalize "seealsoie")))
	(second   (break-node-list secnl (normalize "secondaryie"))))
    (if (or see? seealso?)
	(process-terminal primnode secnl #t)
	(make sequence
	  (process-nonterminal primnode)
	  (if (node-list-empty? secnl)
	      (empty-sosofo)
	      (make element gi: "DD"
		    (make element gi: "DL"
			  (let sloop ((secs second))
			    (if (null? secs)
				(empty-sosofo)
				(make sequence
				  (let* ((nodes (car secs))
					 (sec   (node-list-first nodes))
					 (terts (node-list-rest nodes)))
				    (process-secondary sec terts))
				  (sloop (cdr secs))))))))))))

(define (process-secondary secnode tertnl)
  (let ((see?     (equal? (gi (node-list-first tertnl))
			  (normalize "seeie")))
	(seealso? (equal? (gi (node-list-first tertnl))
			  (normalize "seealsoie")))
	(tert (break-node-list tertnl (normalize "tertiaryie"))))
    (if (or see? seealso?)
	(process-terminal secnode tertnl)
	(make sequence
	  (process-nonterminal secnode)
	  (make element gi: "DD"
		(make element gi: "DL"
		      (let tloop ((terts tert))
			(if (null? terts)
			    (empty-sosofo)
			    (make sequence
			      (let* ((nodes (car terts))
				     (tert  (node-list-first nodes))
				     (sees  (node-list-rest nodes)))
				(process-tertiary tert sees))
			      (tloop (cdr terts)))))))))))

(define (process-tertiary tertnode seenl)
  (process-terminal tertnode seenl))

(define (process-terminal node seenl #!optional (output-id #f))
  (let ((id (attribute-string (normalize "id") (parent node))))
    (make sequence
      (make element gi: "DT"
	    (if id
		(make element gi: "A"
		      attributes: (list (list "NAME" id))
		      (empty-sosofo))
		(empty-sosofo))
	    (process-node-list node))
      (if (node-list-empty? seenl)
	  (empty-sosofo)
	  (make element gi: "DD"
		(make element gi: "DL"
		      (let loop ((nl seenl))
			(if (node-list-empty? nl)
			    (empty-sosofo)
			    (make sequence
			      (make element gi: "DT"
				    (process-node-list 
				     (node-list-first nl)))
			      (loop (node-list-rest nl)))))))))))

(define (process-nonterminal node)
  (make element gi: "DT"
	(process-node-list node)))

(element indexentry
  (let* ((primary   (break-node-list (children (current-node))
				     (normalize "primaryie"))))
    (make sequence
      (let ploop ((prims primary))
	(if (null? prims)
	    (empty-sosofo)
	    (make sequence
	      (let* ((nodes (car prims))
		     (prim  (node-list-first nodes))
		     (secs  (node-list-rest nodes)))
		(process-primary prim secs))
	      (ploop (cdr prims))))))))

(element primaryie (process-children))
(element secondaryie (process-children))
(element tertiaryie (process-children))

(define (indexentry-link nd)
  (let* ((preferred (not (node-list-empty?
			  (select-elements (children (current-node))
					   (normalize "emphasis"))))))
    (make element gi: "A"
	  attributes: (list (list "HREF" 
				  (attribute-string (normalize "url"))))
	  (process-children))))

(element (primaryie ulink)
  (indexentry-link (current-node)))

(element (secondaryie ulink)
  (indexentry-link (current-node)))

(element (tertiaryie ulink)
  (indexentry-link (current-node)))

(element seeie 
  (let ((linkend (attribute-string (normalize "linkend"))))
      (if linkend
	  (make element gi: "A"
		attributes: (list (list "HREF" 
					(href-to (element-with-id linkend))))
		(literal (gentext-element-name (current-node)))
		(literal (gentext-label-title-sep (current-node)))
		(process-children))
	  (make sequence
	    (literal (gentext-element-name (current-node)))
	    (literal (gentext-label-title-sep (current-node)))
	    (process-children)))))

(element seealsoie
  (let* ((alinkends (attribute-string (normalize "linkends")))
	 (linkends  (if alinkends
			(split alinkends)
			'()))
	 (linkend   (if alinkends
			(car linkends)
			#f)))
    (if linkend
	(make element gi: "A"
	      attributes: (list (list "HREF" 
				      (href-to (element-with-id linkend))))
	      (literal (gentext-element-name (current-node)))
	      (literal (gentext-label-title-sep (current-node)))
	      (process-children))
	(make sequence
	  (literal (gentext-element-name (current-node)))
	  (literal (gentext-label-title-sep (current-node)))
	  (process-children)))))

;; =====================HTML INDEX PROCESSING ==============================

(define (htmlnewline)
  (make formatting-instruction data: "
"))

(define (htmlindexattr attr)
  (if (attribute-string (normalize attr))
      (make sequence
	(make formatting-instruction data: attr)
	(make formatting-instruction data: " ")
	(make formatting-instruction data: (attribute-string 
					    (normalize attr)))
	(htmlnewline))
      (empty-sosofo)))

(define (htmlindexterm)
  (let* ((attr    (gi (current-node)))
	 (content (data (current-node)))
	 (string  (string-replace content "
" " "))
	 (sortas  (attribute-string (normalize "sortas"))))
    (make sequence
      (make formatting-instruction data: attr)
      (if sortas
	  (make sequence
	    (make formatting-instruction data: "[")
	    (make formatting-instruction data: sortas)
	    (make formatting-instruction data: "]"))
	  (empty-sosofo))
      (make formatting-instruction data: " ")
      (make formatting-instruction data: string)
      (htmlnewline))))

(define (htmlindexzone zone)
  (let loop ((idlist (split zone)))
    (if (null? idlist)
	(empty-sosofo)
	(make sequence
	  (htmlindexzone1 (car idlist))
	  (loop (cdr idlist))))))

(define (htmlindexzone1 id)
  (let* ((target (ancestor-member (element-with-id id)
				  (append (book-element-list)
					  (division-element-list)
					  (component-element-list)
					  (section-element-list))))
	 (title  (string-replace (element-title-string target) "
" " ")))
    (make sequence
      (make formatting-instruction data: "ZONE ")
      (make formatting-instruction data: (href-to target))
      (htmlnewline)

      (make formatting-instruction data: "TITLE ")
      (make formatting-instruction data: title)
      (htmlnewline))))

(mode htmlindex
  ;; this mode is really just a hack to get at the root element
  (root (process-children))

  (default 
    (if (node-list=? (current-node) (sgml-root-element))
	(make entity
	  system-id: (html-entity-file html-index-filename)
	  (process-node-list (select-elements 
			      (descendants (current-node))
			      (normalize "indexterm"))))
	(empty-sosofo)))

  (element indexterm
    (let* ((target (ancestor-member (current-node)
				    (append (book-element-list)
					    (division-element-list)
					    (component-element-list)
					    (section-element-list))))
	   (title  (string-replace (element-title-string target) "
" " ")))
      (make sequence
	(make formatting-instruction data: "INDEXTERM ")
	(make formatting-instruction data: (href-to target))
	(htmlnewline)

	(make formatting-instruction data: "INDEXPOINT ")
	(make formatting-instruction data: (href-to (current-node)))
	(htmlnewline)

	(make formatting-instruction data: "TITLE ")
	(make formatting-instruction data: title)
	(htmlnewline)

	(htmlindexattr "scope")
	(htmlindexattr "significance")
	(htmlindexattr "class")
	(htmlindexattr "id")
	(htmlindexattr "startref")
	
	(if (attribute-string (normalize "zone"))
	    (htmlindexzone (attribute-string (normalize "zone")))
	    (empty-sosofo))

	(process-children)

	(make formatting-instruction data: "/INDEXTERM")
	(htmlnewline))))
		    
  (element primary
    (htmlindexterm))

  (element secondary
    (htmlindexterm))

  (element tertiary
    (htmlindexterm))

  (element see
    (htmlindexterm))

  (element seealso
    (htmlindexterm))
)