1:
2: # The LearningOnline Network with CAPA
3: # Tags Default Definition Module
4: #
5: # $Id: londefdef.pm,v 1.47 2002/03/06 20:27:00 matthew Exp $
6: #
7: #
8: # Copyright Michigan State University Board of Trustees
9: #
10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
11: #
12: # LON-CAPA is free software; you can redistribute it and/or modify
13: # it under the terms of the GNU General Public License as published by
14: # the Free Software Foundation; either version 2 of the License, or
15: # (at your option) any later version.
16: #
17: # LON-CAPA is distributed in the hope that it will be useful,
18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20: # GNU General Public License for more details.
21: #
22: # You should have received a copy of the GNU General Public License
23: # along with LON-CAPA; if not, write to the Free Software
24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25: #
26: # /home/httpd/html/adm/gpl.txt
27: #
28: # http://www.lon-capa.org/
29: #
30: # Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
31: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
32: # binary executable programs or libraries distributed by the
33: # Michigan State University (the "Licensee"), but any binaries so
34: # distributed are hereby licensed only for use in the context
35: # of a program or computational system for which the Licensee is the
36: # primary author or distributor, and which performs substantial
37: # additional tasks beyond the translation of (La)TeX into HTML.
38: # The C source of the Code may not be distributed by the Licensee
39: # to any other parties under any circumstances.
40: #
41: #
42: # last modified 06/26/00 by Alexander Sakharuk
43: # 11/6,11/30,02/01/01,5/4 Gerd Kortemeyer
44: # 01/18 Alex Sakharuk
45:
46: package Apache::londefdef;
47:
48: use strict;
49: use Apache::lonxml;
50:
51: BEGIN {
52:
53: &Apache::lonxml::register('Apache::londefdef',('m','html','head','map','select','option','input','textarea','form','meta','title','body','center','b','strong','table','dt','h1','h2','h3','h4','h5','h6','cite','i','address','dd','dl','dir','ol','ul','menu','dfn','kbd','tt','code','em','q','p','br','big','small','basefont','font','s','sub','strike','sup','hr','a','li','u','output','param','applet','img','embed','tr','td','allow','frameset','pre','insert'));
54:
55: }
56:
57: #======================= TAG SUBROUTINES =====================
58: #-- <output>
59: sub start_output {
60: my ($target) = @_;
61: if ($target eq 'meta') { $Apache::lonxml::metamode--; }
62: return '';
63: }
64: sub end_output {
65: my ($target) = @_;
66: if ($target eq 'meta') { $Apache::lonxml::metamode++; }
67: return '';
68: }
69: #-- <m> tag
70: sub start_m {
71: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
72: my $currentstring = '';
73: if ($target eq 'web') {
74: my $inside = &Apache::lonxml::get_all_text("/m",$$parser[-1]);
75: $inside ='\\documentstyle{article}'.$inside;
76: &Apache::lonxml::debug("M is starting with:$inside:");
77: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
78: if ($eval eq 'on') {
79: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
80: #&Apache::lonxml::debug("M is evaulated to:$inside:");
81: }
82: $currentstring = &Apache::lontexconvert::converted(\$inside);
83: if ($Apache::lontexconvert::errorstring) {
84: &Apache::lonxml::warning("tth error: ".
85: $Apache::lontexconvert::errorstring);
86: $Apache::lontexconvert::errorstring='';
87: }
88: #&Apache::lonxml::debug("M is ends with:$currentstring:");
89: } elsif ($target eq 'tex') {
90: $currentstring = "";
91: }
92: return $currentstring;
93: }
94: sub end_m {
95: my ($target,$token) = @_;
96: my $currentstring = '';
97: if ($target eq 'web') {
98: } elsif ($target eq 'tex') {
99: $currentstring = "";
100: } elsif ($target eq 'meta') {
101: }
102: return $currentstring;
103: }
104: #-- <html> tag
105: sub start_html {
106: my ($target,$token) = @_;
107: my $currentstring = '';
108: if ($ENV{'browser.mathml'}) {
109: &tth::ttminit();
110: } else {
111: &tth::tthinit();
112: }
113: if ($target eq 'web') {
114: $currentstring = &Apache::lonxml::xmlbegin().
115: &Apache::lonxml::fontsettings();
116: } elsif ($target eq 'tex') {
117: $currentstring .= '\documentclass[letterpaper]{article}
118: \setlength{\oddsidemargin}{-40pt}
119: \setlength{\evensidemargin}{-60pt}
120: \setlength{\topmargin}{200pt}
121: \setlength{\textwidth}{4.4in}
122: \setlength{\textheight}{6.8in}
123: \setlength{\parindent}{20pt}
124: \setlength{\marginparwidth}{90pt}
125: \setlength{\textfloatsep}{8pt plus 2.0pt minus 4.0pt}
126: \newcommand{\keephidden}[1]{}
127: \usepackage[dvips]{graphicx}
128: \usepackage{epsfig}';
129: }
130: return $currentstring;
131: }
132: sub end_html {
133: my ($target,$token) = @_;
134: my $currentstring = '';
135: if ($target eq 'web') {
136: $currentstring = &Apache::lonxml::xmlend();
137: }
138: return $currentstring;
139: }
140: #-- <head> tag
141: sub start_head {
142: my ($target,$token) = @_;
143: my $currentstring = '';
144: if ($target eq 'web') {
145: $currentstring = $token->[4];
146: }
147: return $currentstring;
148: }
149: sub end_head {
150: my ($target,$token) = @_;
151: my $currentstring = '';
152: if ($target eq 'web') {
153: $currentstring = &Apache::lonxml::registerurl(undef,$target).
154: $token->[2];
155: }
156: return $currentstring;
157: }
158: #-- <map> tag
159: sub start_map {
160: my ($target,$token) = @_;
161: my $currentstring = '';
162: if ($target eq 'web') {
163: $currentstring = $token->[4];
164: }
165: return $currentstring;
166: }
167: sub end_map {
168: my ($target,$token) = @_;
169: my $currentstring = '';
170: if ($target eq 'web') {
171: $currentstring = $token->[2];
172: }
173: return $currentstring;
174: }
175: #-- <select> tag
176: sub start_select {
177: my ($target,$token) = @_;
178: my $currentstring = '';
179: if ($target eq 'web') {
180: $currentstring = $token->[4];
181: }
182: return $currentstring;
183: }
184: sub end_select {
185: my ($target,$token) = @_;
186: my $currentstring = '';
187: if ($target eq 'web') {
188: $currentstring = $token->[2];
189: }
190: return $currentstring;
191: }
192: #-- <option> tag
193: sub start_option {
194: my ($target,$token) = @_;
195: my $currentstring = '';
196: if ($target eq 'web') {
197: $currentstring = $token->[4];
198: }
199: return $currentstring;
200: }
201: sub end_option {
202: my ($target,$token) = @_;
203: my $currentstring = '';
204: if ($target eq 'web') {
205: $currentstring = $token->[2];
206: }
207: return $currentstring;
208: }
209: #-- <input> tag
210: sub start_input {
211: my ($target,$token) = @_;
212: my $currentstring = '';
213: if ($target eq 'web') {
214: $currentstring = $token->[4];
215: }
216: return $currentstring;
217: }
218: sub end_input {
219: my ($target,$token) = @_;
220: my $currentstring = '';
221: if ($target eq 'web') {
222: $currentstring = $token->[2];
223: }
224: return $currentstring;
225: }
226: #-- <textarea> tag
227: sub start_textarea {
228: my ($target,$token) = @_;
229: my $currentstring = '';
230: if ($target eq 'web') {
231: $currentstring = $token->[4];
232: }
233: return $currentstring;
234: }
235: sub end_textarea {
236: my ($target,$token) = @_;
237: my $currentstring = '';
238: if ($target eq 'web') {
239: $currentstring = $token->[2];
240: }
241: return $currentstring;
242: }
243: #-- <form> tag
244: sub start_form {
245: my ($target,$token) = @_;
246: my $currentstring = '';
247: if ($target eq 'web') {
248: $currentstring = $token->[4];
249: }
250: return $currentstring;
251: }
252: sub end_form {
253: my ($target,$token) = @_;
254: my $currentstring = '';
255: if ($target eq 'web') {
256: $currentstring = $token->[2];
257: }
258: return $currentstring;
259: }
260: #-- <title> tag
261: sub start_title {
262: my ($target,$token) = @_;
263: my $currentstring = '';
264: if ($target eq 'web') {
265: $currentstring = $token->[4];
266: } elsif ($target eq 'tex') {
267: $currentstring .= '\keephidden{'
268: }
269: if ($target eq 'meta') {
270: $currentstring='<title>';
271: &start_output();
272: }
273: return $currentstring;
274: }
275: sub end_title {
276: my ($target,$token) = @_;
277: my $currentstring = '';
278: if ($target eq 'web') {
279: $currentstring = $token->[2];
280: } elsif ($target eq 'tex') {
281: $currentstring .= '}';
282: }
283: if ($target eq 'meta') {
284: &end_output();
285: $currentstring='</title>';
286: }
287: return $currentstring;
288: }
289: #-- <meta> tag
290: sub start_meta {
291: my ($target,$token,$tagstack,$parstack,$parser) = @_;
292: my $currentstring = '';
293: if ($target eq 'web') {
294: my $args='';
295: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
296: if ($args eq '') {
297: &Apache::lonxml::get_all_text("/meta",$$parser[$#$parser]);
298: } else {
299: $currentstring = $token->[4];
300: }
301: }
302: if ($target eq 'meta') {
303: unless ($token->[2]->{'http-equiv'}) {
304: my $name=$token->[2]->{'name'};
305: $name=~tr/A-Z/a-z/;
306: $name=~s/\s/\_/g;
307: if ($name) {
308: $currentstring='<'.$name.'>'.
309: $token->[2]->{'content'}.
310: '</'.$name.'>';
311: }
312: }
313: }
314: return $currentstring;
315: }
316: sub end_meta {
317: my ($target,$token,$tagstack,$parstack,$parser) = @_;
318: my $currentstring = '';
319: if ($target eq 'web') {
320: my $args='';
321: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
322: if ($args ne '') {
323: $currentstring = $token->[4];
324: }
325: }
326: return $currentstring;
327: }
328: #-- <body> tag
329: sub start_body {
330: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
331: # my ($target,$token) = @_;
332: my $currentstring = '';
333: if ($target eq 'web') {
334: if (!$Apache::lonxml::registered) {
335: $currentstring.='<head>'.
336: &Apache::lonxml::registerurl(undef,$target).'</head>';
337: }
338: my $onLoad='';
339: foreach my $key (keys(%{$token->[2]})) {
340: if ($key =~ /^onload$/i) {
341: $onLoad.=$token->[2]->{$key}.';';
342: delete($token->[2]->{$key});
343: }
344: }
345: $token->[2]->{'onLoad'}=$onLoad.&Apache::lonxml::loadevents();
346: my $onUnload='';
347: foreach my $key (keys(%{$token->[2]})) {
348: if ($key =~ /^onunload$/i) {
349: $onUnload.=$token->[2]->{$key}.';';
350: delete($token->[2]->{$key});
351: }
352: }
353: $token->[2]->{'onUnload'}=$onUnload.
354: &Apache::lonxml::unloadevents();
355:
356: $currentstring .= '<'.$token->[1];
357: foreach (keys %{$token->[2]}) {
358: $currentstring.=' '.$_.'="'.$token->[2]->{$_}.'"';
359: }
360: $currentstring.='>';
361: if ($ENV{'request.state'} ne 'published') {
362: $currentstring.=(<<EDITBUTTON);
363: <form method="post">
364: <input type="submit" name="showmode" value="Edit" />
365: </form>
366: EDITBUTTON
367: }
368: } elsif ($target eq 'tex') {
369: $currentstring = '\begin{document}';
370: }
371: return $currentstring;
372: }
373: sub end_body {
374: my ($target,$token) = @_;
375: my $currentstring = '';
376: if ($target eq 'web') {
377: $currentstring = $token->[2];
378: } elsif ($target eq 'tex') {
379: $currentstring = '\end{document}';
380: }
381: return $currentstring;
382: }
383: #-- <center> tag
384: sub start_center {
385: my ($target,$token) = @_;
386: my $currentstring = '';
387: if ($target eq 'web') {
388: $currentstring = $token->[4];
389: } elsif ($target eq 'tex') {
390: $currentstring = '\begin{center}';
391: } elsif ($target eq 'latexsource') {
392: $currentstring = '\begin{center}';
393: }
394: return $currentstring;
395: }
396: sub end_center {
397: my ($target,$token) = @_;
398: my $currentstring = '';
399: if ($target eq 'web') {
400: $currentstring = $token->[2];
401: } elsif ($target eq 'tex') {
402: $currentstring = '\end{center}';
403: } elsif ($target eq 'latexsource') {
404: $currentstring = '\end{center}';
405: }
406: return $currentstring;
407: }
408: #-- <b> tag
409: sub start_b {
410: my ($target,$token) = @_;
411: my $currentstring = '';
412: if ($target eq 'web') {
413: $currentstring = $token->[4];
414: } elsif ($target eq 'tex') {
415: $currentstring = '\textbf{';
416: } elsif ($target eq 'latexsource') {
417: $currentstring = '\textbf{';
418: }
419: return $currentstring;
420: }
421: sub end_b {
422: my ($target,$token) = @_;
423: my $currentstring = '';
424: if ($target eq 'web') {
425: $currentstring = $token->[2];
426: } elsif ($target eq 'tex') {
427: $currentstring = '}';
428:
429: } elsif ($target eq 'latexsource') {
430: $currentstring = '}';
431: }
432: return $currentstring;
433: }
434: #-- <strong> tag
435: sub start_strong {
436: my ($target,$token) = @_;
437: my $currentstring = '';
438: if ($target eq 'web') {
439: $currentstring = $token->[4];
440: } elsif ($target eq 'tex') {
441: $currentstring = '\textbf{';
442: } elsif ($target eq 'latexsource') {
443: $currentstring = '\textbf{';
444: }
445: return $currentstring;
446: }
447: sub end_strong {
448: my ($target,$token) = @_;
449: my $currentstring = '';
450: if ($target eq 'web') {
451:
452: $currentstring = $token->[2];
453: } elsif ($target eq 'tex') {
454: $currentstring = '}';
455: } elsif ($target eq 'latexsource') {
456: $currentstring = '}';
457: }
458: return $currentstring;
459: }
460: #-- <h1> tag
461: sub start_h1 {
462: my ($target,$token) = @_;
463: my $currentstring = '';
464: if ($target eq 'web') {
465: $currentstring .= $token->[4];
466: } elsif ($target eq 'tex') {
467: $currentstring .= '\large{\textbf{';
468: } elsif ($target eq 'meta') {
469: $currentstring='<subject>';
470: &start_output();
471: }
472: return $currentstring;
473: }
474: sub end_h1 {
475: my ($target,$token) = @_;
476: my $currentstring = '';
477: if ($target eq 'web') {
478: $currentstring .= $token->[2];
479: } elsif ($target eq 'tex') {
480: $currentstring .= '}}';
481: } elsif ($target eq 'meta') {
482: &end_output();
483: $currentstring='</subject>';
484: }
485: return $currentstring;
486: }
487: #-- <h2> tag
488: sub start_h2 {
489: my ($target,$token) = @_;
490: my $currentstring = '';
491: if ($target eq 'web') {
492: $currentstring .= $token->[4];
493: } elsif ($target eq 'tex') {
494: $currentstring .= '\large{\textbf{';
495: }
496: return $currentstring;
497: }
498: sub end_h2 {
499: my ($target,$token) = @_;
500: my $currentstring = '';
501: if ($target eq 'web') {
502: $currentstring .= $token->[2];
503: } elsif ($target eq 'tex') {
504: $currentstring .= '}}';
505: }
506: return $currentstring;
507: }
508: #-- <h3> tag
509: sub start_h3 {
510: my ($target,$token) = @_;
511: my $currentstring = '';
512: if ($target eq 'web') {
513: $currentstring .= $token->[4];
514: } elsif ($target eq 'tex') {
515: $currentstring .= '\large{\textbf{';
516: }
517: return $currentstring;
518: }
519: sub end_h3 {
520: my ($target,$token) = @_;
521: my $currentstring = '';
522: if ($target eq 'web') {
523: $currentstring .= $token->[2];
524: } elsif ($target eq 'tex') {
525: $currentstring .= '}}';
526: }
527: return $currentstring;
528: }
529: #-- <h4> tag
530: sub start_h4 {
531: my ($target,$token) = @_;
532: my $currentstring = '';
533: if ($target eq 'web') {
534: $currentstring .= $token->[4];
535: } elsif ($target eq 'tex') {
536: $currentstring .= '\large{\textbf{';
537: }
538: return $currentstring;
539: }
540: sub end_h4 {
541: my ($target,$token) = @_;
542: my $currentstring = '';
543: if ($target eq 'web') {
544: $currentstring .= $token->[2];
545: } elsif ($target eq 'tex') {
546: $currentstring .= '}}';
547: }
548: return $currentstring;
549: }
550: #-- <h5> tag
551: sub start_h5 {
552: my ($target,$token) = @_;
553: my $currentstring = '';
554: if ($target eq 'web') {
555: $currentstring .= $token->[4];
556: } elsif ($target eq 'tex') {
557: $currentstring .= '\large{\textbf{';
558: }
559: return $currentstring;
560: }
561: sub end_h5 {
562: my ($target,$token) = @_;
563: my $currentstring = '';
564: if ($target eq 'web') {
565: $currentstring .= $token->[2];
566: } elsif ($target eq 'tex') {
567: $currentstring .= '}}';
568: }
569: return $currentstring;
570: }
571: #-- <h6> tag
572: sub start_h6 {
573: my ($target,$token) = @_;
574: my $currentstring = '';
575: if ($target eq 'web') {
576: $currentstring .= $token->[4];
577: } elsif ($target eq 'tex') {
578: $currentstring .= '\large{\textbf{';
579: }
580: return $currentstring;
581: }
582: sub end_h6 {
583: my ($target,$token) = @_;
584: my $currentstring = '';
585: if ($target eq 'web') {
586: $currentstring .= $token->[2];
587: } elsif ($target eq 'tex') {
588: $currentstring .= '}}';
589: }
590: return $currentstring;
591: }
592: #--- <cite> tag
593: sub start_cite {
594: my ($target,$token) = @_;
595: my $currentstring = '';
596: if ($target eq 'web') {
597: $currentstring .= $token->[4];
598: } elsif ($target eq 'tex') {
599: $currentstring .= "\\textit{";
600: } elsif ($target eq 'latexsource') {
601: $currentstring .= "\\textit{";
602: }
603: return $currentstring;
604: }
605: sub end_cite {
606: my ($target,$token) = @_;
607: my $currentstring = '';
608: if ($target eq 'web') {
609: $currentstring .= $token->[2];
610: } elsif ($target eq 'tex') {
611: $currentstring .= "}";
612: } elsif ($target eq 'latexsource') {
613: $currentstring .= "}";
614: }
615: return $currentstring;
616: }
617: #-- <i> tag
618: sub start_i {
619: my ($target,$token) = @_;
620: my $currentstring = '';
621: if ($target eq 'web') {
622: $currentstring .= $token->[4];
623: } elsif ($target eq 'tex') {
624: $currentstring .= '\textit{';
625: } elsif ($target eq 'latexsource') {
626: $currentstring .= '\textit{';
627: }
628: return $currentstring;
629: }
630: sub end_i {
631: my ($target,$token) = @_;
632: my $currentstring = '';
633: if ($target eq 'web') {
634: $currentstring .= $token->[2];
635: } elsif ($target eq 'tex') {
636: $currentstring .= '}';
637: } elsif ($target eq 'latexsource') {
638: $currentstring .= '}';
639: }
640: return $currentstring;
641: }
642: #-- <address> tag
643: sub start_address {
644: my ($target,$token) = @_;
645: my $currentstring = '';
646: if ($target eq 'web') {
647: $currentstring .= $token->[4];
648: } elsif ($target eq 'tex') {
649: $currentstring .= "\\textit{";
650: } elsif ($target eq 'latexsource') {
651: $currentstring .= "\\textit{";
652: }
653: return $currentstring;
654: }
655: sub end_address {
656: my ($target,$token) = @_;
657: my $currentstring = '';
658: if ($target eq 'web') {
659: $currentstring .= $token->[2];
660: } elsif ($target eq 'tex') {
661: $currentstring .= "}";
662: } elsif ($target eq 'latexsource') {
663: $currentstring .= "}";
664: }
665: return $currentstring;
666: }
667: #-- <dfn> tag
668: sub start_dfn {
669: my ($target,$token) = @_;
670: my $currentstring = '';
671: if ($target eq 'web') {
672: $currentstring .= $token->[4];
673: } elsif ($target eq 'tex') {
674: $currentstring .= "\\textit{";
675: } elsif ($target eq 'latexsource') {
676: $currentstring .= "\\textit{";
677: }
678: return $currentstring;
679: }
680: sub end_dfn {
681: my ($target,$token) = @_;
682: my $currentstring = '';
683: if ($target eq 'web') {
684: $currentstring .= $token->[2];
685: } elsif ($target eq 'tex') {
686: $currentstring .= "}";
687: } elsif ($target eq 'latexsource') {
688: $currentstring .= "}";
689: }
690: return $currentstring;
691: }
692: #-- <tt> tag
693: sub start_tt {
694: my ($target,$token) = @_;
695: my $currentstring = '';
696: if ($target eq 'web') {
697: $currentstring .= $token->[4];
698: } elsif ($target eq 'tex') {
699: $currentstring .= '\texttt{';
700: } elsif ($target eq 'latexsource') {
701: $currentstring .= '\texttt{';
702: }
703: return $currentstring;
704: }
705: sub end_tt {
706: my ($target,$token) = @_;
707: my $currentstring = '';
708: if ($target eq 'web') {
709: $currentstring .= $token->[2];
710: } elsif ($target eq 'tex') {
711: $currentstring .= '}';
712: } elsif ($target eq 'latexsource') {
713: $currentstring .= '}';
714: }
715: return $currentstring;
716: }
717: #-- <kbd> tag
718: sub start_kbd {
719: my ($target,$token) = @_;
720: my $currentstring = '';
721: if ($target eq 'web') {
722: $currentstring .= $token->[4];
723: } elsif ($target eq 'tex') {
724: $currentstring .= "\\texttt";
725: } elsif ($target eq 'latexsource') {
726: $currentstring .= "\\texttt{";
727: }
728: return $currentstring;
729: }
730: sub end_kbd {
731: my ($target,$token) = @_;
732: my $currentstring = '';
733: if ($target eq 'web') {
734: $currentstring .= $token->[2];
735: } elsif ($target eq 'tex') {
736: $currentstring .= "}";
737: } elsif ($target eq 'latexsource') {
738: $currentstring .= "}";
739: }
740: return $currentstring;
741: }
742: #-- <code> tag
743: sub start_code {
744: my ($target,$token) = @_;
745: my $currentstring = '';
746: if ($target eq 'web') {
747: $currentstring .= $token->[4];
748: } elsif ($target eq 'tex') {
749: $currentstring .= '\texttt{';
750: }
751: return $currentstring;
752: }
753: sub end_code {
754: my ($target,$token) = @_;
755: my $currentstring = '';
756: if ($target eq 'web') {
757: $currentstring .= $token->[2];
758: } elsif ($target eq 'tex') {
759: $currentstring .= '}';
760: }
761: return $currentstring;
762: }
763: #-- <em> tag
764: sub start_em {
765: my ($target,$token) = @_;
766: my $currentstring = '';
767: if ($target eq 'web') {
768: $currentstring .= $token->[4];
769: } elsif ($target eq 'tex') {
770: $currentstring .= '\emph{';
771: } elsif ($target eq 'latexsource') {
772: $currentstring .= '\emph{';
773: }
774: return $currentstring;
775: }
776: sub end_em {
777: my ($target,$token) = @_;
778: my $currentstring = '';
779: if ($target eq 'web') {
780: $currentstring .= $token->[2];
781: } elsif ($target eq 'tex') {
782: $currentstring .= '}';
783: } elsif ($target eq 'latexsource') {
784: $currentstring .= '}';
785: }
786: return $currentstring;
787: }
788: #-- <q> tag
789: sub start_q {
790: my ($target,$token) = @_;
791: my $currentstring = '';
792: if ($target eq 'web') {
793: $currentstring .= $token->[4];
794: } elsif ($target eq 'tex') {
795: $currentstring .= "\\emph{";
796: } elsif ($target eq 'latexsource') {
797: $currentstring .= "\\emph{";
798: }
799: return $currentstring;
800: }
801: sub end_q {
802: my ($target,$token) = @_;
803: my $currentstring = '';
804: if ($target eq 'web') {
805: $currentstring .= $token->[2];
806: } elsif ($target eq 'tex') {
807: $currentstring .= "}";
808: } elsif ($target eq 'latexsource') {
809: $currentstring .= "}";
810: }
811: return $currentstring;
812: }
813: #-- <p> tag
814: sub start_p {
815: my ($target,$token) = @_;
816: my $currentstring = '';
817: if ($target eq 'web') {
818: $currentstring .= $token->[4];
819: } elsif ($target eq 'tex') {
820: $currentstring .= '{\par ';
821: } elsif ($target eq 'latexsource') {
822: $currentstring .= '{\par ';
823: }
824: return $currentstring;
825: }
826: sub end_p {
827: my ($target,$token) = @_;
828: my $currentstring = '';
829: if ($target eq 'web') {
830: $currentstring .= $token->[2];
831: } elsif ($target eq 'tex') {
832: $currentstring .= '}';
833: } elsif ($target eq 'latexsource') {
834: $currentstring .= '}';
835: }
836: return $currentstring;
837: }
838: #-- <br> tag
839: sub start_br {
840: my ($target,$token) = @_;
841: my $currentstring = '';
842: if ($target eq 'web') {
843: $currentstring .= $token->[4];
844: } elsif ($target eq 'tex') {
845: $currentstring .= '\\\\';
846: } elsif ($target eq 'latexsource') {
847: $currentstring .= '\\';
848: }
849: return $currentstring;
850: }
851: sub end_br {
852: my ($target,$token) = @_;
853: my $currentstring = '';
854: if ($target eq 'web') {
855: $currentstring .= $token->[2];
856: }
857: return $currentstring;
858: }
859: #-- <big> tag
860: sub start_big {
861: my ($target,$token) = @_;
862: my $currentstring = '';
863: if ($target eq 'web') {
864: $currentstring .= $token->[4];
865: } elsif ($target eq 'tex') {
866: $currentstring .= '\large{';
867: } elsif ($target eq 'latexsource') {
868: $currentstring .= '{\Large ';
869: }
870: return $currentstring;
871: }
872: sub end_big {
873: my ($target,$token) = @_;
874: my $currentstring = '';
875: if ($target eq 'web') {
876: $currentstring .= $token->[2];
877: } elsif ($target eq 'tex') {
878: $currentstring .= '}';
879: } elsif ($target eq 'latexsource') {
880: $currentstring .= '}';
881: }
882: return $currentstring;
883: }
884: #-- <small> tag
885: sub start_small {
886: my ($target,$token) = @_;
887: my $currentstring = '';
888: if ($target eq 'web') {
889: $currentstring .= $token->[4];
890: } elsif ($target eq 'tex') {
891: $currentstring .= '{\footnotesize ';
892: } elsif ($target eq 'latexsource') {
893: $currentstring .= '{\footnotesize ';
894: }
895: return $currentstring;
896: }
897: sub end_small {
898: my ($target,$token) = @_;
899: my $currentstring = '';
900: if ($target eq 'web') {
901: $currentstring .= $token->[2];
902: } elsif ($target eq 'tex') {
903: $currentstring .= '}';
904: } elsif ($target eq 'latexsource') {
905: $currentstring .= '}';
906: }
907: return $currentstring;
908: }
909: #-- <basefont> tag
910: sub start_basefont {
911: my ($target,$token) = @_;
912: my $currentstring = '';
913: if ($target eq 'web') {
914: $currentstring = $token->[4];
915: }
916: return $currentstring;
917: }
918: sub end_basefont {
919: my ($target,$token) = @_;
920: my $currentstring = '';
921: if ($target eq 'web') {
922: $currentstring = $token->[4];
923: }
924: return $currentstring;
925: }
926: #-- <font> tag
927: sub start_font {
928: my ($target,$token) = @_;
929: my $currentstring = '';
930: if ($target eq 'web') {
931: $currentstring = $token->[4];
932: }
933: return $currentstring;
934: }
935: sub end_font {
936: my ($target,$token) = @_;
937: my $currentstring = '';
938: if ($target eq 'web') {
939: $currentstring = $token->[2];
940: }
941: return $currentstring;
942: }
943: #-- <strike> tag
944: sub start_strike {
945: my ($target,$token) = @_;
946: my $currentstring = '';
947: if ($target eq 'web') {
948: $currentstring .= $token->[4];
949: } elsif ($target eq 'tex') {
950: $currentstring .= "{\\underline ";
951: }
952: return $currentstring;
953: }
954: sub end_strike {
955: my ($target,$token) = @_;
956: my $currentstring = '';
957: if ($target eq 'web') {
958: $currentstring .= $token->[2];
959: } elsif ($target eq 'tex') {
960: $currentstring .= " }";
961: }
962: return $currentstring;
963: }
964: #-- <s> tag
965: sub start_s {
966: my ($target,$token) = @_;
967: my $currentstring = '';
968: if ($target eq 'web') {
969: $currentstring .= $token->[4];
970: } elsif ($target eq 'tex') {
971: $currentstring .= "{\\underline ";
972: }
973: return $currentstring;
974: }
975: sub end_s {
976: my ($target,$token) = @_;
977: my $currentstring = '';
978: if ($target eq 'web') {
979: $currentstring .= $token->[2];
980: } elsif ($target eq 'tex') {
981: $currentstring .= " }";
982: }
983: return $currentstring;
984: }
985: #-- <sub> tag
986: sub start_sub {
987: my ($target,$token) = @_;
988: my $currentstring = '';
989: if ($target eq 'web') {
990: $currentstring .= $token->[4];
991: } elsif ($target eq 'tex') {
992: $currentstring .= "\$_{ ";
993: }
994: return $currentstring;
995: }
996: sub end_sub {
997: my ($target,$token) = @_;
998: my $currentstring = '';
999: if ($target eq 'web') {
1000: $currentstring .= $token->[2];
1001: } elsif ($target eq 'tex') {
1002: $currentstring .= " }\$";
1003: }
1004: return $currentstring;
1005: }
1006: #-- <sup> tag
1007: sub start_sup {
1008: my ($target,$token) = @_;
1009: my $currentstring = '';
1010: if ($target eq 'web') {
1011: $currentstring .= $token->[4];
1012: } elsif ($target eq 'tex') {
1013: $currentstring .= "\$^{ ";
1014: }
1015: return $currentstring;
1016: }
1017: sub end_sup {
1018: my ($target,$token) = @_;
1019: my $currentstring = '';
1020: if ($target eq 'web') {
1021: $currentstring .= $token->[2];
1022: } elsif ($target eq 'tex') {
1023: $currentstring .= " }\$";
1024: }
1025: return $currentstring;
1026: }
1027: #-- <hr> tag
1028: sub start_hr {
1029: my ($target,$token) = @_;
1030: my $currentstring = '';
1031: if ($target eq 'web') {
1032: $currentstring .= $token->[4];
1033: } elsif ($target eq 'tex') {
1034: $currentstring .= "\\hline ";
1035: }
1036: return $currentstring;
1037: }
1038: sub end_hr {
1039: my ($target,$token) = @_;
1040: my $currentstring = '';
1041: if ($target eq 'web') {
1042: $currentstring .= $token->[2];
1043: } elsif ($target eq 'tex') {
1044: }
1045: return $currentstring;
1046: }
1047: #-- <a> tag
1048: sub start_a {
1049: my ($target,$token) = @_;
1050: my $currentstring = '';
1051: if ($target eq 'web') {
1052: $currentstring .= $token->[4];
1053: } elsif ($target eq 'tex') {
1054: }
1055: return $currentstring;
1056: }
1057: sub end_a {
1058: my ($target,$token,$tagstack,$stackref) = @_;
1059: my $currentstring = '';
1060: if ($target eq 'web') {
1061: $currentstring .= $token->[2];
1062: } elsif ($target eq 'tex') {
1063: my $tempor_var = $stackref->[$#$stackref];
1064: if (index($tempor_var,'name') != -1 ) {
1065: $tempor_var =~ s/name=([^,]*),/$1/g;
1066: # $currentstring .= " \\label{$tempor_var}";
1067: } elsif (index($tempor_var,'href') != -1 ) {
1068: $tempor_var =~ s/href=([^,]*),/$1/g;
1069: $currentstring .= " \\ref{$tempor_var}";
1070: }
1071: }
1072: return $currentstring;
1073: }
1074: #-- <li> tag
1075: sub start_li {
1076: my ($target,$token,$tagstack,$stackref) = @_;
1077: my $currentstring = '';
1078: if ($target eq 'web') {
1079: $currentstring = $token->[4];
1080: } elsif ($target eq 'tex') {
1081: my $tempor_var = $stackref->[$#$stackref];
1082: if (index($tempor_var,'circle') != -1 ) {
1083: $currentstring .= " \\item[o] ";
1084: } elsif (index($tempor_var,'square') != -1 ) {
1085: $currentstring .= " \\item[$\Box$] ";
1086: } elsif ($tempor_var ne '') {
1087: $_ = $tempor_var;
1088: m/my\s*([^=]*)=/;
1089: $currentstring .= " \\item[$1] ";
1090: } else {
1091: $currentstring .= " \\item ";
1092: }
1093: }
1094: return $currentstring;
1095: }
1096: sub end_li {
1097: my ($target,$token) = @_;
1098: my $currentstring = '';
1099: if ($target eq 'web') {
1100: $currentstring = $token->[2];
1101: }
1102: return $currentstring;
1103: }
1104: #-- <u> tag
1105: sub start_u {
1106: my ($target,$token) = @_;
1107: my $currentstring = '';
1108: if ($target eq 'web') {
1109: $currentstring .= $token->[4];
1110: } elsif ($target eq 'tex') {
1111: $currentstring .= "{\\underline ";
1112: }
1113: return $currentstring;
1114: }
1115: sub end_u {
1116: my ($target,$token) = @_;
1117: my $currentstring = '';
1118: if ($target eq 'web') {
1119: $currentstring .= $token->[2];
1120: } elsif ($target eq 'tex') {
1121: $currentstring .= " }";
1122: }
1123: return $currentstring;
1124: }
1125: #-- <ul> tag
1126: sub start_ul {
1127: my ($target,$token) = @_;
1128: my $currentstring = '';
1129: if ($target eq 'web') {
1130: $currentstring = $token->[4];
1131: } elsif ($target eq 'tex') {
1132: $currentstring = '\begin{itemize}';
1133: }
1134: return $currentstring;
1135: }
1136: sub end_ul {
1137: my ($target,$token) = @_;
1138: my $currentstring = '';
1139: if ($target eq 'web') {
1140: $currentstring = $token->[2];
1141: } elsif ($target eq 'tex') {
1142: $currentstring = '\end{itemize}';
1143: }
1144: return $currentstring;
1145: }
1146: #-- <menu> tag
1147: sub start_menu {
1148: my ($target,$token) = @_;
1149: my $currentstring = '';
1150: if ($target eq 'web') {
1151: $currentstring = $token->[4];
1152: } elsif ($target eq 'tex') {
1153: $currentstring = " \\begin{itemize} ";
1154: }
1155: return $currentstring;
1156: }
1157: sub end_menu {
1158: my ($target,$token) = @_;
1159: my $currentstring = '';
1160: if ($target eq 'web') {
1161: $currentstring = $token->[2];
1162: } elsif ($target eq 'tex') {
1163: $currentstring = " \\end{itemize}";
1164: }
1165: return $currentstring;
1166: }
1167: #-- <dir> tag
1168: sub start_dir {
1169: my ($target,$token) = @_;
1170: my $currentstring = '';
1171: if ($target eq 'web') {
1172: $currentstring = $token->[4];
1173: } elsif ($target eq 'tex') {
1174: $currentstring = " \\begin{itemize} ";
1175: }
1176: return $currentstring;
1177: }
1178: sub end_dir {
1179: my ($target,$token) = @_;
1180: my $currentstring = '';
1181: if ($target eq 'web') {
1182: $currentstring = $token->[2];
1183: } elsif ($target eq 'tex') {
1184: $currentstring = " \\end{itemize}";
1185: }
1186: return $currentstring;
1187: }
1188: #-- <ol> tag
1189: sub start_ol {
1190: my ($target,$token) = @_;
1191: my $currentstring = '';
1192: if ($target eq 'web') {
1193: $currentstring = $token->[4];
1194: } elsif ($target eq 'tex') {
1195: $currentstring = '\begin{enumerate}';
1196: }
1197: return $currentstring;
1198: }
1199: sub end_ol {
1200: my ($target,$token) = @_;
1201: my $currentstring = '';
1202: if ($target eq 'web') {
1203: $currentstring = $token->[2];
1204: } elsif ($target eq 'tex') {
1205: $currentstring = '\end{enumerate}';
1206: }
1207: return $currentstring;
1208: }
1209: #-- <dl> tag
1210: sub start_dl {
1211: my ($target,$token) = @_;
1212: my $currentstring = '';
1213: if ($target eq 'web') {
1214: $currentstring = $token->[4];
1215: } elsif ($target eq 'tex') {
1216: $currentstring = '\begin{description}';
1217: }
1218: return $currentstring;
1219: }
1220: sub end_dl {
1221: my ($target,$token) = @_;
1222: my $currentstring = '';
1223: if ($target eq 'web') {
1224: $currentstring = $token->[2];
1225: } elsif ($target eq 'tex') {
1226: $currentstring = '\end{description}';
1227: }
1228: return $currentstring;
1229: }
1230: #-- <dt> tag
1231: sub start_dt {
1232: my ($target,$token) = @_;
1233: my $currentstring = '';
1234: if ($target eq 'web') {
1235: $currentstring = $token->[4];
1236: } elsif ($target eq 'tex') {
1237: $currentstring = '\item[';
1238: }
1239: return $currentstring;
1240: }
1241: sub end_dt {
1242: my ($target,$token) = @_;
1243: my $currentstring = '';
1244: if ($target eq 'web') {
1245: $currentstring = $token->[2];
1246: } elsif ($target eq 'tex') {
1247: $currentstring = ']';
1248: }
1249: return $currentstring;
1250: }
1251: #-- <dd> tag
1252: sub start_dd {
1253: my ($target,$token) = @_;
1254: my $currentstring = '';
1255: if ($target eq 'web') {
1256: $currentstring = $token->[4];
1257: }
1258: return $currentstring;
1259: }
1260: sub end_dd {
1261: my ($target,$token) = @_;
1262: my $currentstring = '';
1263: if ($target eq 'web') {
1264: $currentstring = $token->[2];
1265: }
1266: return $currentstring;
1267: }
1268: #-- <table> tag
1269: sub start_table {
1270: my ($target,$token) = @_;
1271: my $currentstring = '';
1272: if ($target eq 'web') {
1273: $currentstring = $token->[4];
1274: } elsif ($target eq 'tex') {
1275: $currentstring = '';
1276: }
1277: return $currentstring;
1278: }
1279: sub end_table {
1280: my ($target,$token) = @_;
1281: my $currentstring = '';
1282: if ($target eq 'web') {
1283: $currentstring = $token->[2];
1284: } elsif ($target eq 'tex') {
1285: $currentstring = '';
1286: }
1287: return $currentstring;
1288: }
1289: #-- <tr> tag
1290: sub start_tr {
1291: my ($target,$token) = @_;
1292: my $currentstring = '';
1293: if ($target eq 'web') {
1294: $currentstring = $token->[4];
1295: } elsif ($target eq 'tex') {
1296: $currentstring = '';
1297: }
1298: return $currentstring;
1299: }
1300: sub end_tr {
1301: my ($target,$token) = @_;
1302: my $currentstring = '';
1303: if ($target eq 'web') {
1304: $currentstring = $token->[2];
1305: } elsif ($target eq 'tex') {
1306: $currentstring = '';
1307: }
1308: return $currentstring;
1309: }
1310: #-- <td> tag
1311: sub start_td {
1312: my ($target,$token) = @_;
1313: my $currentstring = '';
1314: if ($target eq 'web') {
1315: $currentstring = $token->[4];
1316: } elsif ($target eq 'tex') {
1317: $currentstring = '';
1318: }
1319: return $currentstring;
1320: }
1321: sub end_td {
1322: my ($target,$token) = @_;
1323: my $currentstring = '';
1324: if ($target eq 'web') {
1325: $currentstring = $token->[2];
1326: } elsif ($target eq 'tex') {
1327: $currentstring = '';
1328: }
1329: return $currentstring;
1330: }
1331: #-- <img> tag
1332: sub start_img {
1333: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1334: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1335: $token->[2]->{'src'};
1336: my $currentstring = '';
1337:
1338: if ($target eq 'web') {
1339: $currentstring = $token->[4];
1340: } elsif ($target eq 'tex') {
1341: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval);
1342: my $file;
1343: my $path;
1344: if ($src =~ m!(.*)/([^/]*)$!) {
1345: $file = $2;
1346: $path = $1;
1347: if ($path=~m:^/:) {
1348: $path = '/home/httpd/html'.$path;
1349: } elsif ($path =~ /^\./) {
1350: $path = $Apache::lonxml::pwd[-1].'/'.$path;
1351: } else {
1352: #else it is a full url don't print
1353: $path = undef;
1354: }
1355: } else {
1356: $path = $Apache::lonxml::pwd[-1];
1357: $file = $src;
1358: }
1359: $file=~s/(\.gif|\.jpg)$/\.eps/;
1360: if ($path) {
1361: $currentstring = '\graphicspath{{'.$path.'}}\fbox{\includegraphics{'.$file.'}}';
1362: } else {
1363: $currentstring = 'See the image at \tt{'.$src.'}';
1364: }
1365: }
1366: return $currentstring;
1367: }
1368: sub end_img {
1369: my ($target,$token) = @_;
1370: my $currentstring = '';
1371: if ($target eq 'web') {
1372: $currentstring = $token->[2];
1373: } elsif ($target eq 'tex') {
1374: $currentstring = '';
1375: }
1376: return $currentstring;
1377: }
1378: #-- <applet> tag
1379:
1380: sub start_applet {
1381: my ($target,$token) = @_;
1382: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1383: $token->[2]->{'code'};
1384: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1385: $token->[2]->{'archive'};
1386: my $currentstring = '';
1387: if ($target eq 'web') {
1388: $currentstring = $token->[4];
1389: } elsif ($target eq 'tex') {
1390: $currentstring = " \\begin{figure} ";
1391: }
1392: return $currentstring;
1393: }
1394: sub end_applet {
1395: my ($target,$token) = @_;
1396: my $currentstring = '';
1397: if ($target eq 'web') {
1398: $currentstring = $token->[2];
1399: } elsif ($target eq 'tex') {
1400: $currentstring = " \\end{figure}";
1401: }
1402: return $currentstring;
1403: }
1404:
1405: #-- <embed> tag
1406:
1407: sub start_embed {
1408: my ($target,$token) = @_;
1409: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1410: $token->[2]->{'src'};
1411: my $currentstring = '';
1412: if ($target eq 'web') {
1413: $currentstring = $token->[4];
1414: } elsif ($target eq 'tex') {
1415: $currentstring = " \\begin{figure} ";
1416: }
1417: return $currentstring;
1418: }
1419: sub end_embed {
1420: my ($target,$token) = @_;
1421: my $currentstring = '';
1422: if ($target eq 'web') {
1423: $currentstring = $token->[2];
1424: } elsif ($target eq 'tex') {
1425: $currentstring = " \\end{figure}";
1426: }
1427: return $currentstring;
1428: }
1429:
1430: #-- <param> tag
1431:
1432: sub start_param {
1433: my ($target,$token) = @_;
1434: if ($token->[2]->{'name'} eq 'cabbase') {
1435: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1436: $token->[2]->{'value'};
1437: }
1438: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1439: $token->[2]->{'src'};
1440: my $currentstring = '';
1441: if ($target eq 'web') {
1442: $currentstring = $token->[4];
1443: } elsif ($target eq 'tex') {
1444: $currentstring = " \\begin{figure} ";
1445: }
1446: return $currentstring;
1447: }
1448: sub end_param {
1449: my ($target,$token) = @_;
1450: my $currentstring = '';
1451: if ($target eq 'web') {
1452: $currentstring = $token->[2];
1453: } elsif ($target eq 'tex') {
1454: $currentstring = " \\end{figure}";
1455: }
1456: return $currentstring;
1457: }
1458:
1459: #-- <allow> tag
1460:
1461: sub start_allow {
1462: my ($target,$token) = @_;
1463:
1464: $Apache::lonxml::extlinks[$#Apache::lonxml::extlinks+1]=
1465: $token->[2]->{'src'};
1466:
1467: return '';
1468: }
1469: sub end_allow {
1470: return '';
1471: }
1472: #-- Frames
1473: sub start_frameset {
1474: my ($target,$token) = @_;
1475: my $currentstring = '';
1476: if ($target eq 'web') {
1477: if (!$Apache::lonxml::registered) {
1478: $currentstring.='<head>'.
1479: &Apache::lonxml::registerurl(undef,$target).'</head>';
1480: }
1481: $currentstring .= $token->[4];
1482: }
1483: return $currentstring;
1484: }
1485: sub end_frameset {
1486: my ($target,$token) = @_;
1487: my $currentstring = '';
1488: if ($target eq 'web') {
1489: $currentstring = $token->[2];
1490: }
1491: return $currentstring;
1492: }
1493: #-- <pre>
1494: sub start_pre {
1495: my ($target,$token) = @_;
1496: my $currentstring = '';
1497: if ($target eq 'web') {
1498: $currentstring .= $token->[4];
1499: } elsif ($target eq 'tex') {
1500: $currentstring .= '\begin{verbatim}';
1501: }
1502: return $currentstring;
1503: }
1504: sub end_pre {
1505: my ($target,$token) = @_;
1506: my $currentstring = '';
1507: if ($target eq 'web') {
1508: $currentstring .= $token->[2];
1509: } elsif ($target eq 'tex') {
1510: $currentstring .= '\end{verbatim}';
1511: }
1512: return $currentstring;
1513: }
1514: #-- <insert>
1515: sub start_insert {
1516: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1517: my $currentstring = '';
1518: if ($target eq 'web') {
1519: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval);
1520: $currentstring .= '<b>'.$display.'</b>';;
1521: }
1522: return $currentstring;
1523: }
1524: sub end_insert {
1525: my ($target,$token) = @_;
1526: my $currentstring = '';
1527: if ($target eq 'web') {
1528: $currentstring .= '';
1529: }
1530: return $currentstring;
1531: }
1532: 1;
1533: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>