blob: acb7188cedc5e0fc251415067cd2a31b908fd4dc (
plain)
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
|
# -*- tcl -*-
# Copyright (c) 2009 Andreas Kupries <andreas_kupries@sourceforge.net>
# Support package. Basic html generation commands.
# # ## ### ##### ######## ############# #####################
## Requirements
package require Tcl 8.4 ; # Required Core
package require doctools::text ; # Basic generator state management.
namespace eval ::doctools::html {}
doctools::text::import ::doctools::html
# # ## ### ##### ######## ############# #####################
proc ::doctools::html::begin {} {
text::begin
Begin
return
}
proc ::doctools::html::save {} {
variable state
set current [array get state]
text::save
Begin
set state(stack) $current
return
}
proc ::doctools::html::restore {} {
variable state
set html [text::restore]
array set state $state(stack)
return $html
}
proc ::doctools::html::collect {script} {
save
uplevel 1 $script
return [restore]
}
# # ## ### ##### ######## ############# #####################
proc ::doctools::html::tag1 {name args} {
text::+ <$name
if {[llength $args]} {
foreach {a v} $args { text::+ " $a=\"$v\"" }
}
text::+ >
return
}
proc ::doctools::html::tag {name args} {
tagD $name $args
return
}
proc ::doctools::html::tagD {name dict} {
variable state
lappend state(tstack) $name
text::+ <$name
if {[llength $dict]} {
foreach {a v} $dict { text::+ " $a=\"$v\"" }
}
text::+ >
return
}
proc ::doctools::html::/tag {} {
variable state
set tag [lindex $state(tstack) end]
set state(tstack) [lreplace $state(tstack) end end]
text::+ </$tag>
return
}
proc ::doctools::html::tag/ {name args} {
variable state
lappend state(tstack) $tag
text::+ <$tag
if {[llength $args]} {
foreach {a v} $args { text::+ " $a=\"$v\"" }
text::+ { }
}
text::+ />
return
}
proc ::doctools::html::tag* {name args} {
set script [lindex $args end]
set args [lreplace $args end end]
tagD $name $args
uplevel 1 $script
/tag
return
}
proc ::doctools::html::tag= {name args} {
set text [lindex $args end]
set args [lreplace $args end end]
eval [linsert $args 0 tag $name]
+ $text
/tag
return
}
# # ## ### ##### ######## ############# #####################
proc ::doctools::html::+ {text} {
text::+ [Quote $text]
return
}
proc ::doctools::html::comment {comment} {
text::+ "<!-- ${comment} -->"
return
}
proc ::doctools::html::++ {html} {
text::+ $html
return
}
# # ## ### ##### ######## ############# #####################
proc ::doctools::html::import {{namespace {}}} {
uplevel 1 [list namespace eval ${namespace}::html {
namespace import ::doctools::html::*
}]
return
}
proc ::doctools::html::importhere {{namespace ::}} {
uplevel 1 [list namespace eval ${namespace} {
namespace import ::doctools::html::*
}]
return
}
# # ## ### ##### ######## ############# #####################
proc ::doctools::html::Begin {} {
variable state
array unset state *
array set state {
tags {}
stack {}
}
return
}
proc ::doctools::html::Quote {text} {
variable textMap
return [string map $textMap $text]
}
# # ## ### ##### ######## ############# #####################
namespace eval ::doctools::html {
variable state
array set state {}
# Replaces HTML markup characters in $text with the appropriate
# entity references.
variable textMap {
& & < < > >
\xa0 \xb0 ° \xc0 À \xd0 Ð \xe0 à \xf0 ð
\xa1 ¡ \xb1 ± \xc1 Á \xd1 Ñ \xe1 á \xf1 ñ
\xa2 ¢ \xb2 ² \xc2 Â \xd2 Ò \xe2 â \xf2 ò
\xa3 £ \xb3 ³ \xc3 Ã \xd3 Ó \xe3 ã \xf3 ó
\xa4 ¤ \xb4 ´ \xc4 Ä \xd4 Ô \xe4 ä \xf4 ô
\xa5 ¥ \xb5 µ \xc5 Å \xd5 Õ \xe5 å \xf5 õ
\xa6 ¦ \xb6 ¶ \xc6 Æ \xd6 Ö \xe6 æ \xf6 ö
\xa7 § \xb7 · \xc7 Ç \xd7 × \xe7 ç \xf7 ÷
\xa8 ¨ \xb8 ¸ \xc8 È \xd8 Ø \xe8 è \xf8 ø
\xa9 © \xb9 ¹ \xc9 É \xd9 Ù \xe9 é \xf9 ù
\xaa ª \xba º \xca Ê \xda Ú \xea ê \xfa ú
\xab « \xbb » \xcb Ë \xdb Û \xeb ë \xfb û
\xac ¬ \xbc ¼ \xcc Ì \xdc Ü \xec ì \xfc ü
\xad ­ \xbd ½ \xcd Í \xdd Ý \xed í \xfd ý
\xae ® \xbe ¾ \xce Î \xde Þ \xee î \xfe þ
\xaf &hibar; \xbf ¿ \xcf Ï \xdf ß \xef ï \xff ÿ
{"} "
} ; # " make the emacs highlighting code happy.
# Text commands which are html commands, unchanged
namespace import \
::doctools::text::done \
::doctools::text::+++ \
::doctools::text::newline \
::doctools::text::prefix \
::doctools::text::indent \
::doctools::text::dedent \
::doctools::text::indented \
::doctools::text::indenting \
::doctools::text::newlines
namespace export begin done save restore collect + +++ \
prefix indent dedent indented indenting newline newlines \
tag /tag tag/ tag* tag1 tag= comment ++
}
# # ## ### ##### ######## ############# #####################
package provide doctools::html 0.1
return
|