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\def\ctxlxml #1{\ctxlua{lxml.#1}}
36
37
38
39\def\xmlconcat #1#2#3{\clf_xmlconcat {#1}{#2}{\detokenize{#3}}}
40\def\xmlconcatrange #1#2#3#4#5{\clf_xmlconcatrange{#1}{#2}{#3}{#4}{\detokenize{#5}}}
41
42
43
44\def\xmlloadfile #1#2{\clf_xmlloadfile {#1}{#2}{\directxmlparameter\c!compress}}
45\def\xmlloadbuffer#1#2{\clf_xmlloadbuffer{#1}{#2}{\directxmlparameter\c!compress}}
46\def\xmlloaddata #1#2{\clf_xmlloaddata {#1}{#2}{\directxmlparameter\c!compress}}
47
48\let\xmlload\xmlloadfile
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\let\xmlposition \xmlindex
132
133\unexpanded\def\xmlinfo#1{\hbox{\ttxx[\xmlname{#1}]}}
134\unexpanded\def\xmlshow#1{\startpacked\ttx\xmlverbatim{#1}\stoppacked}
135
136
137
138
139
140
141
142
143\unexpanded\def\xmlsetfunction#1#2#3{\ctxcommand{xmlsetfunction("#1",\!!bs#2\!!es,#3)}}
144
145
146
147\def\xmltempbuffername{xmltemp}
148
149\unexpanded\def\prettyprintbuffer#1#2
150 {\ifdefined\scitebuffer
151 \scitebuffer[#2][#1]
152 \else
153 \typebuffer[#1][\c!option=#2]
154 \fi}
155
156\unexpanded\def\xmlprettyprint#1#2
157 {\xmltobufferverbose{#1}{.}{\xmltempbuffername}
158 \prettyprintbuffer\xmltempbuffername{#2}}
159
160\unexpanded\def\xmlprettyprinttext#1#2
161 {\xmltobuffertextonly{#1}{.}{\xmltempbuffername}
162 \prettyprintbuffer\xmltempbuffername{#2}}
163
164\unexpanded\def\inlineprettyprintbuffer#1#2
165 {\ifdefined\sciteinlinebuffer
166 \sciteinlinebuffer[#2][#1]
167 \else
168 \typeinlinebuffer[#1][\c!option=#2]
169 \fi}
170
171\unexpanded\def\xmlinlineprettyprint#1#2
172 {\xmltobufferverbose{#1}{.}{\xmltempbuffername}
173 \inlineprettyprintbuffer\xmltempbuffername{#2}}
174
175\unexpanded\def\xmlinlineprettyprinttext#1#2
176 {\xmltobuffertextonly{#1}{.}{\xmltempbuffername}
177 \inlineprettyprintbuffer\xmltempbuffername{#2}}
178
179
180
181\let\xmlstartraw\clf_xmlstartraw
182\let\xmlstopraw \clf_xmlstopraw
183
184\let\startxmlraw\clf_xmlstartraw
185\let\stopxmlraw \clf_xmlstopraw
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207\let\xmldoiftextelse \xmldoifelsetext
208\let\xmldoifemptyelse \xmldoifelseempty
209\let\xmldoifselfemptyelse \xmldoifelseselfempty
210
211
212
213
214
215
216
217
218
219
220\let\xmlsetup\setupwithargumentswapped
221\let\xmls \setupwithargumentswapped
222\let\xmlw \setupwithargument
223
224
225
226\unexpanded\def\xmlprependsetup #1{\clf_xmlprependsetup{*}{#1}}
227\unexpanded\def\xmlappendsetup #1{\clf_xmlappendsetup {*}{#1}}
228\unexpanded\def\xmlbeforesetup #1#2{\clf_xmlbeforesetup {*}{#1}{#2}}
229\unexpanded\def\xmlaftersetup #1#2{\clf_xmlaftersetup {*}{#1}{#2}}
230\unexpanded\def\xmlremovesetup #1{\clf_xmlremovesetup {*}{#1}}
231\unexpanded\def\xmlresetsetups {\clf_xmlresetsetups {*}}
232
233\unexpanded\def\xmlprependdocumentsetup #1#2{\clf_xmlprependsetup{#1}{#2}}
234\unexpanded\def\xmlappenddocumentsetup #1#2{\clf_xmlappendsetup {#1}{#2}}
235\unexpanded\def\xmlbeforedocumentsetup #1#2#3{\clf_xmlbeforesetup {#1}{#2}{#3}}
236\unexpanded\def\xmlafterdocumentsetup #1#2#3{\clf_xmlaftersetup {#1}{#2}{#3}}
237\unexpanded\def\xmlremovedocumentsetup #1#2{\clf_xmlremovesetup {#1}{#2}}
238\unexpanded\def\xmlresetdocumentsetups #1{\clf_xmlresetsetups {#1}}
239
240\unexpanded\def\xmlflushsetups #1{\clf_xmlflushsetups {#1}{*}{}}
241\unexpanded\def\xmlflushdocumentsetups #1#2{\clf_xmlflushsetups {#1}{*}{#2}}
242
243\let\xmlregistersetup \xmlappendsetup
244\let\xmlregisterdocumentsetup\xmlappenddocumentsetup
245
246\def\xmldocument{main}
247
248\unexpanded\def\xmlregisteredsetups
249 {\xmlstarttiming
250 \xmlflushsetups\xmldocument
251 \xmldefaulttotext\xmldocument
252 \xmlstoptiming}
253
254\unexpanded\def\xmlregistereddocumentsetups#1#2
255 {\xmlstarttiming
256
257 \xmlflushdocumentsetups{#1}{#2}
258 \xmldefaulttotext{#1}
259 \xmlstoptiming}
260
261\unexpanded\def\xmlstarttiming{\clf_xmlstarttiming}
262\unexpanded\def\xmlstoptiming {\clf_xmlstoptiming}
263
264\def\lxml_process#1#2#3#4#5
265 {\begingroup
266 \edef\xmldocument{#3}
267
268 #2{#3}{#4}
269 \setcatcodetable\notcatcodes
270 \doifelsenothing{#5}
271 {\xmlsetup{#3}{xml:process}}
272 {\xmlsetup{#3}{#5}}
273
274 \endgroup}
275
276\unexpanded\def\xmlprocessfile {\lxml_process\plusone \xmlload}
277\unexpanded\def\xmlprocessdata {\lxml_process\zerocount\xmlloaddata}
278\unexpanded\def\xmlprocessbuffer {\lxml_process\zerocount\xmlloadbuffer}
279 \let\xmlprocess \xmlprocessfile
280
281\startxmlsetups xml:flush
282 \xmlflush{#1}
283\stopxmlsetups
284
285\startxmlsetups xml:process
286 \xmlregistereddocumentsetups{#1}{#1}
287 \xmlmain{#1}
288\stopxmlsetups
289
290\unexpanded\def\xmlloadonly#1#2#3
291 {\xmlload{#1}{#2}
292 \xmlregistereddocumentsetups{#1}{#3}}
293
294
295
296
297
298
299
300
301
302
303
304
305
306\unexpanded\def\xmlcdataobeyedline {\obeyedline}
307\unexpanded\def\xmlcdataobeyedspace{\strut\obeyedspace}
308\unexpanded\def\xmlcdatabefore {\begingroup\tt}
309\unexpanded\def\xmlcdataafter {\endgroup}
310
311
312
313
314
315
316
317
318
319
320
321
322
323\unexpanded\def\startxmldisplayverbatim
324 {\dosingleempty\lxml_start_display_verbatim}
325
326\let\stopxmldisplayverbatim\relax
327
328\def\lxml_start_display_verbatim[#1]
329 {\startpacked
330 \edef\currenttyping{#1}
331 \ifx\currenttyping\empty
332 \let\currenttyping\v!typing
333 \else
334 \edef\currenttyping{xml:\currenttyping}
335 \fi
336 \unexpanded\def\stopxmldisplayverbatim
337 {\endofverbatimlines
338 \stoppacked}
339 \doinitializeverbatim
340 \beginofverbatimlines}
341
342\unexpanded\def\startxmlinlineverbatim
343 {\dosingleempty\lxml_start_inline_verbatim}
344
345\let\stopxmlinlineverbatim\relax
346
347\unexpanded\def\lxml_start_inline_verbatim[#1]
348 {\begingroup
349 \edef\currenttype{#1}
350 \ifx\currenttype\empty
351 \let\currenttype\v!type
352 \else
353 \edef\currenttype{xml:\currenttype}
354 \fi
355 \let\stopxmlinlineverbatim\endgroup
356 \doinitializeverbatim}
357
358
359
360\unexpanded\def\xmlinstalldirective#1#2
361 {\clf_xmlinstalldirective{#1}{\csstring#2}}
362
363
364
365
366
367\appendtoks
368 \xmlinstalldirective{tex}{xmltexcommand}
369\to \everyjob
370
371\def\xmltexcommand#1{\begincsname#1\endcsname}
372
373
374
375
376
377
378
379
380
381
382
383
384\newconstant\xmlprocessingmode
385
386\installcorenamespace{xml}
387\installcorenamespace{xmldefaults}
388\installcorenamespace{xmlmapvalue}
389
390\installdirectcommandhandler \??xml {xml}
391
392\letvalue{\??xmldefaults\v!normal}\zerocount
393\letvalue{\??xmldefaults\v!none }\zerocount
394\letvalue{\??xmldefaults\v!text }\plusone
395\letvalue{\??xmldefaults\v!hidden}\plustwo
396
397\unexpanded\def\xmldefaulttotext
398 {\ifcase\xmlprocessingmode
399 \expandafter\gobbleoneargument
400 \or
401 \expandafter\clf_xmlsetcommandtotext
402 \or
403 \expandafter\clf_xmlsetcommandtonone
404 \else
405 \expandafter\gobbleoneargument
406 \fi}
407
408\appendtoks
409 \xmlprocessingmode\executeifdefined{\??xmldefaults\directxmlparameter\c!default}\plusone
410\to \everysetupxml
411
412\setupxml
413 [\c!default=,
414 \c!compress=\v!no,
415 \c!entities=\v!no]
416
417\appendtoks
418 \doif{\directxmlparameter\c!entities}\v!yes\clf_xmlloadentities
419\to \everysetupxml
420
421\def\xmlmapvalue #1#2#3{\setvalue{\??xmlmapvalue#1:#2}{#3}}
422\def\xmldoifelsevalue #1#2{\ifcsname\??xmlmapvalue#1:#2\endcsname\expandafter\firstoftwoarguments\else\expandafter\secondoftwoarguments\fi}
423
424\def\xmlvalue#1#2
425 {\ifcsname\??xmlmapvalue#1:#2\endcsname
426 \expandafter\expandafter\expandafter\lastnamedcs\expandafter\gobbleoneargument
427 \else
428 \expandafter\firstofoneargument
429 \fi}
430
431\def\xmlmappedvalue#1#2#3
432 {\ifcsname\??xmlmapvalue#1:#2\endcsname
433 \expandafter\lastnamedcs
434 \else
435 \csname\??xmlmapvalue#1:#3\expandafter\endcsname
436 \fi}
437
438\let\xmldoifvalueelse\xmldoifelsevalue
439
440\let\xmlmapval\xmlmapvalue
441\let\xmlval \xmlvalue
442
443
444
445\def\xmlgetindex #1{\clf_xmlgetindex {\xmldocument}{#1}}
446\def\xmlwithindex #1#2{\clf_xmlwithindex{\xmldocument}{#1}{#2}}
447\def\xmlreference #1#2{\string\xmlwithindex{#1}{#2}}
448
449
450
451
452
453
454
455\unexpanded\def\xmlsetentity#1#2{\clf_xmlsetentity{#1}{\detokenize{#2}}}
456\unexpanded\def\xmltexentity#1#2{\clf_xmltexentity{#1}{\detokenize{#2}}}
457
458
459
460\setnewconstant\xmlautoentities\plusone
461
462\unexpanded\def\xmle
463 {\ifcase\xmlautoentities
464 \expandafter\lxml_e_none
465 \or
466 \expandafter\lxml_e_upper
467 \or
468 \expandafter\lxml_e_upperlower
469 \else
470 \expandafter\lxml_e_none
471 \fi}
472
473\def\lxml_e_none#1#2
474 {#1}
475
476\def\lxml_e_upper#1#2
477 {\ifcsname#2\endcsname
478 \csname#2\expandafter\endcsname
479 \else
480 #1
481 \fi}
482
483\def\lxml_e_upperlower#1#2
484 {\ifcsname#2\endcsname
485 \csname#2\expandafter\endcsname
486 \else\ifcsname#1\endcsname
487 \csname#1\expandafter\expandafter\expandafter\endcsname
488 \else
489 #1
490 \fi\fi}
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511\unexpanded\def\processXMLbuffer
512 {\dosingleempty\lxml_process_buffer}
513
514\def\lxml_process_buffer[#1]
515 {\xmlprocessbuffer{temp}{#1}{}}
516
517\unexpanded\def\processXMLfile#1
518 {\xmlprocessfile{temp}{#1}{}}
519
520\unexpanded\def\XMLdata#1
521 {\xmlprocessdata{temp}{#1}{}}
522
523\let\processxmlbuffer\processXMLbuffer
524\let\processxmlfile \processXMLfile
525\let\xmldata \XMLdata
526
527\unexpanded\def\xmlsetinjectors[#1]
528 {\clf_xmlsetinjectors{#1}}
529
530\unexpanded\def\xmlresetinjectors
531 {\clf_xmlresetinjectors{}}
532
533
534
535\def\xmlinjector#1{\fastsetup{xml:directive:injector:#1}}
536
537\startsetups xml:directive:injector:page
538 \page
539\stopsetups
540
541\startsetups xml:directive:injector:column
542 \column
543\stopsetups
544
545\startsetups xml:directive:injector:blank
546 \blank
547\stopsetups
548
549\startsetups xml:directive:injector:noline
550 \vskip\lineheight
551\stopsetups
552
553\let\xmlapplyselectors\clf_xmlapplyselectors
554
555
556
557\protect \endinput
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578 |