File: dblink.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 (397 lines) | stat: -rw-r--r-- 12,596 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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
;; $Id: dblink.dsl,v 1.19 1999/11/18 12:21:28 nwalsh Exp $
;;
;; This file is part of the Modular DocBook Stylesheet distribution.
;; See ../README or http://www.berkshire.net/~norm/dsssl/
;;

;; ========================= LINKS AND ANCHORS ==========================

(element link
  ;; No warnings about missing targets.  Jade will do that for us, and
  ;; this way we can use -wno-idref if we really don't care.
  (let* ((endterm   (attribute-string (normalize "endterm")))
	 (linkend   (attribute-string (normalize "linkend")))
	 (target    (element-with-id linkend))
	 (etarget   (if endterm 
			(element-with-id endterm)
			(empty-node-list)))
	 (link-cont (if endterm
			(if (node-list-empty? etarget)
			    (literal 
			     (string-append "LINK CONTENT ENDTERM '"
					    endterm
					    "' MISSING"))
			    (with-mode xref-endterm-mode
			      (process-node-list etarget)))
			(process-children))))
    (if (node-list-empty? target)
	link-cont
	(make link 
	  destination: (node-list-address target)
	  link-cont))))

(element ulink 
  (make sequence
    ($charseq$)
    (if %footnote-ulinks%
	($ss-seq$ + (literal (footnote-number (current-node))))
	(if (and %show-ulinks% 
		 (not (equal? (attribute-string (normalize "url"))
			      (data-of (current-node)))))
	    (make sequence
	      (literal " (")
	      (literal (attribute-string (normalize "url")))
	      (literal ")"))
	    (empty-sosofo)))))

(element footnoteref 
  (process-element-with-id (attribute-string (normalize "linkend"))))

(element anchor (empty-sosofo))
(element beginpage (empty-sosofo))

;; ======================================================================

(define (olink-link)
  ;; This is an olink without a TARGETDOCENT, treat it as a link within
  ;; the same document.
  (let* ((localinfo (attribute-string (normalize "localinfo")))
	 (target    (element-with-id localinfo))
	 (linkmode  (attribute-string (normalize "linkmode")))
	 (modespec  (if linkmode (element-with-id linkmode) (empty-node-list)))
	 (xreflabel (if (node-list-empty? modespec)
			#f
			(attribute-string (normalize "xreflabel") modespec)))
	 (linktext  (strip (data-of (current-node)))))
    (if (node-list-empty? target)
	(make sequence
	  (error (string-append "OLink to missing ID '" localinfo "'"))
	  (if (and (equal? linktext "") xreflabel)
	      (literal xreflabel)
	      (process-children)))
	(if (equal? linktext "")
	    (if xreflabel
		(xref-general target xreflabel)
		(xref-general target))
	    (process-children)))))

(define (olink-simple)
  ;; Assumptions: 
  ;; - The TARGETDOCENT is identified by a public ID
  ;; - If the element has no content, the title extracted by
  ;;   (olink-resource-title) should be used
  ;; - The (olink-resource-title) function can deduce the title from
  ;;   the pubid and the sysid
  (let* ((target   (attribute-string (normalize "targetdocent")))
	 (pubid    (entity-public-id target))
	 (sysid    (system-id-filename target))
	 (title    (olink-resource-title pubid sysid))
	 (linktext (strip (data-of (current-node)))))
    (if (equal? linktext "")
	(make sequence
	  font-posture: 'italic
	  (literal title))
	(process-children))))

(define (olink-outline-xref olroot target linktext)
  (let* ((name  (attribute-string (normalize "name") target))
	 (label (attribute-string (normalize "label") target))
	 (title (select-elements (children target) (normalize "ttl")))
	 (substitute (list
		      (list "%g" (if name (literal name) (literal "")))
		      (list "%n" (if label (literal label) (literal "")))
		      (list "%t" (with-mode olink-title-mode
				   (process-node-list title)))))
	 (tlist   (match-split-list linktext (assoc-objs substitute))))
    (string-list-sosofo tlist substitute)))

(define (olink-outline)
  (let* ((target    (attribute-string (normalize "targetdocent")))
	 (linkmode  (attribute-string (normalize "linkmode")))
	 (localinfo (attribute-string (normalize "localinfo")))
	 (modespec  (if linkmode (element-with-id linkmode) (empty-node-list)))
	 (xreflabel (if (node-list-empty? modespec) 
			""
			(attribute-string (normalize "xreflabel") modespec)))
	 (pubid     (entity-public-id target))
	 (sysid     (system-id-filename target))
	 (basename  (trim-string sysid '(".sgm" ".xml" ".sgml")))
	 (olinkfile (string-append basename %olink-outline-ext%))
	 (olinkdoc  (sgml-parse olinkfile))
	 (olinkroot (node-property 'document-element olinkdoc))
	 (olnode    (if localinfo
			(element-with-id localinfo olinkroot)
			olinkroot))
	 (linktext (strip (data-of (current-node)))))
    (if (equal? linktext "")
	(olink-outline-xref olinkroot olnode xreflabel)
	(process-children))))

(element olink
  (if (not (attribute-string (normalize "targetdocent")))
      (olink-link)
      (if (attribute-string (normalize "linkmode"))
	  (olink-outline)
	  (olink-simple))))

(mode olink-title-mode
  (default (process-children))

  (element ttl
    (make sequence
      font-posture: 'italic
      (process-children)))

  (element it
    (make sequence
      font-posture: 'upright
      (process-children)))

  (element tt
    (make sequence
      font-family-name: %mono-font-family%
      (process-children)))

  (element sub 
    ($ss-seq$ -))

  (element sup 
    ($ss-seq$ +))
)

;; ======================================================================

(element xref
  (let* ((endterm (attribute-string (normalize "endterm")))
	 (linkend (attribute-string (normalize "linkend")))
	 (target  (element-with-id linkend))
	 (xreflabel (if (node-list-empty? target)
			#f
			(attribute-string (normalize "xreflabel") target))))
    (if (node-list-empty? target)
	(error (string-append "XRef LinkEnd to missing ID '" linkend "'"))
	(if xreflabel
	    (make link 
	      destination: (node-list-address target)
	      (literal xreflabel))
	    (if endterm
		(if (node-list-empty? (element-with-id endterm))
		    (error (string-append "XRef EndTerm to missing ID '" 
					  endterm "'"))
		    (make link 
		      destination: (node-list-address (element-with-id endterm))
		      (with-mode xref-endterm-mode 
			(process-element-with-id endterm))))
		(cond
		 ((or (equal? (gi target) (normalize "biblioentry"))
		      (equal? (gi target) (normalize "bibliomixed")))
		  ;; xref to the bibliography is a special case
		  (xref-biblioentry target))
		 ((equal? (gi target) (normalize "co"))
		  ;; callouts are a special case
		  (xref-callout target))
		 ((equal? (gi target) (normalize "listitem"))
		  (xref-listitem target))
		 ((equal? (gi target) (normalize "question"))
		  (xref-question target))
		 ((equal? (gi target) (normalize "answer"))
		  (xref-answer target))
		 ((equal? (gi target) (normalize "refentry"))
		  (xref-refentry target))
		 ((equal? (gi target) (normalize "glossentry"))
		  ;; as are glossentrys
		  (xref-glossentry target))
		 ((equal? (gi target) (normalize "author"))
		  ;; and authors
		  (xref-author target))
		 ((equal? (gi target) (normalize "authorgroup"))
		  ;; and authorgroups
		  (xref-authorgroup target))
		 (else 
		  (xref-general target))))))))

(define (xref-general target #!optional (xref-string #f))
  ;; This function is used by both XREF and OLINK (when no TARGETDOCENT
  ;; is specified).  The only case where xref-string is supplied is
  ;; on OLINK.
  (let ((label (attribute-string (normalize "xreflabel") target)))
    (make link 
      destination: (node-list-address target)
      (if xref-string
	  (auto-xref target xref-string)
	  (if label
	      (xreflabel-sosofo label)
	      (auto-xref target))))))

(define (xref-refentry target)
;; refmeta/refentrytitle, refmeta/manvolnum, refnamediv/refdescriptor, 
;; refnamediv/refname
  (let* ((refmeta    (select-elements (children target)
				      (normalize "refmeta")))
	 (refnamediv (select-elements (children target)
				      (normalize "refnamediv")))
	 (rfetitle   (select-elements (children refmeta) 
				      (normalize "refentrytitle")))
	 (manvolnum  (select-elements (children refmeta)
				      (normalize "manvolnum")))
	 (refdescrip (select-elements (children refnamediv)
				      (normalize "refdescriptor")))
	 (refname    (select-elements (children refnamediv)
				      (normalize "refname")))

	 (title      (if (node-list-empty? rfetitle)
			 (if (node-list-empty? refdescrip)
			     (node-list-first refname)
			     (node-list-first refdescrip))
			 (node-list-first rfetitle))))
  (make link 
    destination: (node-list-address target)

    (make sequence
      font-posture: (if %refentry-xref-italic% 
			'italic
			(inherited-font-posture))

      (process-node-list (children title))
      (if (and %refentry-xref-manvolnum%
	       (not (node-list-empty? manvolnum)))
	  (process-node-list manvolnum)
	  (empty-sosofo))))))

(define (xref-glossentry target)
  (let ((glossterms (select-elements (children target)
				     (normalize "glossterm"))))
    (make link 
      destination: (node-list-address target)
      (with-mode xref-glossentry-mode
	(process-node-list (node-list-first glossterms))))))

(define (xref-author target)
  (make link 
    destination: (node-list-address target)
    (literal (author-string target))))

(define (xref-authorgroup target)
  ;; it's a quirk of author-list-string that it needs to point to
  ;; one of the authors in the authorgroup, not the authorgroup.
  ;; go figure.
  (make link 
    destination: (node-list-address target)
    (let loop ((author (select-elements (children target)
					(normalize "author"))))
      (if (node-list-empty? author)
	  (empty-sosofo)
	  (make sequence
	    (literal (author-list-string (node-list-first author)))
	    (loop (node-list-rest author)))))))

(define (xref-biblioentry target)
  (let* ((abbrev (node-list-first 
		  (node-list-filter-out-pis (children target))))
	 (label  (attribute-string (normalize "xreflabel") target)))
    (make link 
      destination: (node-list-address target)

      (if biblio-xref-title
	  (let* ((citetitles (select-elements (descendants target)
					     (normalize "citetitle")))
		 (titles     (select-elements (descendants target)
					     (normalize "title")))
		 (title      (if (node-list-empty? citetitles)
				 (node-list-first titles)
				 (node-list-first citetitles))))
	    (with-mode xref-title-mode
	      (process-node-list title)))
	  (if biblio-number
	      (make sequence
		(literal "[" (number->string (bibentry-number target)) "]"))
	      (if label
		  (make sequence
		    (literal "[" label "]"))
		  (if (equal? (gi abbrev) (normalize "abbrev"))
		      (make sequence
			(process-node-list abbrev))
		      (make sequence
			(literal "[" 
				 (attribute-string (normalize "id") target)
				 "]")))))))))

(define (xref-callout target)
  (make link 
    destination: (node-list-address target)
    ($callout-mark$ target)))

(define (xref-listitem target)
  (if (equal? (gi (parent target)) (normalize "orderedlist"))
      (make link 
	destination: (node-list-address target)
	(literal (orderedlist-listitem-label-recursive target)))
      (error 
       (string-append "XRef to LISTITEM only supported in ORDEREDLISTs"))))


(define (xref-question target)
  (make link
    destination: (node-list-address target)
    (make sequence
      (literal (gentext-element-name target))
      (literal (gentext-label-title-sep target))
      (literal (question-answer-label target)))))

(define (xref-answer target)
  (xref-question target))

(mode xref-endterm-mode
  (default
    (make sequence
      font-posture: 'italic
      (process-children-trim))))

(define (xreflabel-sosofo xreflabel)
  (make sequence
    font-posture: 'italic
    (literal xreflabel)))

;; ======================================================================

;; Returns the title of the element as a sosofo, italicized for xref.
;;
(define (element-title-xref-sosofo nd)
  (make sequence
    font-posture: 'italic
    (element-title-sosofo nd)))

(mode xref-title-mode
  (element title
    (make sequence
      font-posture: 'italic
      (process-children-trim)))

  (element citetitle
    (make sequence
      font-posture: 'italic
      (process-children-trim)))

  (element refname
    (process-children-trim))

  (element refentrytitle
    (process-children-trim))
)

(mode xref-glossentry-mode
  (element glossterm
    ($italic-seq$)))

;; ======================================================================

(define (element-page-number-sosofo target)
  (with-mode pageno-mode
	(process-node-list target)))

(mode pageno-mode
  (default
    (current-node-page-number-sosofo)))

;; ======================================================================