Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-xhtml-xtpipes.tex

raw
1 % $Id: tex4ht-xhtml-xtpipes.tex 740 2020-06-13 22:35:32Z karl $
2 % htlatex tex4ht-xhtml-xtpipes "xhtml,next,3" "" "-d./"
3 %
4 % Copyright 2009-2020 TeX Users Group
5 % Copyright 1996-2009 Eitan M. Gurari
6 % Released under LPPL 1.3c+.
7 % See tex4ht-cpright.tex for license text.
8
9 \documentclass{article}
10 \Configure{ProTex}{log,<<<>>>,title,list,`,[[]]}
11 \usepackage{url}
12 \input{common.tex}
13 \begin{document}
14 \input tex4ht-cpright.tex
15 \input tex4ht-dir
16
17
18 %%%%%%%%%%%%%%%%%%
19 \part{Post Processing for Html Output Mode}
20 %%%%%%%%%%%%%%%%%%
21
22
23 %%%%%%%%%%%%%%%%%%
24 \section{Outline}
25 %%%%%%%%%%%%%%%%%%
26
27 \AtEndDocument{\OutputCodE\<xhtml.4xt\>}
28
29 \Needs{"xmllint --valid --noout xhtml.4xt"}
30
31 \<xhtml.4xt\><<<
32 <?xml version="1.0" encoding="UTF-8" ?>
33 <!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" >
34 <!-- xhtml.4xt (`version), generated from `jobname.tex
35 Copyright (C) 2009-2010 TeX Users Group
36 Copyright (C) `CopyYear.2008. Eitan M. Gurari
37 `<TeX4ht copyright`> -->
38 <xtpipes preamble="yes" signature="xhtml.4xt (`version)">
39 <sax content-handler="xtpipes.util.ScriptsManager"
40 lexical-handler="xtpipes.util.ScriptsManagerLH" >
41 `<tabular script`>
42 `<longtable script`>
43 `<email script`>
44 `<empty html element script`>
45 </sax>
46 </xtpipes>
47 >>>
48
49
50 %%%%%%%%%%%%%%%%%%
51 \section{email script}
52 %%%%%%%%%%%%%%%%%%
53
54 \<email script\><<<
55 <script element="span::email" >
56 `<set htm email links`>
57 </script>
58 >>>
59
60 <set name="email" >
61 `<open xslt script`>
62 `<email templates`>
63 `<close xslt script`>
64 </set>
65 <xslt name="." xml="." xsl="email" />
66
67
68 \<email templates\><<<
69 <xsl:template match=" text()[contains(.,'@')] " >
70 <span class="set-emails">
71 <xsl:copy>
72 </xsl:copy>
73 </span>
74 </xsl:template>
75 >>>
76
77
78 \<set htm email links\><<<
79 <sax name="." xml="." content-handler="tex4ht.XhtmlEmails" />
80 >>>
81
82
83
84
85 \<java licence\><<<
86 (`version)
87 >>>
88
89
90 \AtEndDocument{%
91 \OutputCodE\<XhtmlEmails.java\>
92 }
93 \ifdojava
94 \Needs{"
95 javac -classpath \TEXMFTEXivBIN tex4ht.jar
96 XhtmlEmails.java
97 -d \XTPIPES
98 "}
99 \fi
100
101 \<XhtmlEmails.java\><<<
102 package tex4ht;
103 /* XhtmlEmails.java (`version), generated from `jobname.tex
104 Copyright (C) 2009-2010 TeX Users Group
105 Copyright (C) `CopyYear.2008. Eitan M. Gurari
106 `<TeX4ht copyright`> */
107
108 import xtpipes.XtpipesUni;
109 import org.xml.sax.*;
110 import org.xml.sax.helpers.DefaultHandler;
111 import java.io.*;
112 import java.lang.reflect.*;
113 import java.util.HashMap;
114
115 public class XhtmlEmails extends DefaultHandler {
116 PrintWriter out = null;
117 String data = "";
118 public XhtmlEmails(PrintWriter out,
119 HashMap<String,Object> scripts,
120 Method method, PrintWriter log, boolean trace) {
121 this.out = out;
122 }
123 public void characters(char[] ch, int start, int length) {
124 data += new String(ch, start, length);
125
126 //XtpipesUni.toUni(ch, start, length, "<>&");
127 }
128
129 public void startElement(String ns, String sName,
130 String qName,
131 Attributes atts) {
132 String s = "<" + qName + "\n";
133 for (int i = 0; i < atts.getLength(); i++) {
134 String name = atts.getQName(i);
135 s += (" " + name + "=\""
136 + XtpipesUni.toUni(atts.getValue(i), "<>&\"")
137 + "\"");
138 }
139 s += ">";
140 `<process email data`>
141 out.print(XtpipesUni.toUni(data, "&") + s);
142 data = "";
143 }
144 public void endElement(String ns, String sName, String qName) {
145 String s = "</" + qName + ">";
146 `<process email data`>
147 out.print( XtpipesUni.toUni(data, "&") + s);
148 data = "";
149 }
150
151 }
152 >>>
153
154
155 \<process email data\><<<
156 while( data.indexOf('@') >0 ){
157 `<clean prefix`>
158 `<clean postfix`>
159 }
160 data = XtpipesUni.toUni(data, "<>&");
161 >>>
162
163
164
165
166 \<clean prefix\><<<
167 String [] pre = data.split(
168 "[`<email name`>]*@"
169 , 2);
170 if( pre[0].endsWith("}") ){
171 if( pre[0].indexOf("{") != -1 ){
172 pre[0] = pre[0].substring( 0, pre[0].lastIndexOf("{") );
173 } }
174 int len = pre[0] . length();
175 if( len > 0 ){
176 out.print( XtpipesUni.toUni(pre[0], "<>&") );
177 data = data.substring(len);
178 }
179 >>>
180
181 \<clean postfix\><<<
182 String [] post = data.split(
183 "@[`<email name`>]*"
184 , 2);
185 if( post[1] . length() > 0 ){
186 data = data.substring(0, data.length() - post[1] . length());
187 }
188 `<set a link to email`>
189 data = post[1];
190 >>>
191
192
193 \<set a link to email\><<<
194 if( data.indexOf("{") == -1 ){
195 out.print(
196 "<a href=\"mailto:" + XtpipesUni.toUni(data, "&") + "\">"
197 + XtpipesUni.toUni(data, "<>&")
198 + "</a>"
199 );
200 } else {
201 int idx = data.indexOf('@');
202 String ext = data.substring(idx);
203 data = data.substring(0,idx);
204 `<clean group prefix`>
205 }
206 >>>
207
208
209
210 \<clean group prefix\><<<
211 while( true ){
212 pre = data.split(
213 "[`<email name`>]+"
214 , 2);
215 if( pre.length < 2 ){
216 out.print( XtpipesUni.toUni(data + ext, "<>&") );
217 data = "";
218 break;
219 }
220 len = pre[0] . length();
221 if( len > 0 ){
222 out.print( XtpipesUni.toUni(pre[0], "<>&") );
223 data = data.substring(len);
224 }
225 data = data.substring(0, data.length() - pre[1].length());
226 out.print(
227 "<a href=\"mailto:" + XtpipesUni.toUni(data + ext, "&") + "\">"
228 + XtpipesUni.toUni(data, "<>&")
229 + "</a>"
230 );
231 data = pre[1];
232 }
233 >>>
234
235 \<email name\><<<
236 \\p{javaLowerCase}\\p{javaUpperCase}\\d\\-_\\./&>>>
237
238
239 \url{http://tools.ietf.org/html/rfc2368}
240
241 \begin{verbatim}
242 Alice Smith" <[email protected]>
243 {alice, bob}@somewhere.com
244 [email protected], [email protected]
245 \end{verbatim}
246
247 %%%%%%%%%%%%%%%%%%
248 \section{Long Tables}
249 %%%%%%%%%%%%%%%%%%
250
251
252
253 \<longtable script\><<<
254 <script element="table::longtable" >
255 <set name="longtbl" >
256 `<open xslt script`>
257 `<longtable templates`>
258 `<close xslt script`>
259 </set>
260 <xslt name="." xml="." xsl="longtbl" />
261 </script>
262 >>>
263
264
265 \<longtable templates\><<<
266 <xsl:template match=" table[ @class='longtable' ]
267 / tr[ (normalize-space(.)='') ] " >
268 <xsl:if test=" normalize-space(following-sibling::*) != '' ">
269 <xsl:copy>
270 <xsl:apply-templates select="*|@*|text()|comment()" />
271 </xsl:copy>
272 </xsl:if>
273 </xsl:template>
274 >>>
275
276
277
278
279 %%%%%%%%%%%%%%%%%%
280 \section{Tabular}
281 %%%%%%%%%%%%%%%%%%
282
283
284
285 \<tabular script\><<<
286 <script element="table::tabular" >
287 <set name="tabular" >
288 `<open xslt script`>
289 `<tabular templates`>
290 `<close xslt script`>
291 </set>
292 <xslt name="." xml="." xsl="tabular" />
293 </script>
294 >>>
295
296
297 \<tabular templates\><<<
298 <xsl:template match=" table[ @class='tabular' ]
299 / tr[ (normalize-space(.)='') ] " >
300
301 <xsl:message terminate="no">
302 OK 1
303 </xsl:message>
304
305 <xsl:if test=" normalize-space(following-sibling::*) != '' ">
306 <xsl:copy>
307 <xsl:apply-templates select="*|@*|text()|comment()" />
308 <xsl:message terminate="no">
309 OK 2
310 </xsl:message>
311 </xsl:copy>
312 </xsl:if>
313 </xsl:template>
314 >>>
315
316
317
318
319
320 \<tabular templates\><<<
321 <xsl:template match=" tr[ (normalize-space(.)='')
322 and
323 (parent::table[ @class='tabular' ])
324 ] " >
325
326 <xsl:message terminate="no">
327 OK 1
328 </xsl:message>
329
330 <xsl:if test=" normalize-space(following-sibling::*) != '' ">
331 <xsl:copy>
332 <xsl:apply-templates select="*|@*|text()|comment()" />
333 <xsl:message terminate="no">
334 OK 2
335 </xsl:message>
336 </xsl:copy>
337 </xsl:if>
338 </xsl:template>
339 >>>
340
341
342 %%%%%%%%%%%%%%%%%%
343 \section{Empty HTML Element Script}
344 %%%%%%%%%%%%%%%%%%
345
346 \<empty html element script\><<<
347 <script element="meta" >
348 <set name="meta" >
349 `<open xslt script`>
350 <xsl:template match="meta" >
351 <xsl:text disable-output-escaping="yes">&lt;meta</xsl:text>
352 <xsl:apply-templates select="@*" mode="attrs" />
353 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
354 </xsl:template>
355 `<copy attributes`>
356 `<close xslt script`>
357 </set>
358 <xslt name="." xml="." xsl="meta" />
359 </script>
360 >>>
361
362
363 \<empty html element script\><<<
364 <script element="area" >
365 <set name="area" >
366 `<open xslt script`>
367 <xsl:template match="area" >
368 <xsl:text disable-output-escaping="yes">&lt;area</xsl:text>
369 <xsl:apply-templates select="@*" mode="attrs" />
370 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
371 </xsl:template>
372 `<copy attributes`>
373 `<close xslt script`>
374 </set>
375 <xslt name="." xml="." xsl="area" />
376 </script>
377 >>>
378
379
380
381
382 \<empty html element script\><<<
383 <script element="base" >
384 <set name="base" >
385 `<open xslt script`>
386 <xsl:template match="base" >
387 <xsl:text disable-output-escaping="yes">&lt;base</xsl:text>
388 <xsl:apply-templates select="@*" mode="attrs" />
389 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
390 </xsl:template>
391 `<copy attributes`>
392 `<close xslt script`>
393 </set>
394 <xslt name="." xml="." xsl="base" />
395 </script>
396 >>>
397
398
399
400
401 \<empty html element script\><<<
402 <script element="basefont" >
403 <set name="basefont" >
404 `<open xslt script`>
405 <xsl:template match="basefont" >
406 <xsl:text disable-output-escaping="yes">&lt;basefont</xsl:text>
407 <xsl:apply-templates select="@*" mode="attrs" />
408 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
409 </xsl:template>
410 `<copy attributes`>
411 `<close xslt script`>
412 </set>
413 <xslt name="." xml="." xsl="basefont" />
414 </script>
415 >>>
416
417
418
419
420 \<empty html element script\><<<
421 <script element="br" >
422 <set name="br" >
423 `<open xslt script`>
424 <xsl:template match="br" >
425 <xsl:text disable-output-escaping="yes">&lt;br</xsl:text>
426 <xsl:apply-templates select="@*" mode="attrs" />
427 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
428 </xsl:template>
429 `<copy attributes`>
430 `<close xslt script`>
431 </set>
432 <xslt name="." xml="." xsl="br" />
433 </script>
434 >>>
435
436
437
438
439 \<empty html element script\><<<
440 <script element="col" >
441 <set name="col" >
442 `<open xslt script`>
443 <xsl:template match="col" >
444 <xsl:text disable-output-escaping="yes">&lt;col</xsl:text>
445 <xsl:apply-templates select="@*" mode="attrs" />
446 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
447 </xsl:template>
448 `<copy attributes`>
449 `<close xslt script`>
450 </set>
451 <xslt name="." xml="." xsl="col" />
452 </script>
453 >>>
454
455
456
457
458 \<empty html element script\><<<
459 <script element="frame" >
460 <set name="frame" >
461 `<open xslt script`>
462 <xsl:template match="frame" >
463 <xsl:text disable-output-escaping="yes">&lt;frame</xsl:text>
464 <xsl:apply-templates select="@*" mode="attrs" />
465 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
466 </xsl:template>
467 `<copy attributes`>
468 `<close xslt script`>
469 </set>
470 <xslt name="." xml="." xsl="frame" />
471 </script>
472 >>>
473
474
475
476
477 \<empty html element script\><<<
478 <script element="hr" >
479 <set name="hr" >
480 `<open xslt script`>
481 <xsl:template match="hr" >
482 <xsl:text disable-output-escaping="yes">&lt;hr</xsl:text>
483 <xsl:apply-templates select="@*" mode="attrs" />
484 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
485 </xsl:template>
486 `<copy attributes`>
487 `<close xslt script`>
488 </set>
489 <xslt name="." xml="." xsl="hr" />
490 </script>
491 >>>
492
493
494
495
496 \<empty html element script\><<<
497 <script element="img" >
498 <set name="img" >
499 `<open xslt script`>
500 <xsl:template match="img" >
501 <xsl:text disable-output-escaping="yes">&lt;img</xsl:text>
502 <xsl:apply-templates select="@*" mode="attrs" />
503 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
504 </xsl:template>
505 `<copy attributes`>
506 `<close xslt script`>
507 </set>
508 <xslt name="." xml="." xsl="img" />
509 </script>
510 >>>
511
512
513
514
515 \<empty html element script\><<<
516 <script element="input" >
517 <set name="input" >
518 `<open xslt script`>
519 <xsl:template match="input" >
520 <xsl:text disable-output-escaping="yes">&lt;input</xsl:text>
521 <xsl:apply-templates select="@*" mode="attrs" />
522 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
523 </xsl:template>
524 `<copy attributes`>
525 `<close xslt script`>
526 </set>
527 <xslt name="." xml="." xsl="input" />
528 </script>
529 >>>
530
531
532
533
534 \<empty html element script\><<<
535 <script element="isindex" >
536 <set name="isindex" >
537 `<open xslt script`>
538 <xsl:template match="isindex" >
539 <xsl:text disable-output-escaping="yes">&lt;isindex</xsl:text>
540 <xsl:apply-templates select="@*" mode="attrs" />
541 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
542 </xsl:template>
543 `<copy attributes`>
544 `<close xslt script`>
545 </set>
546 <xslt name="." xml="." xsl="isindex" />
547 </script>
548 >>>
549
550
551
552
553 \<empty html element script\><<<
554 <script element="link" >
555 <set name="link" >
556 `<open xslt script`>
557 <xsl:template match="link" >
558 <xsl:text disable-output-escaping="yes">&lt;link</xsl:text>
559 <xsl:apply-templates select="@*" mode="attrs" />
560 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
561 </xsl:template>
562 `<copy attributes`>
563 `<close xslt script`>
564 </set>
565 <xslt name="." xml="." xsl="link" />
566 </script>
567 >>>
568
569
570
571
572 \<empty html element script\><<<
573 <script element="param" >
574 <set name="param" >
575 `<open xslt script`>
576 <xsl:template match="param" >
577 <xsl:text disable-output-escaping="yes">&lt;param</xsl:text>
578 <xsl:apply-templates select="@*" mode="attrs" />
579 <xsl:text disable-output-escaping="yes">/&gt;</xsl:text>
580 </xsl:template>
581 `<copy attributes`>
582 `<close xslt script`>
583 </set>
584 <xslt name="." xml="." xsl="param" />
585 </script>
586 >>>
587
588
589
590
591
592
593
594
595
596
597 \<copy attributes\><<<
598 <xsl:template match="@*" mode="attrs" >
599 <xsl:text> </xsl:text>
600 <xsl:value-of select="name()" />
601 <xsl:text>="</xsl:text>
602 <xsl:value-of select="." />
603 <xsl:text>"</xsl:text>
604 </xsl:template>
605 >>>
606
607
608
609
610 %%%%%%%%%%%%%%%%%%
611 \section{Shared}
612 %%%%%%%%%%%%%%%%%%
613
614
615
616 \<open xslt script\><<<
617 <![CDATA[
618 <xsl:stylesheet version="1.0"
619 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
620 >
621 <xsl:output omit-xml-declaration = "yes" method="xml" />
622 >>>
623
624 \<close xslt script\><<<
625 <xsl:template match="*|@*|text()|comment()" >
626 <xsl:copy>
627 <xsl:apply-templates select="*|@*|text()|comment()" />
628 </xsl:copy>
629 </xsl:template>
630 </xsl:stylesheet>
631 ]]>
632 >>>
633
634
635
636
637 \ifdojava
638 \AtEndDocument{\Needs{%
639 "pushd \XTPIPES || exit 1
640 ;
641 jar cf tex4ht.jar *
642 ;
643 popd
644 ;
645 if [ ! -d \TEXMFTEXivBIN\space]; then exit 1; fi
646 ;
647 mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN
648 ;
649 if [ ! -d \TEXMFTEXivXTPIPES\space]; then exit 1; fi
650 ;
651 cp \XTPIPES xtpipes/lib/*
652 \TEXMFTEXivXTPIPES
653 "}}
654 \fi
655
656
657 %%%%%%%%%%%%%%%%%%%%%%%%%%%%
658 \end{document}
659 %%%%%%%%%%%%%%%%%%%%%%%%%%%%