File: fmt.html

package info (click to toggle)
tcllib 1.20%2Bdfsg-1
  • links: PTS
  • area: main
  • in suites: bullseye
  • size: 68,064 kB
  • sloc: tcl: 216,842; ansic: 14,250; sh: 2,846; xml: 1,766; yacc: 1,145; pascal: 881; makefile: 107; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (642 lines) | stat: -rw-r--r-- 16,721 bytes parent folder | download | duplicates (2)
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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
# -*- tcl -*-
#
# fmt.html
#
# Copyright (c) 2001-2019 Andreas Kupries <andreas_kupries@sourceforge.net>
#
# Definitions to convert a tcl based manpage definition into
# a manpage based upon HTML markup.
#
################################################################
################################################################

dt_source _common.tcl   ; # Shared code
dt_source _html.tcl     ; # HTML basic formatting
dt_source _xref.tcl     ; # xref management

global _in_example
set    _in_example 0

proc c_copyrightsymbol {} {return "[markup "&"]copy;"}

proc bgcolor {} {return ""}
proc border  {} {return 0}
proc Year    {} {clock format [clock seconds] -format %Y}

c_holdBuffers require synopsis

################################################################
## Backend for HTML markup

# --------------------------------------------------------------
# Handling of lists. Simplified, the global check of nesting and
# legality of list commands allows us to throw away most of the
# existing checks.

global liststack ; # stack of list tags to use in list_end
set    liststack {}

proc lpush {t class} {
    global  liststack 
    lappend liststack [list [tag/ $t] [litc_getandclear]]
    return [taga $t [list class $class]]
}

proc lpop {} {
    global liststack
    set t         [lindex   $liststack end]
    set liststack [lreplace $liststack end end]
    foreach {t l} $t break
    litc_set $l
    return $t
}

proc fmt_plain_text {text} {
    global _in_example
    if {$_in_example} {
	set text [string map [list \\\\\n \\\n] $text]
    }
    return $text
}

################################################################
# Formatting commands.

c_pass 1 fmt_manpage_begin {title section version} {c_cinit ; c_clrSections ; return}
c_pass 2 fmt_manpage_begin {title section version} {

    global sec_is_open      ; set sec_is_open      0
    global subsec_is_open   ; set subsec_is_open   0
    global prev_litem_close ; set prev_litem_close {}
    global para_is_open     ; set para_is_open     0
    global liststack        ; set liststack        {}
    global defaultstyle

    XrefInit
    c_cinit
    set module      [dt_module]
    set shortdesc   [c_get_module]
    set description [c_get_title]
    set copyright   [c_get_copyright]

    set pagetitle "$title - $shortdesc"
    
    set hdr ""

    if {![Get raw]} {
	append  hdr [markup {<!DOCTYPE html>}]
	append  hdr [tag html] [tag head] \n
	append  hdr [tag_ title $pagetitle] \n

	if {![Extend hdr ByParameter meta]} {
	    # Insert standard CSS definitions.
	    append hdr [tag_ style \
			    "[markup <]!--${defaultstyle}--[markup >]" \
			    type text/css] \n
	}

	append  hdr [tag/ head] \n
	append  hdr [ht_comment [c_provenance]]\n
	if {$copyright != {}} {
	    append  hdr [ht_comment $copyright]\n
	}
	append  hdr [ht_comment "$title.$section"]
	append  hdr \n\n
	append  hdr [tag body]
    }

    Extend hdr ByParameter header \
	@TITLE@ $pagetitle

    append  hdr [tag* div class doctools] \n

    set thetitle "[string trimleft $title :]($section) $version $module \"$shortdesc\""
    append  hdr [tag_ h1 $thetitle class doctools_title] \n
    append  hdr [fmt_section Name name] \n
    append  hdr "[para_open] $title - $description"
    return $hdr
}

c_pass 1 fmt_moddesc   {desc} {c_set_module $desc}
c_pass 2 fmt_moddesc   {desc} NOP

c_pass 1 fmt_titledesc {desc} {c_set_title $desc}
c_pass 2 fmt_titledesc {desc} NOP

c_pass 1 fmt_copyright {desc} {c_set_copyright $desc}
c_pass 2 fmt_copyright {desc} NOP

c_pass 1 fmt_manpage_end {} {c_creset ; return}
c_pass 2 fmt_manpage_end {} {
    c_creset
    set res ""

    set sa [c_xref_seealso]
    set kw [c_xref_keywords]
    set ca [c_xref_category]
    set ct [c_get_copyright]

    if {[llength $sa] > 0} {
	append res [fmt_section {See Also} see-also] \n
	append res [join [XrefList [lsort $sa] sa] ", "] \n
    }
    if {[llength $kw] > 0} {
	append res [fmt_section Keywords keywords] \n
	append res [join [XrefList [lsort $kw] kw] ", "] \n
    }
    if {$ca ne ""} {
	append res [fmt_section Category category] \n
	append res $ca \n
    }
    if {$ct != {}} {
	append res [fmt_section Copyright copyright] \n
	append res [join [split $ct \n] [tag br]\n] [tag br]\n
    }

   # Close last paragraph, subsection, and section.
    append res [para_close][subsec_close][sec_close]

    Extend res ByParameter footer

    append res [tag/ div]
    if {![Get raw]} {
	append res [tag/ body] [tag/ html]
    }
    return $res
}

c_pass 1 fmt_section {name id} {c_newSection $name 1 end $id}
c_pass 2 fmt_section {name id} {
    return "[sec_open $id][tag_ h2 [anchor $id $name]]\n[para_open]"
}

c_pass 1 fmt_subsection {name id} {c_newSection $name 2 end $id}
c_pass 2 fmt_subsection {name id} {
    return "[subsec_open $id][tag_ h3 [anchor $id $name]]\n[para_open]"
}

# Para breaks inside and outside of lists are identical
proc fmt_nl   {} {para_open}
proc fmt_para {} {para_open}

c_pass 2 fmt_require {pkg {version {}}} NOP
c_pass 1 fmt_require {pkg {version {}}} {
    if {$version != {}} { append pkg " " $version }
    c_hold require [tag_ li "package require [bold $pkg pkgname]"]
    return
}

c_pass 2 fmt_usage {cmd args} NOP
c_pass 1 fmt_usage {cmd args} {
    if {[llength $args]} {
	set text "$cmd [join $args " "]"
    } else {
	set text $cmd
    }
    c_hold synopsis [tag_ li $text]
    return
}

c_pass 1 fmt_call {cmd args} {
    if {[llength $args]} {
	set text "$cmd [join $args " "]"
    } else {
	set text $cmd
    }
    c_hold synopsis [tag_ li [link $text "#[c_cnext]"]]
    return
}
c_pass 2 fmt_call {cmd args} {
    if {[llength $args]} {
	set text "$cmd [join $args " "]"
    } else {
	set text $cmd
    }
    return [fmt_lst_item [anchor [c_cnext] $text]]
}

c_pass 1 fmt_description {did} NOP
c_pass 2 fmt_description {did} {
    set result ""
    set syn [c_held synopsis]
    set req [c_held require]

    # Create the TOC.

    # Pass 1: We have a number of special sections which were not
    #         listed explicitly in the document sources. Add them
    #         now. Note the inverse order for the sections added
    #         at the beginning.

    c_newSection Description 1 0 $did
    if {$syn != {} || $req != {}} {c_newSection Synopsis 1 0 synopsis}
    c_newSection {Table Of Contents} 1 0 toc

    if {[llength [c_xref_seealso]]  > 0} {c_newSection {See Also} 1 end see-also}
    if {[llength [c_xref_keywords]] > 0} {c_newSection Keywords   1 end keywords}
    if {[c_xref_category]         ne ""} {c_newSection Category   1 end category}
    if {[c_get_copyright]         != {}} {c_newSection Copyright  1 end copyright}

    set sections [c_sections]

    # Pass 2: Generate the markup for the TOC, indenting the
    #         links according to the level of each section.

    append result [fmt_section {Table Of Contents} toc] [para_close] \n
    append result [taga ul {class doctools_toc}] \n

    set lastlevel 1
    set close 0
    foreach {name id level} $sections {
	# level in {1,2}, 1 = section, 2 = subsection
	if {$level == $lastlevel} {
	    # Close previous item.
	    if {$close} { append result [tag/ li] \n }
	} elseif {$level > $lastlevel} {
	    # Start list of subsections
	    append result \n [tag ul] \n
	} else { # level < lastlevel
	    # End list of subsections, and of previous item (two
	    # actually, the subsection, and the section item).
	    append result [tag/ li] \n [tag/ ul] \n [tag/ li] \n
	}
	# Start entry
	if {$level == 1} {
	    append result [taga li {class doctools_section}]
	} else {
	    append result [taga li {class doctools_subsection}]
	}
	append result [link $name "#$id"]
	set close 1

	set lastlevel $level
    }
    if {$lastlevel > 1 } { append result [tag/ ul] \n }
    if {$close}          { append result [tag/ li] \n }

    append result [tag/ ul] \n

    # Implicit sections coming after the TOC (Synopsis, then the
    # description which starts the actual document). The other
    # implicit sections are added at the end of the document and
    # are generated by 'fmt_manpage_end' in the second pass.

    if {$syn != {} || $req != {}} {
	append result [fmt_section Synopsis synopsis] [para_close] [taga div {class doctools_synopsis}] \n
	if {$req != {}} {
	    append result [tag_ ul \n$req\n class doctools_requirements] \n
	}
	if {$syn != {}} {
	    append result [tag_ ul \n$syn\n class doctools_syntax] \n
	}
	append result [tag/ div] \n
    }
    append result [fmt_section Description $did] \n
    return $result
}

################################################################

proc fmt_list_begin  {what {hint {}}} {
    # NOTE: The hint is ignored. Use stylesheet definitions to modify
    # item and general list spacing.
    switch -exact -- $what {
	enumerated  {set tag ol}
	itemized    {set tag ul}
	arguments -
	commands  -
	options   -
	tkoptions -
	definitions {set tag dl}
    }
    return [para_close][lpush $tag doctools_$what]
}

proc fmt_list_end {}        {
    set res [para_close][litc_getandclear]\n[lpop][para_open]
    return $res
}
proc fmt_lst_item {text}    {
    set res [para_close][litc_getandclear]\n[tag_ dt $text]\n[tag dd][para_open]
    litc_set [tag/ dd]
    return $res
}
proc fmt_bullet {} {
    set res [para_close][litc_getandclear]\n[tag li][para_open]
    litc_set [tag/ li]
    return $res
}
proc fmt_enum {} {
    set res [para_close][litc_getandclear]\n[tag li][para_open]
    litc_set [tag/ li]
    return $res
}

proc fmt_cmd_def {command} {
    fmt_lst_item [fmt_cmd $command]
}
proc fmt_arg_def {type name {mode {}}} {
    set    text ""
    append text $type " " [fmt_arg $name]
    if {$mode != {}} {
	append text " (" $mode ")"
    }
    fmt_lst_item $text
}
proc fmt_opt_def {name {arg {}}} {
    set text [fmt_option $name]
    if {$arg != {}} {append text " " $arg}
    fmt_lst_item $text
}
proc fmt_tkoption_def {name dbname dbclass} {
    set    text ""
    append text "Command-Line Switch:\t[fmt_option $name][tag br]\n"
    append text "Database Name:\t[bold $dbname optdbname][tag br]\n"
    append text "Database Class:\t[bold $dbclass optdbclass][tag br]\n"
    fmt_lst_item $text
}

################################################################

proc fmt_example_begin {} {
    global _in_example ; set _in_example 1
    return [para_close]\n[tag* pre class doctools_example]
}
proc fmt_example_end   {} {
    global _in_example ; set _in_example 0
    return [tag/ pre]\n[para_open]
}
proc fmt_example {code} {
    return "[fmt_example_begin][fmt_plain_text $code][fmt_example_end]"
}

################################################################

proc fmt_arg  {text} { italic $text                arg }
proc fmt_cmd  {text} { bold   [XrefMatch $text sa] cmd }
proc fmt_emph {text} { em     $text }
proc fmt_opt  {text} { span   "?$text?" opt }

proc fmt_comment {text} {ht_comment $text}
proc fmt_sectref {title {id {}}} {
    if {$id == {}} { set id [c_sectionId $title] }

    if {[c_sectionKnown $id]} {
    	return [span [link $title "#$id"] sectref]
    } else {
	return [bold $title sectref]
    }
}

proc fmt_syscmd  {text} {bold [XrefMatch $text sa] syscmd}
proc fmt_method  {text} {bold $text method}
proc fmt_option  {text} {bold $text option}
proc fmt_widget  {text} {bold $text widget}
proc fmt_fun     {text} {bold $text function}
proc fmt_type    {text} {bold $text type}
proc fmt_package {text} {bold [XrefMatch $text sa kw] package}
proc fmt_class   {text} {bold $text class}
proc fmt_var     {text} {bold $text variable}
proc fmt_file    {text} {return "\"[bold $text file]\""}
proc fmt_namespace     {text} {bold $text namespace}
proc fmt_uri     {text {label {}}} {
    if {$label == {}} {set label $text}
    return [link $label $text]
}

proc fmt_image {text {label {}}} {
    # text = symbolic name of the image.

    set img [dt_imgdst $text {png gif jpg}]

    if {$label eq {}} {
	set label $text
    }

    if {$img ne {}} {
	return [imagelink $label [LinkTo $img [LinkHere]]]
    }

    if {[regexp -- {^http://} $text] ||
	[regexp -- {^ftp://}  $text]} {
	return [imagelink $label $text]
    }

    #puts_stderr here:\t[LinkHere]
    #puts_stderr dest:\t$img
    #puts_stderr rela:\t[LinkTo $img [LinkHere]]
    #puts_stderr

    return [strong "Image: $label"]
}

proc fmt_term    {text} {italic [XrefMatch $text kw sa] term}
proc fmt_const   {text} {bold $text const}

proc fmt_mdash {} { return "[markup &]mdash;" }
proc fmt_ndash {} { return "[markup &]ndash;" }

################################################################

global sec_is_open
set    sec_is_open 0

proc sec_open  {id} {
    global sec_is_open
    set res [para_close][subsec_close][sec_close][tag* div id $id class doctools_section]
    set sec_is_open 1
    return $res
}

proc sec_close {}   {
    global sec_is_open
    if {!$sec_is_open} {return ""}
    set sec_is_open 0
    return [tag/ div]\n
}

################################################################

global subsec_is_open
set    subsec_is_open 0

proc subsec_open  {id} {
    global subsec_is_open
    set res [para_close][subsec_close][tag* div id $id class doctools_subsection]
    set subsec_is_open 1
    return $res
}

proc subsec_close {}   {
    global subsec_is_open
    if {!$subsec_is_open} {return ""}
    set subsec_is_open 0
    return [tag/ div]\n
}

################################################################

# Piece of html to close the previous list element, if any.
# Saved on the list stack

global prev_litem_close
set    prev_litem_close   {}

proc litc_getandclear {} {
    global prev_litem_close
    set res $prev_litem_close
    set prev_litem_close {}
    return $res
}

proc litc_set {value} {
    global prev_litem_close
    set prev_litem_close $value
    return
}

################################################################

global para_is_open
set    para_is_open 0

proc para_open {} {
    global para_is_open
    set res [para_close][tag p]
    set para_is_open 1
    return $res
}

proc para_close {} {
    global para_is_open
    if {!$para_is_open} {return ""}
    set para_is_open 0
    return [tag/ p]
}

################################################################

proc GetXref {} { Get xref } ;# xref access to engine parameters

global    __var
array set __var {
    meta   {}
    header {}
    footer {}
    xref   {}
    raw    0
}
proc Get               {varname}      {global __var ; return $__var($varname)}
proc fmt_listvariables {}             {global __var ; return [array names __var]}
proc fmt_varset        {varname text} {
    global __var
    if {![info exists __var($varname)]} {return -code error "Unknown engine variable \"$varname\""}
    set __var($varname) $text
    return
}

# Engine parameter handling
proc Extend {v _ by args} {
    set html [Get $by]
    if {$html == {}} { return 0 }
    upvar 1 $v text
    if {[llength $args]} {
	set html [string map $args $html]
    }
    append text [markup $html] \n
    return 1
}

global defaultstyle
set    defaultstyle {
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
}

################################################################