1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17\writestatus{loading}{ConTeXt XML Support Initialization}
18
19
20
21
22
23
24\registerctxluafile{lxmlent}{}
25\registerctxluafile{lxmltex}{}
26\registerctxluafile{lxmldir}{}
27\registerctxluafile{lxmlini}{}
28
29\unprotect
30
31
32
33
34
35\permanent\def\ctxlxml#1{\ctxlua{lxml.#1}}
36
37
38
39\permanent\def\xmlconcat #1#2#3{\clf_xmlconcat {#1}{#2}{\detokenize{#3}}}
40\permanent\def\xmlconcatrange #1#2#3#4#5{\clf_xmlconcatrange{#1}{#2}{#3}{#4}{\detokenize{#5}}}
41
42
43
44\permanent\def\xmlloadfile #1#2{\clf_xmlloadfile {#1}{#2}{\directxmlparameter\c!compress}}
45\permanent\def\xmlloadbuffer#1#2{\clf_xmlloadbuffer{#1}{#2}{\directxmlparameter\c!compress}}
46\permanent\def\xmlloaddata #1#2{\clf_xmlloaddata {#1}{#2}{\directxmlparameter\c!compress}}
47
48\aliased\let\xmlload\xmlloadfile
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67\aliased\let\xmlposition\xmlindex
68
69\permanent\protected\def\xmlinfo#1{\hbox{\ttxx[\xmlname{#1}]}}
70\permanent\protected\def\xmlshow#1{\startpacked\ttx\xmlverbatim{#1}\stoppacked}
71
72
73
74
75
76
77
78
79\permanent\protected\def\xmlsetfunction#1#2#3{\ctxcommand{xmlsetfunction("#1",\!!bs#2\!!es,#3)}}
80
81
82
83\immutable\def\xmltempbuffername{xmltemp}
84
85\permanent\protected\def\prettyprintbuffer#1#2
86 {\ifdefined\scitebuffer
87 \scitebuffer[#2][#1]
88 \else
89 \typebuffer[#1][\c!option=#2]
90 \fi}
91
92\permanent\protected\def\xmlprettyprint#1#2
93 {\xmltobufferverbose{#1}{.}{\xmltempbuffername}
94 \prettyprintbuffer\xmltempbuffername{#2}}
95
96\permanent\protected\def\xmlprettyprinttext#1#2
97 {\xmltobuffertextonly{#1}{.}{\xmltempbuffername}
98 \prettyprintbuffer\xmltempbuffername{#2}}
99
100\permanent\protected\def\inlineprettyprintbuffer#1#2
101 {\ifdefined\sciteinlinebuffer
102 \sciteinlinebuffer[#2][#1]
103 \else
104 \typeinlinebuffer[#1][\c!option=#2]
105 \fi}
106
107\permanent\protected\def\xmlinlineprettyprint#1#2
108 {\xmltobufferverbose{#1}{.}{\xmltempbuffername}
109 \inlineprettyprintbuffer\xmltempbuffername{#2}}
110
111\permanent\protected\def\xmlinlineprettyprinttext#1#2
112 {\xmltobuffertextonly{#1}{.}{\xmltempbuffername}
113 \inlineprettyprintbuffer\xmltempbuffername{#2}}
114
115
116
117\aliased\let\xmlstartraw\clf_xmlstartraw
118\aliased\let\xmlstopraw \clf_xmlstopraw
119
120\aliased\let\startxmlraw\clf_xmlstartraw
121\aliased\let\stopxmlraw \clf_xmlstopraw
122
123
124
125
126
127
128
129\aliased\let\xmldoiftextelse \xmldoifelsetext
130\aliased\let\xmldoifemptyelse \xmldoifelseempty
131\aliased\let\xmldoifselfemptyelse \xmldoifelseselfempty
132
133
134
135
136
137
138
139
140
141
142\aliased\let\xmlsetup\setupwithargumentswapped
143\aliased\let\xmls \setupwithargumentswapped
144\aliased\let\xmlw \setupwithargument
145
146
147
148\permanent\protected\def\xmlprependsetup #1{\clf_xmlprependsetup{*}{#1}}
149\permanent\protected\def\xmlappendsetup #1{\clf_xmlappendsetup {*}{#1}}
150\permanent\protected\def\xmlbeforesetup #1#2{\clf_xmlbeforesetup {*}{#1}{#2}}
151\permanent\protected\def\xmlaftersetup #1#2{\clf_xmlaftersetup {*}{#1}{#2}}
152\permanent\protected\def\xmlremovesetup #1{\clf_xmlremovesetup {*}{#1}}
153\permanent\protected\def\xmlresetsetups {\clf_xmlresetsetups {*}}
154
155\permanent\protected\def\xmlprependdocumentsetup #1#2{\clf_xmlprependsetup{#1}{#2}}
156\permanent\protected\def\xmlappenddocumentsetup #1#2{\clf_xmlappendsetup {#1}{#2}}
157\permanent\protected\def\xmlbeforedocumentsetup #1#2#3{\clf_xmlbeforesetup {#1}{#2}{#3}}
158\permanent\protected\def\xmlafterdocumentsetup #1#2#3{\clf_xmlaftersetup {#1}{#2}{#3}}
159\permanent\protected\def\xmlremovedocumentsetup #1#2{\clf_xmlremovesetup {#1}{#2}}
160\permanent\protected\def\xmlresetdocumentsetups #1{\clf_xmlresetsetups {#1}}
161
162\permanent\protected\def\xmlflushsetups #1{\clf_xmlflushsetups {#1}{*}{}}
163\permanent\protected\def\xmlflushdocumentsetups #1#2{\clf_xmlflushsetups {#1}{*}{#2}}
164
165\aliased\let\xmlregistersetup \xmlappendsetup
166\aliased\let\xmlregisterdocumentsetup\xmlappenddocumentsetup
167
168\mutable\def\xmldocument{main}
169
170\permanent\protected\def\xmlregisteredsetups
171 {\xmlstarttiming
172 \xmlflushsetups\xmldocument
173 \xmldefaulttotext\xmldocument
174 \xmlstoptiming}
175
176\permanent\protected\def\xmlregistereddocumentsetups#1#2
177 {\xmlstarttiming
178
179 \xmlflushdocumentsetups{#1}{#2}
180 \xmldefaulttotext{#1}
181 \xmlstoptiming}
182
183\permanent\protected\def\xmlstarttiming{\clf_xmlstarttiming}
184\permanent\protected\def\xmlstoptiming {\clf_xmlstoptiming}
185
186\def\lxml_process#1#2#3#4#5
187 {\begingroup
188 \edef\xmldocument{#3}
189
190 #2{#3}{#4}
191 \setcatcodetable\notcatcodes
192 \xmlsetup{#3}{\ifempty{#5}xml:process\else#5\fi}
193
194 \endgroup}
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211\permanent\protected\def\xmlprocessfile {\lxml_process\plusone \xmlload}
212\permanent\protected\def\xmlprocessdata {\lxml_process\zerocount\xmlloaddata}
213\permanent\protected\def\xmlprocessbuffer{\lxml_process\zerocount\xmlloadbuffer}
214\aliased \let\xmlprocess \xmlprocessfile
215
216\startxmlsetups xml:flush
217 \xmlflush{#1}
218\stopxmlsetups
219
220\startxmlsetups xml:process
221 \xmlregistereddocumentsetups{#1}{#1}
222 \xmlmain{#1}
223\stopxmlsetups
224
225\permanent\protected\def\xmlloadonly#1#2#3
226 {\xmlload{#1}{#2}
227 \xmlregistereddocumentsetups{#1}{#3}}
228
229
230
231
232
233
234
235
236
237
238
239
240
241\permanent\protected\def\xmlcdataobeyedline {\obeyedline}
242\permanent\protected\def\xmlcdataobeyedspace{\strut\obeyedspace}
243\permanent\protected\def\xmlcdatabefore {\begingroup\tt}
244\permanent\protected\def\xmlcdataafter {\endgroup}
245
246
247
248
249
250
251
252
253
254
255
256
257
258\permanent\tolerant\protected\def\startxmldisplayverbatim[#1]
259 {\startpacked
260 \cdef\currenttyping{#1}
261 \ifempty\currenttyping
262 \let\currenttyping\v!typing
263 \else
264 \cdef\currenttyping{xml:\currenttyping}
265 \fi
266 \enforced\protected\def\stopxmldisplayverbatim
267 {\endofverbatimlines
268 \stoppacked}
269 \doinitializeverbatim
270 \beginofverbatimlines}
271
272\permanent\protected\lettonothing\stopxmldisplayverbatim
273
274\permanent\tolerant\protected\def\startxmlinlineverbatim[#1]
275 {\begingroup
276 \cdef\currenttype{#1}
277 \ifempty\currenttype
278 \let\currenttype\v!type
279 \else
280 \cdef\currenttype{xml:\currenttype}
281 \fi
282 \enforced\let\stopxmlinlineverbatim\endgroup
283 \doinitializeverbatim}
284
285\permanent\protected\lettonothing\stopxmlinlineverbatim
286
287
288
289\permanent\protected\def\xmlinstalldirective#1#2
290 {\clf_xmlinstalldirective{#1}{\csstring#2}}
291
292
293
294
295
296\appendtoks
297 \xmlinstalldirective{tex}{xmltexcommand}
298\to \everyjob
299
300\permanent\def\xmltexcommand#1{\begincsname#1\endcsname}
301
302
303
304
305
306
307
308
309
310
311
312
313\newconstant\xmlprocessingmode
314
315\installcorenamespace{xml}
316\installcorenamespace{xmldefaults}
317\installcorenamespace{xmlmapvalue}
318
319\installdirectcommandhandler \??xml {xml}
320
321\letcsname\??xmldefaults\v!normal\endcsname\zerocount
322\letcsname\??xmldefaults\v!none \endcsname\zerocount
323\letcsname\??xmldefaults\v!text \endcsname\plusone
324\letcsname\??xmldefaults\v!hidden\endcsname\plustwo
325
326\permanent\protected\def\xmldefaulttotext
327 {\ifcase\xmlprocessingmode
328 \expandafter\gobbleoneargument
329 \or
330 \expandafter\clf_xmlsetcommandtotext
331 \or
332 \expandafter\clf_xmlsetcommandtonone
333 \else
334 \expandafter\gobbleoneargument
335 \fi}
336
337\appendtoks
338 \xmlprocessingmode\executeifdefined{\??xmldefaults\directxmlparameter\c!default}\plusone
339\to \everysetupxml
340
341\setupxml
342 [\c!default=,
343 \c!compress=\v!no,
344 \c!entities=\v!no]
345
346\appendtoks
347 \ifcstok{\directxmlparameter\c!entities}\v!yes
348 \clf_xmlloadentities
349 \fi
350\to \everysetupxml
351
352\permanent\def\xmlmapvalue #1#2#3{\defcsname\??xmlmapvalue#1:#2\endcsname{#3}}
353\permanent\def\xmldoifelsevalue #1#2{\ifcsname\??xmlmapvalue#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
354
355\permanent\def\xmlvalue#1#2
356 {\ifcsname\??xmlmapvalue#1:#2\endcsname
357 \expandafter\expandafter\expandafter\lastnamedcs\expandafter\gobbleoneargument
358 \else
359 \expandafter\firstofoneargument
360 \fi}
361
362\permanent\def\xmlmappedvalue#1#2#3
363 {\ifcsname\??xmlmapvalue#1:#2\endcsname
364 \expandafter\lastnamedcs
365 \else
366 \csname\??xmlmapvalue#1:#3\expandafter\endcsname
367 \fi}
368
369\aliased\let\xmldoifvalueelse\xmldoifelsevalue
370
371\aliased\let\xmlmapval\xmlmapvalue
372\aliased\let\xmlval \xmlvalue
373
374
375
376\permanent\def\xmlgetindex #1{\clf_xmlgetindex {\xmldocument}{#1}}
377\permanent\def\xmlwithindex #1#2{\clf_xmlwithindex{\xmldocument}{#1}{#2}}
378\permanent\def\xmlreference #1#2{\string\xmlwithindex{#1}{#2}}
379
380
381
382
383
384
385
386\permanent\protected\def\xmlsetentity#1#2{\clf_xmlsetentity{#1}{\detokenize{#2}}}
387\permanent\protected\def\xmltexentity#1#2{\clf_xmltexentity{#1}{\detokenize{#2}}}
388
389
390
391\setnewconstant\xmlautoentities\plusone
392
393\permanent\protected\def\xmle
394 {\ifcase\xmlautoentities
395 \expandafter\lxml_e_none
396 \or
397 \expandafter\lxml_e_upper
398 \or
399 \expandafter\lxml_e_upperlower
400 \else
401 \expandafter\lxml_e_none
402 \fi}
403
404\def\lxml_e_none#1#2
405 {#1}
406
407\def\lxml_e_upper#1#2
408 {\ifcsname#2\endcsname
409 \csname#2\expandafter\endcsname
410 \else
411 #1
412 \fi}
413
414\def\lxml_e_upperlower#1#2
415 {\ifcsname#2\endcsname
416 \csname#2\expandafter\endcsname
417 \orelse\ifcsname#1\endcsname
418 \csname#1\expandafter\endcsname
419 \else
420 #1
421 \fi}
422
423
424
425
426\permanent\tolerant\protected\def\processXMLbuffer[#1]{\xmlprocessbuffer{temp}{#1}{}}
427\permanent \protected\def\processXMLfile #1{\xmlprocessfile {temp}{#1}{}}
428\permanent \protected\def\XMLdata #1{\xmlprocessdata {temp}{#1}{}}
429
430\aliased\let\processxmlbuffer\processXMLbuffer
431\aliased\let\processxmlfile \processXMLfile
432\aliased\let\xmldata \XMLdata
433
434\permanent\protected\def\xmlsetinjectors [#1]{\clf_xmlsetinjectors{#1}}
435\permanent\protected\def\xmlresetinjectors {\clf_xmlresetinjectors{}}
436
437
438
439\permanent\def\xmlinjector#1{\fastsetup{xml:directive:injector:#1}}
440
441\startsetups xml:directive:injector:page
442 \page
443\stopsetups
444
445\startsetups xml:directive:injector:column
446 \column
447\stopsetups
448
449\startsetups xml:directive:injector:blank
450 \blank
451\stopsetups
452
453\startsetups xml:directive:injector:noline
454 \vskip\lineheight
455\stopsetups
456
457\aliased\let\xmlapplyselectors\clf_xmlapplyselectors
458
459
460
461
462\protect \endinput
463
464 |