x-html.mkiv /size: 8009 b    last modification: 2020-07-01 14:35
1
%D \module
2
%D [ file=x-html,
3
%D version=2011.02.03, % adapted 2014.11.08
4
%D title=\CONTEXT\ Modules,
5
%D subtitle=HTML,
6
%D author=Hans Hagen,
7
%D date=\currentdate,
8
%D copyright={PRAGMA ADE \& \CONTEXT\ Development Team}]
9
%C
10
%C This module is part of the \CONTEXT\ macro||package and is
11
%C therefore copyrighted by \PRAGMA. See mreadme.pdf for
12
%C details.
13 14
\startmodule
[
html
]
15 16
%D Usage:
17
%D
18
%D \starttyping
19
%D \xmlregistersetup{xml:html:basics}
20
%D \xmlregistersetup{xml:html:tables}
21
%D \stoptyping
22 23
% \xmlsetsetup{#1}{(p|span)[@lang]}{xml:html:lang}
24
%
25
% \startxmlsetups xml:html:lang
26
% \begingroup
27
% \language[\xmlatt{#1}{lang}]
28
% \xmlsetup{#1}{xml:html:\xmltag{#1}}
29
% \endgroup
30
% \stopxmlsetups
31 32
\unprotect
33 34
\definehighlight
[
b
]
[
\c!command
=
\v!no
,
\c!style
=
\v!bold
]
35
\definehighlight
[
i
]
[
\c!command
=
\v!no
,
\c!style
=
\v!italic
]
36
\definehighlight
[
bi
]
[
\c!command
=
\v!no
,
\c!style
=
\v!bolditalic
]
37
\definehighlight
[
em
]
[
\c!command
=
\v!no
,
\c!style
=
\em
]
38
\definehighlight
[
tt
]
[
\c!command
=
\v!no
,
\c!style
=
\v!mono
]
39
\definehighlight
[
strong
][
\c!command
=
\v!no
,
\c!style
=
\v!bold
]
40
\definehighlight
[
u
]
[
\c!command
=
\v!no
,
\c!style
=
\directsetbar
{
\v!underbar
}
]
41
\definehighlight
[
code
]
[
\c!command
=
\v!no
,
\c!style
=
\v!mono
]
42
\definehighlight
[
pre
]
[
\c!command
=
\v!no
]
43 44
\protect
45 46
% todo: pre
47 48
\startxmlsetups
xml
:
html
:
basics
49
\xmlsetsetup
{
#
1
}{
p
|
br
|
b
|
i
|
u
|
em
|
tt
|
strong
|
ul
|
ol
|
li
|
table
|
thead
|
tbody
|
tfoot
|
tr
|
td
|
th
|
span
|
img
}{
xml
:
html
:
*
}
50
\xmlsetsetup
{
#
1
}{
b
/
i
}{
xml
:
html
:
bi
}
51
\xmlsetsetup
{
#
1
}{
i
/
b
}{
xml
:
html
:
bi
}
52
\xmlstripanywhere
{
#
1
}{
!
pre
}
53
\stopxmlsetups
54 55
\startxmlsetups
xml
:
html
:
tables
56
\xmlsetsetup
{
#
1
}{
table
|
thead
|
tbody
|
tfoot
|
tr
|
td
|
th
}{
xml
:
html
:
*
}
57
\stopxmlsetups
58 59
\startxmlsetups
xml
:
html
:
p
60
\xmldoifnotselfempty
{
#
1
}
{
61
\dontleavehmode
62
\ignorespaces
63
\xmlflush
{
#
1
}
64
\removeunwantedspaces
65
}
66
\par
67
\stopxmlsetups
68 69
\startxmlsetups
xml
:
html
:
br
70
\crlf
71
\stopxmlsetups
72 73
\startxmlsetups
xml
:
html
:
b
74
\directhighlight
{
b
}{
\xmlflush
{
#
1
}}
75
\stopxmlsetups
76 77
\startxmlsetups
xml
:
html
:
i
78
\directhighlight
{
i
}{
\xmlflush
{
#
1
}}
79
\stopxmlsetups
80 81
\startxmlsetups
xml
:
html
:
bi
82
\directhighlight
{
bi
}{
\xmlflush
{
#
1
}}
83
\stopxmlsetups
84 85
\startxmlsetups
xml
:
html
:
em
86
\directhighlight
{
em
}{
\xmlflush
{
#
1
}}
87
\stopxmlsetups
88 89
\startxmlsetups
xml
:
html
:
tt
90
\directhighlight
{
tt
}{
\xmlflush
{
#
1
}}
91
\stopxmlsetups
92 93
\startxmlsetups
xml
:
html
:
strong
94
\directhighlight
{
strong
}{
\xmlflush
{
#
1
}}
95
\stopxmlsetups
96 97
\startxmlsetups
xml
:
html
:
u
98
\directhighlight
{
u
}{
\xmlflush
{
#
1
}}
99
\stopxmlsetups
100 101
\startxmlsetups
xml
:
html
:
ul
102
\startitemize
[
packed
]
103
\xmlflush
{
#
1
}
104
\stopitemize
105
\stopxmlsetups
106 107
\startxmlsetups
xml
:
html
:
ol
108
\startitemize
[
packed
,
n
]
109
\xmlflush
{
#
1
}
110
\stopitemize
111
\stopxmlsetups
112 113
\startxmlsetups
xml
:
html
:
li
114
\startitem
115
\xmlflush
{
#
1
}
116
\stopitem
117
\stopxmlsetups
118 119
\startxmlsetups
xml
:
html
:
code
120
\directhighlight
{
code
}{
\xmlflushspacewise
{
#
1
}}
121
\stopxmlsetups
122 123
\startxmlsetups
xml
:
html
:
pre
124
\directhighlight
{
pre
}{
\xmlflushspacewise
{
#
1
}}
125
\stopxmlsetups
126 127
\startxmlsetups
xml
:
html
:
span
128
\xmlflush
{
#
1
}
129
\stopxmlsetups
130 131
\startxmlsetups
xml
:
html
:
img
132
\ifhmode
133
\dontleavehmode
134
\externalfigure
[
\xmlatt
{
#
1
}{
src
}
]
135
\else
136
\startlinecorrection
137
\externalfigure
[
\xmlatt
{
#
1
}{
src
}
]
138
\stoplinecorrection
139
\fi
140
\stopxmlsetups
141 142
% tables, maybe we need a generic html table module
143
%
144
% todo: align
145 146
% beware, the padding code is somewhat experimental, eventually the
147
% table will be done in cld code
148
%
149
% we can also use \xmlmap for border etc
150 151
% \registerctxluafile{lxml-css}{}
152 153
\starttexdefinition
cssgetsinglepadding
#
1
154
\ctxlua {
155
context
(
(
xml
.
css
.
padding
(
156
"
#1
"
,
157
\number
\dimexpr
0
.
1
ex
,
158
\number
\dimexpr
0
.
01
\hsize
,
159
\number
\dimexpr
1
ex
,
160
\number
\dimexpr
1
em
161
)
)
)
% returns 4 values therefore ()
162
}
sp
163
\stoptexdefinition
164 165
\startxmlsetups
xml
:
html
:
table
166
\edef
\CellPadding
{
\xmlatt
{
#
1
}{
cellpadding
}}
167
\ifx
\CellPadding
\empty
168
\edef
\CellPadding
{
.
2
5
ex
}
169
\else
170
\edef
\CellPadding
{
\cssgetsinglepadding
\CellPadding
}
171
\fi
172
\startlinecorrection
[
blank
]
173
\doifelse
{
\xmlatt
{
#
1
}{
border
}}
{
0
}
{
174
\bTABLE
[
frame
=
off
,
offset
=
\CellPadding
]
175
\xmlflush
{
#
1
}
176
\eTABLE
177
}
{
178
\bTABLE
[
offset
=
\CellPadding
]
179
\xmlflush
{
#
1
}
180
\eTABLE
181
}
182
\stoplinecorrection
183
\stopxmlsetups
184 185
\startxmlsetups
xml
:
html
:
thead
186
\bTABLEhead
187
\xmlflush
{
#
1
}
188
\eTABLEhead
189
\stopxmlsetups
190 191
\startxmlsetups
xml
:
html
:
tbody
192
\bTABLEbody
193
\xmlflush
{
#
1
}
194
\eTABLEbody
195
\stopxmlsetups
196 197
\startxmlsetups
xml
:
html
:
tfoot
198
\bTABLEfoot
199
\xmlflush
{
#
1
}
200
\eTABLEfoot
201
\stopxmlsetups
202 203
\startxmlsetups
xml
:
html
:
tr
204
\bTR
[
ny
=
\xmlattdef
{
#
1
}{
rowspan
}{
1
}
]
205
\xmlflush
{
#
1
}
206
\eTR
207
\stopxmlsetups
208 209
\startxmlsetups
xml
:
html
:
td
210
\bTD
[
nx
=
\xmlattdef
{
#
1
}{
colspan
}{
1
}
]
211
\xmlflush
{
#
1
}
212
\eTD
213
\stopxmlsetups
214 215
\startxmlsetups
xml
:
html
:
th
216
\bTH
[
nx
=
\xmlattdef
{
#
1
}{
colspan
}{
1
}
]
217
\xmlflush
{
#
1
}
218
\eTH
219
\stopxmlsetups
220 221
% \xmlregistersetup{xml:html:basics}
222 223
%D For old times sake:
224 225
\startxmlsetups
xml
:
setups
:
common
226
\xmlsetup
{
#
1
}{
xml
:
html
:
basics
}
227
\xmlsetup
{
#
1
}{
xml
:
html
:
tables
}
228
% \ifconditional\qmlcleanuptwo
229
% \xmlsetsetup{#1}{html/br[index() == 1]}{xml:noppes:1}
230
% \xmlsetsetup{#1}{html/p[index() == lastindex()]/br[index() == lastindex()]}{xml:noppes:2}
231
% \xmlsetsetup{#1}{html/br[index() == lastindex()]}{xml:noppes:3}
232
% \xmlsetsetup{#1}{br[name(1) == 'img']}{xml:noppes}
233
% \xmlsetsetup{#1}{br[name(1) == 'br' and name(2) == 'img']}{xml:noppes}
234
% % \xmlsetsetup{#1}{br/following-sibling::img[position()==1]}{xml:noppes}
235
% \fi
236
\stopxmlsetups
237 238
\stopmodule
239 240
\continueifinputfile
{
x
-
html
.
mkiv
}
241 242
\xmlregistersetup
{
xml
:
html
:
basics
}
243
\xmlregistersetup
{
xml
:
html
:
tables
}
244 245
\startxmlsetups
xml
:
whatever
246
\xmlsetsetup
{
#
1
}
{
247
html
|
body
248
}
{
xml
:
html
:
*
}
249
\stopxmlsetups
250 251
\xmlregisterdocumentsetup
{
main
}{
xml
:
whatever
}
252 253
\startxmlsetups
xml
:
html
:
html
254
\xmlflush
{
#
1
}
255
\stopxmlsetups
256 257
\startxmlsetups
xml
:
html
:
body
258
\xmlflush
{
#
1
}
259
\stopxmlsetups
260 261
\setuphead
[
subject
][
page
=
yes
,
style
=
\bfa
]
262 263
\starttexdefinition
ShowExample
#
1
264
\startsubject
[
title
=#
1
]
265
\typebuffer
[#
1
]
266
\starttextrule
{
result
}
267
\xmlprocessbuffer
{
main
}{
#
1
}{}
268
\stoptextrule
269
\stopsubject
270
\stoptexdefinition
271 272
\starttext
273 274
\startbuffer
[
test
1
]
275
<
html
><
body
>
276
<
p
>
test
<
/
p
>
277
<
p
/
>
278
<
p
>
test
<
/
p
>
279
<
/
body
><
/
html
>
280
\stopbuffer
281 282
\startbuffer
[
test
2
]
283
<
html
><
body
>
284
<
p
>
test
(
hierna
een
lf
)
285
test
<
/
p
>
286
<
/
body
><
/
html
>
287
\stopbuffer
288 289
\startbuffer
[
test
3
]
290
<
html
><
body
>
291
<
p
>
test
(
hierna
een
lf
met
lege
regel
)
292 293
test
<
/
p
>
294
<
/
body
><
/
html
>
295
\stopbuffer
296 297
\startbuffer
[
test
4
]
298
<
html
><
body
>
299
<
p
>
test
(
hierna
een
lf
met
twee
lege
regels
)
300 301 302
test
<
/
p
>
303
<
/
body
><
/
html
>
304
\stopbuffer
305 306
\startbuffer
[
test
5
]
307
<
html
><
body
>
308
<
p
>
test
(
hierna
br
geen
lf
)<
br
/
>
test
<
/
p
>
309
<
/
body
><
/
html
>
310
\stopbuffer
311 312
\startbuffer
[
test
6
]
313
<
html
><
body
>
314
<
p
>
test
(
hierna
br
met
lf
)<
br
/
>
315
test
<
/
p
>
316
<
/
body
><
/
html
>
317
\stopbuffer
318 319
\startbuffer
[
test
7
]
320
<
html
><
body
>
321
<
p
>
test
(
hierna
br
met
lf
en
lege
regel
)<
br
/
>
322 323
test
<
/
p
>
324
<
/
body
><
/
html
>
325
\stopbuffer
326 327
\startbuffer
[
test
8
]
328
<
html
><
body
>
329
<
p
>
test
(
hierna
br
met
lf
en
twee
lege
regels
)<
br
/
>
330 331 332
test
<
/
p
>
333
<
/
body
><
/
html
>
334
\stopbuffer
335 336
\startbuffer
[
test
9
]
337
<
html
><
body
>
338
<
p
>
test
(
hierna
bold
)
<
b
>
bold
<
/
b
>
test
<
/
p
>
339
<
/
body
><
/
html
>
340
\stopbuffer
341 342
\startbuffer
[
test
1
0
]
343
<
html
><
body
>
344
<
p
>
test
(
hierna
lf
met
bold
)
345
<
b
>
bold
<
u
>
underlined
<
/
u
><
/
b
>
test
<
/
p
>
346
<
/
body
><
/
html
>
347
\stopbuffer
348 349
\startbuffer
[
test
1
1
]
350
<
html
><
body
>
351
<
p
>
test
(
hierna
lf
met
lege
regel
en
bold
)
352 353
<
b
>
bold
<
/
b
>
test
<
/
p
>
354
<
/
body
><
/
html
>
355
\stopbuffer
356 357
\startbuffer
[
test
1
2
]
358
<
html
><
body
>
359
<
p
>
test
(
hierna
lf
met
lege
regel
en
lf
in
bold
)
360 361
<
b
>
362
bold
363
<
/
b
>
test
<
/
p
>
364
<
/
body
><
/
html
>
365
\stopbuffer
366 367
\startbuffer
[
test
1
3
]
368
<
html
><
body
>
369
<
p
>
test
(
hierna
lf
met
lege
regel
en
lf
en
lege
regel
in
bold
)
370 371
<
b
>
372 373
bold
374 375
<
/
b
>
test
<
/
p
>
376
<
/
body
><
/
html
>
377
\stopbuffer
378 379
\dorecurse
{
1
3
}{
\ShowExample
{
test
#
1
}}
380 381
\stoptext
382