File: html-common.dsl

package info (click to toggle)
php-doc 20061001-1
  • links: PTS
  • area: non-free
  • in suites: etch, etch-m68k
  • size: 45,764 kB
  • ctags: 1,611
  • sloc: xml: 502,485; php: 7,645; cpp: 500; makefile: 297; perl: 161; sh: 141; awk: 28
file content (439 lines) | stat: -rw-r--r-- 13,887 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
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
;; -*- Scheme -*-
;;
;; $Id: html-common.dsl,v 1.27 2006/01/16 23:14:18 hholzgra Exp $
;;

;; Returns the depth of the auto-generated TOC (table of
;; contents) that should be made at the nd-level
(define (toc-depth nd)
  (if (string=? (gi nd) "book")
      2 ; the depth of the top-level TOC
      1 ; the depth of all other TOCs
      ))

;; re-defining element-id as we need to get the id of the parent
;; element not only for title but also for question in the faq
(define (element-id #!optional (nd (current-node)))
  (let ((elem (if (equal? (gi nd) (normalize "title")) (parent nd)  
                   (if (equal? (gi nd) (normalize "question")) (parent nd) 
                       nd))))
    (if (attribute-string (normalize "id") elem)
        (attribute-string (normalize "id") elem)
        (generate-anchor elem))))


;; convert to lower case unless all characters are upper case
(define (case-fold-updown str)
  (let (
        (upstr (case-fold-up   str))
        (downstr (case-fold-down str))
        )
    (if (equal? upstr str) upstr downstr )
    )
)

;; Make function definitions bold
(element (funcdef function) 
  ($bold-seq$
   (make sequence
     (process-children)
     )
   )
  )


;; There are two different kinds of optionals
;; optional parameters and optional parameter parts.
;; An optional parameter is identified by an optional tag
;; with a parameter tag as its parent 
;; and only whitespace between them
(element optional 
  ;;check for true optional parameter
  (if (is-true-optional (current-node))
      ;; yes - handle '[...]' in paramdef
      (process-children-trim) 
      ;; no - do '[...]' output
      (make sequence
        (literal %arg-choice-opt-open-str%)
        (process-children-trim)
        (literal %arg-choice-opt-close-str%)
        )
      )
  )                

;; Print out parameters in italic
(element (paramdef parameter)
  (make sequence
    font-posture: 'italic                                                       
    (process-children-trim)
    )
  )                                                       

;; Now this is going to be tricky
(element paramdef  
  (make sequence
    ;; special treatment for first parameter in funcsynopsis
    (if (equal? (child-number (current-node)) 1)
        ;; is first ?
        (make sequence
          ;; start parameter list
          (literal " (") 
          ;; is optional ?
          ( if (has-true-optional (current-node))
               (literal %arg-choice-opt-open-str%)
               (empty-sosofo)
               )
          )
        ;; not first
        (empty-sosofo)
        )
    
    ;;
    (process-children-trim)
    
    ;; special treatment for last parameter 
    (if (equal? (gi (ifollow (current-node))) (normalize "paramdef"))                                        
        ;; more parameters will follow
        (make sequence
          ;; next is optional ?
          ( if (has-true-optional (ifollow (current-node)))
               ;; optional
               (make sequence
                 (literal " ")
                 (literal %arg-choice-opt-open-str%)
                 )
               ;; not optional
               (empty-sosofo)
               )
          (literal ", " ) 
          )
        ;; last parameter
        (make sequence
          (literal 
           (let loop ((result "")(count (count-true-optionals (parent (current-node)))))
             (if (<= count 0)
                 result
                 (loop (string-append result %arg-choice-opt-close-str%)(- count 1))
                 )
             )
           )
          ( literal ")" )
          )
        )
    )
  )


;; Linking types to the correct place
(element type
  (let* 
    ((orig-name (data (current-node)))
      (type-name (cond 
        ((equal-ci? orig-name "bool")   "boolean")
        ((equal-ci? orig-name "double") "float")
        ((equal-ci? orig-name "int")   "integer")
        ((equal-ci? orig-name "NULL")   "null")
        (else orig-name))
      )
      (linkend (string-append "language.types." type-name))
      (target (element-with-id linkend))
    )
    (cond ((node-list-empty? target)
      (make sequence (process-children) )
      )
      (else 
        (make element gi: "A"
          attributes: (list (list "HREF" (href-to target)))
          ( $bold-seq$(make sequence (process-children) ) )
        )
      )
    )
  )
)


(define (my-href-to target)
  (cond ((node-list-empty? target) (normalize ""))
        (else (href-to target)))
  )

(element function
  (let* (
		 (function-name (data (current-node)))
		 (chapter-id (attribute-string (normalize "id") (ancestor-member (parent) (list "chapter"))))
		 (role-name (if (attribute-string (normalize "role"))
						(attribute-string (normalize "role"))
                        (cond ((or (equal? chapter-id "zend") 
                                   (equal? chapter-id "tsrm")) 
                               ( cond ((equal? (case-fold-up function-name) function-name) (normalize "zend-macro"))
                                      (else (normalize "zend-api"))
									  ))
                              (else (normalize "php")))
						))
		 (id-base (case-fold-down (string-replace (string-replace function-name "_" "-") "::" ".")))
		 (target (cond 
				  ((equal-ci? role-name "php")        
				   (my-href-to (element-with-id (string-append "function."   id-base ))))
				  ((equal-ci? role-name "zend-api")   
				   (my-href-to (element-with-id (string-append "zend-api."   id-base ))))
				  ((equal-ci? role-name "zend-macro") 
				   (my-href-to (element-with-id (string-append "zend-macro." id-base ))))
				  ((equal-ci? role-name "libc")       
				   (string-append %manpage-url-base% function-name %manpage-url-ext%))
				  (else "")
				  )
				 )
		 (parent-gi (gi (parent)))
		 )
	
    (cond
     ;; function names should be plain in FUNCDEF
     ((equal? parent-gi "funcdef")
      (process-children))
     
     ;; If a valid ID for the target function is not found, or if the
     ;; FUNCTION tag is within the definition of the same function,
     ;; make it bold, add (), but don't make a link
     ((or (equal? target "") 
      (equal? (case-fold-updown
           (data (node-list-first
              (select-elements
               (node-list-first
                (children
                 (select-elements
                  (children
                   (ancestor-member (parent) (list "refentry")))
                  "refnamediv")))
               "refname"))))
          (case-fold-updown function-name)))
      ($bold-seq$
       (make sequence 
     (process-children)
     (literal "()"))))
     
     ;; Else make a link to the function and add ()
     (else
      (make element gi: "A"
            attributes: (list
                         (list "HREF" target))
            ($bold-seq$
             (make sequence
                   (process-children)
                   (literal
                    )
                   (literal "()")))))
     )))


;; Link for classnames
(element classname
  (let* ((class-name (data (current-node)))
     (linkend 
      (string-append
       "class." 
        (string-replace
         (case-fold-down class-name) "_" "-")))
     (target (element-with-id linkend))
     (parent-gi (gi (parent))))
    (cond
     ;; Function names should be plain in SYNOPSIS
     ((equal? parent-gi "synopsis")
      (process-children))
     
     ;; If a valid ID for the target class is not found, or if the
     ;; CLASSNAME tag is within the definition of the same class,
     ;; make it bold, but don't make a link
     ((or (node-list-empty? target)
      (equal? (case-fold-down
           (data (node-list-first
              (select-elements
               (node-list-first
                (children
                 (select-elements
                  (children
                   (ancestor-member (parent) (list "refentry")))
                  "refnamediv")))
               "refname"))))
          class-name))
      ($bold-seq$
       (process-children)))
     
     ;; Else make a link to the class
     (else
      (make element gi: "A"
        attributes: (list
             (list "HREF" (href-to target)))
        ($bold-seq$
         (process-children)))))))


;; Linking to constants
(element constant
  (let* ((constant-name (data (current-node)))
     (linkend 
      (string-append "constant." 
             (case-fold-down
              (string-replace constant-name "_" "-"))))
     (target (element-with-id linkend))
     (parent-gi (gi (parent))))

    (cond
     ;; If a valid ID for the target constant is not found
     ;; make it bold, but don't make a link
     ((or (node-list-empty? target)(attribute-string (normalize "id")(current-node)))
            ($bold-mono-seq$
       (process-children)))
     
     ;; Else make a link to the constant
     (else
      (make element gi: "A"
        attributes: (list
             (list "HREF" (href-to target)))
        ($bold-mono-seq$
         (process-children)))))))


;; Dispaly of examples
(element example
  (make sequence
    (make element gi: "TABLE"
      attributes: (list
               (list "WIDTH" "100%")
               (list "BORDER" "0")
               (list "CELLPADDING" "0")
               (list "CELLSPACING" "0")
               (list "CLASS" "EXAMPLE"))
      (make element gi: "TR"
        (make element gi: "TD"
              ($formal-object$))))))


;; Prosessing tasks for the frontpage
(mode book-titlepage-recto-mode
  (element authorgroup
    (process-children))
    
  (element author
    (let ((author-name  (author-string))
          (author-affil (select-elements (children (current-node)) 
                                         (normalize "affiliation"))))
      (make sequence      
        (make element gi: "DIV"
              attributes: (list (list "CLASS" (gi)))
              (literal author-name))
        (process-node-list author-affil))))

  (element editor
    (let ((editor-name (author-string)))
      (make sequence
        (if (first-sibling?)
            (make element gi: "H2"
                  attributes: (list (list "CLASS" "EDITEDBY"))
                  (literal (gentext-edited-by)))
            (empty-sosofo))
        (make element gi: "DIV"
              attributes: (list (list "CLASS" (gi)))
              (literal editor-name)))))
)


;; Put version info where the refname part in the refnamediv is, except
;; on pcre reference pages (these are masked as function pages, but are
;; not function pages themselfs)
(element (refnamediv refname)
  (let ((refid (attribute-string (normalize "id") (parent (parent (current-node)))))
        (partid (attribute-string (normalize "id") (parent (parent (parent (parent (current-node))))))))
    (if (and (or (not (string? refid))
                 (not (string=? (substring refid 0 (min (string-length refid) 14)) "reference.pcre"))
                 )
             (or (string=? partid "funcref") (string=? partid "pecl-funcref"))
             )
      (make sequence
        (make element gi: "P"
          (literal "    (")
          (version-info (current-node))
          (literal ")")
        )
        (process-children)
      )
      (process-children)
    )
  )
)

;; Display of question tags, link targets
(element question
  (let* ((chlist   (children (current-node)))
         (firstch  (node-list-first chlist))
         (restch   (node-list-rest chlist)))
    (make element gi: "B"
    (make element gi: "DIV"
          attributes: (list (list "CLASS" (gi)))
          (make element gi: "P"
                (make element gi: "A"
                      attributes: (list (list "NAME" (element-id)))
                      (empty-sosofo))
                (make element gi: "B"
                      (literal (question-answer-label (current-node)) " "))
                (process-node-list (children firstch)))
          (process-node-list restch))))   )          

;; Adding class HTML parameter to examples
;; having a role parameter, to make PHP examples
;; distinguisable from other ones in the manual
(define ($verbatim-display$ indent line-numbers?)
  (let (
(content (make element gi: "PRE"
       attributes: (list
    (list "CLASS" (if (attribute-string (normalize "role"))
      (attribute-string (normalize "role"))
      (gi))))
       (if (or indent line-numbers?)
   ($verbatim-line-by-line$ indent line-numbers?)
   (process-children-trim)))))
    (if %shade-verbatim%
(make element gi: "TABLE"
      attributes: (list 
                   (list "BORDER" "0")
                   (list "BGCOLOR" "#E0E0E0")
                   (list "CELLPADDING" "5")
                   )
      (make element gi: "TR"
    (make element gi: "TD"
  content)))
(make sequence
  (para-check)
  content
  (para-check 'restart)))))

;; Special handling of note role="seealso"
(define ($admonpara$)
  (let* ((title     (select-elements 
             (children (parent (current-node))) (normalize "title")))
     (has-title (not (node-list-empty? title)))
     (adm-title (if has-title 
            (make sequence
              (with-mode title-sosofo-mode
                (process-node-list (node-list-first title)))
              (literal (gentext-label-title-sep 
                    (gi (parent (current-node))))))
            (literal
             (gentext-element-name 
              (if (equal? (normalize "seealso") (attribute-string (normalize "role") (parent (current-node))))
               (normalize "seealsoie")
               (parent (current-node))))
             (gentext-label-title-sep 
              (gi (parent (current-node))))))))
    (make element gi: "P"
      (if (and (not %admon-graphics%) (= (child-number) 1))
          (make element gi: "B"
            adm-title)
          (empty-sosofo))
      (process-children))))



(define (linebreak) (make element gi: "BR" (empty-sosofo)))


;; vim: ts=2 sw=2 et