1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.449 2013/10/12 01:26:31 raeburn Exp $
5: #
6: #
7: # Copyright Michigan State University Board of Trustees
8: #
9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
10: #
11: # LON-CAPA is free software; you can redistribute it and/or modify
12: # it under the terms of the GNU General Public License as published by
13: # the Free Software Foundation; either version 2 of the License, or
14: # (at your option) any later version.
15: #
16: # LON-CAPA is distributed in the hope that it will be useful,
17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19: # GNU General Public License for more details.
20: #
21: # You should have received a copy of the GNU General Public License
22: # along with LON-CAPA; if not, write to the Free Software
23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24: #
25: # /home/httpd/html/adm/gpl.txt
26: #
27: # http://www.lon-capa.org/
28: ## Copyright for TtHfunc and TtMfunc by Ian Hutchinson.
29: # TtHfunc and TtMfunc (the "Code") may be compiled and linked into
30: # binary executable programs or libraries distributed by the
31: # Michigan State University (the "Licensee"), but any binaries so
32: # distributed are hereby licensed only for use in the context
33: # of a program or computational system for which the Licensee is the
34: # primary author or distributor, and which performs substantial
35: # additional tasks beyond the translation of (La)TeX into HTML.
36: # The C source of the Code may not be distributed by the Licensee
37: # to any other parties under any circumstances.
38: #
39:
40: package Apache::londefdef;
41:
42: use Apache::lonnet;
43: use strict;
44: use Apache::lonxml;
45: use Apache::lontable;
46: use Image::Magick;
47: use Apache::lonmenu();
48: use Apache::lonmeta();
49: use Apache::lonlocal;
50: use Apache::loncommon();
51: use Apache::Constants qw(:common);
52: use File::Basename;
53: use LONCAPA();
54: # use Data::Dumper;
55:
56: BEGIN {
57:
58: &Apache::lonxml::register('Apache::londefdef',('a','abbr','acronym','accessrule','address','allow','applet','area','b','base','basefont','bgo','bgsound','big','blink','blockquote','blankspace','body','br','button','caption','center','cite','code','col','colgroup','dd','del','dfn','dir','div','dl','dt','em','embed','externallink','fieldset','font','form','frame','frameset','h1','h2','h3','h4','h5','h6','head','hr','html','i','iframe','img','input','ins','insert','isindex','kbd','keygen','label','layer','legend','li','link','m','map','marquee','menu','meta','multicol','nobr','noembed','noframes','nolayer','noscript','object','ol','optgroup','option','output','p','param','pre','q','s','samp','select','server','small','spacer','span','strike','strong','style','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput'));
59:
60: }
61:
62:
63: sub initialize_londefdef {
64: $Apache::londefdef::TD_redirection=0;
65: @Apache::londefdef::table = ();
66: $Apache::londefdef::select=0;
67: undef(@Apache::londefdef::description);
68: @Apache::londefdef::DD=(0);
69: @Apache::londefdef::DT=(0);
70: @Apache::londefdef::seenDT=(0);
71: $Apache::londefdef::list_index=0;
72: undef($Apache::londefdef::head);
73: undef($Apache::londefdef::title);
74: }
75:
76: #======================= TAG SUBROUTINES =====================
77: #-- <output>
78: sub start_output {
79: my ($target) = @_;
80: if ($target eq 'meta') { $Apache::lonxml::metamode--; }
81: return '';
82: }
83: sub end_output {
84: my ($target) = @_;
85: if ($target eq 'meta') { $Apache::lonxml::metamode++; }
86: return '';
87: }
88: #-- <m> tag
89: sub start_m {
90: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
91: my $currentstring = '';
92: my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser);
93: if ($target eq 'web' || $target eq 'analyze') {
94: &Apache::lonxml::debug("M is starting with:$inside:");
95: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
96: if ($eval eq 'on') {
97: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
98: #&Apache::lonxml::debug("M is evaluated to:$inside:");
99: }
100: my $tex = $inside;
101: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
102: $currentstring = &Apache::lontexconvert::converted(\$inside,$display);
103: if ($Apache::lontexconvert::errorstring) {
104: my $errormsg='<pre>'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'</pre> occurred while attempting to convert this TeX: <pre>';
105: $tex = &HTML::Entities::encode($tex,'<>&"');
106: my ($linenumber) =
107: ($Apache::lontexconvert::errorstring =~ /Line (\d+)/);
108: if (defined($linenumber)) {
109: my @tex=split("\n",$tex);
110: $tex[$linenumber]='<b><font color="red">'.
111: $tex[$linenumber].'</font></b>';
112: $tex=join("\n",@tex);
113: }
114: &Apache::lonxml::warning($errormsg.$tex.'</pre>');
115: $Apache::lontexconvert::errorstring='';
116: }
117: #&Apache::lonxml::debug("M is ends with:$currentstring:");
118: $Apache::lonxml::post_evaluate=0;
119: } elsif ($target eq 'tex') {
120:
121: $currentstring = $inside;
122: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
123: if ($eval eq 'on') {
124: $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
125: }
126: if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
127: # detect simple math mode entry exits, and convert them
128: # to use \ensuremath ... unless there's a \verb inside.
129: if (! ($currentstring=~/\\verb/)) {
130: if ($currentstring=~/^\s*\$[^\$].*\$\s*$/) {
131: $currentstring=~s/^(\s*)\$/$1/;
132: $currentstring=~s/\$(\s*)$/$1/;
133: $currentstring='\ensuremath{'.$currentstring.'}';
134: }
135: }
136: $Apache::lonxml::post_evaluate=0;
137: }
138: return $currentstring;
139: }
140:
141: sub end_m {
142: my ($target,$token) = @_;
143: my $currentstring = '';
144: if ($target eq 'tex') {
145: $currentstring = "";
146: }
147: return $currentstring;
148: }
149:
150: sub start_tthoption {
151: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
152: my $result;
153: if ($target eq 'web' || $target eq 'webgrade') {
154: my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser,
155: $style);
156: $inside=~s/^\s*//;
157: if ($env{'browser.mathml'}) {
158: &tth::ttmoptions($inside);
159: } else {
160: &tth::tthoptions($inside);
161: }
162: }
163: return $result;
164: }
165:
166: sub end_tthoption {
167: my ($target,$token) = @_;
168: my $result;
169: return $result;
170: }
171:
172: #-- <html> tag (end tag optional)
173: sub start_html {
174: my ($target,$token) = @_;
175: my $currentstring = '';
176: if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) {
177: # start_body() takes care of emitting the <html>
178: } elsif ($target eq 'tex') {
179:
180: $currentstring .= &latex_header();
181: }
182: return $currentstring;
183: }
184:
185: sub end_html {
186: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
187: my $currentstring = '';
188: if ($target eq 'web' || $target eq 'webgrade') {
189: # end_body takes care of the </html>
190: }
191: return $currentstring;
192: }
193:
194: #-- <head> tag (end tag optional)
195: sub start_head {
196: my ($target,$token) = @_;
197: my $currentstring = '';
198: if ($target eq 'web' || $target eq 'webgrade') {
199: &Apache::lonxml::startredirection();
200: }
201: return $currentstring;
202: }
203:
204: sub end_head {
205: my ($target,$token) = @_;
206: my $currentstring = '';
207: if (($target eq 'web' && $env{'request.state'} eq 'published') ||
208: ($target eq 'webgrade' && $env{'request.state'} eq 'published')) {
209: # in case there is a </head> but no <head>
210: if ($Apache::lonxml::redirection) {
211: $Apache::londefdef::head = &Apache::lonxml::endredirection();
212: }
213: }
214: return $currentstring;
215: }
216:
217: #-- <map> tag (end tag required)
218: sub start_map {
219: my ($target,$token) = @_;
220: my $currentstring = '';
221: if ($target eq 'web' || $target eq 'webgrade') {
222: $currentstring = $token->[4];
223: }
224: return $currentstring;
225: }
226:
227: sub end_map {
228: my ($target,$token) = @_;
229: my $currentstring = '';
230: if ($target eq 'web' || $target eq 'webgrade') {
231: $currentstring = $token->[2];
232: }
233: return $currentstring;
234: }
235:
236: #-- <select> tag (end tag required)
237: sub start_select {
238: my ($target,$token) = @_;
239: my $currentstring = '';
240: if ($target eq 'web' || $target eq 'webgrade') {
241: $currentstring = $token->[4];
242: } elsif ($target eq 'tex') {
243: $Apache::londefdef::select=0;
244: }
245: return $currentstring;
246: }
247:
248: sub end_select {
249: my ($target,$token) = @_;
250: my $currentstring = '';
251: if ($target eq 'web' || $target eq 'webgrade') {
252: $currentstring = $token->[2];
253: }
254: return $currentstring;
255: }
256:
257: #-- <option> tag (end tag optional)
258: sub start_option {
259: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
260: my $currentstring = '';
261: if ($target eq 'web' || $target eq 'webgrade') {
262: $currentstring = $token->[4];
263: } elsif ($target eq 'tex') {
264: $Apache::londefdef::select++;
265: if ($Apache::londefdef::select == 1) {
266: $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
267: } else {
268: $currentstring='\keephidden{';
269: }
270: }
271: return $currentstring;
272: }
273:
274: sub end_option {
275: my ($target,$token) = @_;
276: my $currentstring = '';
277: if ($target eq 'web' || $target eq 'webgrade') {
278: $currentstring = $token->[2];
279: } elsif ($target eq 'tex') {
280: $currentstring='}';
281: }
282: return $currentstring;
283: }
284:
285: #-- <input> tag (end tag forbidden)
286: sub start_input {
287: my ($target,$token) = @_;
288: my $currentstring = '';
289: if ($target eq 'web' || $target eq 'webgrade') {
290: $currentstring = $token->[4];
291: }
292: return $currentstring;
293: }
294:
295: sub end_input {
296: my ($target,$token) = @_;
297: my $currentstring = '';
298: if ($target eq 'web' || $target eq 'webgrade') {
299: $currentstring = $token->[2];
300: }
301: return $currentstring;
302: }
303:
304: #-- <textarea> tag (end tag required)
305: sub start_textarea {
306: my ($target,$token) = @_;
307: my $currentstring = '';
308: if ($target eq 'web' || $target eq 'webgrade') {
309: $currentstring = $token->[4];
310: }
311: return $currentstring;
312: }
313:
314: sub end_textarea {
315: my ($target,$token) = @_;
316: my $currentstring = '';
317: if ($target eq 'web' || $target eq 'webgrade') {
318: $currentstring = $token->[2];
319: }
320: return $currentstring;
321: }
322:
323: #-- <form> tag (end tag required)
324: sub start_form {
325: my ($target,$token) = @_;
326: my $currentstring = '';
327: if ($target eq 'web' || $target eq 'webgrade') {
328: $currentstring = $token->[4];
329: }
330: return $currentstring;
331: }
332:
333: sub end_form {
334: my ($target,$token) = @_;
335: my $currentstring = '';
336: if ($target eq 'web' || $target eq 'webgrade') {
337: $currentstring = $token->[2];
338: }
339: return $currentstring;
340: }
341:
342: #-- <title> tag (end tag required)
343: sub start_title {
344: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
345: my $currentstring = '';
346: if ($target eq 'web' || $target eq 'webgrade') {
347: $Apache::londefdef::title =
348: &Apache::lonxml::get_all_text('/title',$parser,$style);
349: } elsif ($target eq 'tex') {
350: $currentstring .= '\keephidden{Title of the document: '
351: }
352: if ($target eq 'meta') {
353: $currentstring='<title>';
354: &start_output($target);
355: }
356: return $currentstring;
357: }
358:
359: sub end_title {
360: my ($target,$token) = @_;
361: my $currentstring = '';
362: if ($target eq 'web' || $target eq 'webgrade') {
363: # start_title takes care of swallowing the title
364: } elsif ($target eq 'tex') {
365: $currentstring .= '}';
366: }
367: if ($target eq 'meta') {
368: &end_output($target);
369: $currentstring='</title>';
370: }
371: return $currentstring;
372: }
373:
374: #-- <meta> tag (end tag forbidden)
375: sub start_meta {
376: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
377: my $currentstring = '';
378: if ($target eq 'web' || $target eq 'webgrade') {
379: my $args='';
380: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
381: if ($args eq '') {
382: &Apache::lonxml::get_all_text("/meta",$parser,$style);
383: } else {
384: $currentstring = $token->[4];
385: }
386: if ($env{'form.grade_imsexport'}) {
387: $currentstring = '';
388: }
389: } elsif ($target eq 'meta') {
390: unless (&Apache::lonxml::get_param
391: ('http-equiv',$parstack,$safeeval,undef,1)) {
392: my $name=$token->[2]->{'name'};
393: $name=~tr/A-Z/a-z/;
394: $name=~s/\s/\_/gs;
395: $name=~s/\W//gs;
396: if ($name) {
397: $currentstring='<'.$name;
398: my $display=&Apache::lonxml::get_param
399: ('display',$parstack,$safeeval,undef,1);
400: if ($display) {
401: $display=~s/\"/\'/g;
402: $currentstring.=' display="'.$display.'"';
403: }
404: $currentstring.='>'.
405: &Apache::lonxml::get_param
406: ('content',$parstack,$safeeval,undef,1).
407: '</'.$name.'>';
408: }
409: my $display=&Apache::lonxml::get_param
410: ('display',$parstack,$safeeval,undef,1);
411: if ($display) {
412: $display=&HTML::Entities::encode($display,'<>&"');
413: $currentstring.='<'.$name.'.display>'.$display.
414: '</'.$name.'.display>';
415: }
416: }
417: } elsif ($target eq 'tex') {
418: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
419: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
420: if ((not defined $content) && (not defined $name)) {
421: &Apache::lonxml::startredirection();
422: }
423: } elsif ($target eq 'edit') {
424: $currentstring .= &Apache::edit::tag_start($target,$token);
425: $currentstring .= &Apache::edit::text_arg('Name:','name',$token,30);
426: $currentstring .= &Apache::edit::text_arg('Content:','content',$token,70);
427: $currentstring .= &Apache::edit::end_row();
428: } elsif ($target eq 'modified') {
429: my $constructtag =
430: &Apache::edit::get_new_args($token,$parstack,$safeeval,
431: 'name','content');
432: if ($constructtag) { $currentstring = &Apache::edit::rebuild_tag($token); }
433: }
434: return $currentstring;
435: }
436:
437: sub end_meta {
438: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
439: my $currentstring = '';
440: if ($target eq 'web' || $target eq 'webgrade') {
441: my $args='';
442: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
443: if ($args ne '') {
444: $currentstring = $token->[4];
445: }
446: } elsif ($target eq 'tex') {
447: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
448: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
449: if ((not defined $content) && (not defined $name)) {
450: &Apache::lonxml::endredirection();
451: }
452: }
453: return $currentstring;
454: }
455:
456: sub insert_meta {
457: return '
458: <meta />';
459: }
460:
461: #-- <start> tag
462: sub start_style {
463: my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style) = @_;
464: my $currentstring = '';
465:
466: if ($target eq 'tex') {
467: Apache::lonxml::startredirection();
468: } else {
469: $currentstring = $token->[4];
470: }
471:
472: return $currentstring;
473: }
474:
475: sub end_style {
476: my ($target, $token, $tagstack, $parstack, $parser, $safeeval) = @_;
477: my $currentstring = '';
478:
479: if ($target eq 'tex') {
480: Apache::lonxml::endredirection();
481: } else {
482: $currentstring = $token->[2];
483: }
484: return $currentstring;
485: }
486:
487: # accessrule
488: sub start_accessrule {
489: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
490: my $currentstring = '';
491: my $eff =&Apache::lonxml::get_param('effect',$parstack,$safeeval,undef,1);
492: my $realm=&Apache::lonxml::get_param('realm', $parstack,$safeeval,undef,1);
493: my $role =&Apache::lonxml::get_param('role', $parstack,$safeeval,undef,1);
494: my $type =&Apache::lonxml::get_param('type', $parstack,$safeeval,undef,1);
495:
496: my ($dom,$crs,$sec,$separator);
497: if ($type eq 'user') {
498: ($dom,$crs,$sec)=split(m{/},$realm);
499: $crs = &LONCAPA::clean_username($crs);
500: $separator = '/';
501: } else {
502: ($dom,$crs,$sec)=split(/\_/,$realm);
503: $crs = &LONCAPA::clean_courseid($crs);
504: $separator = '_';
505: }
506: $dom = &LONCAPA::clean_domain($dom);
507:
508: $sec =~s/\W//;
509: $realm = $dom;
510: if ($crs =~ /\S/) { $realm .= $separator.$crs; }
511: if ($sec =~ /\S/) { $realm .= $separator.$sec; }
512: $role=~s/\W//g;
513:
514: if ($target eq 'web') {
515: my $args='';
516: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
517: if ($args eq '') {
518: &Apache::lonxml::get_all_text("/accessrule",$parser,$style);
519: } else {
520: $currentstring = $token->[4];
521: }
522: }
523: if ($target eq 'meta') {
524: $currentstring='<rule>'.$eff.':'.$realm.':'.$role.':'.$type.'</rule>';
525: }
526: return $currentstring;
527: }
528:
529: sub end_accessrule {
530: my ($target,$token,$tagstack,$parstack,$parser) = @_;
531: my $currentstring = '';
532: if ($target eq 'web') {
533: my $args='';
534: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
535: if ($args ne '') {
536: $currentstring = $token->[4];
537: }
538: }
539: return $currentstring;
540: }
541:
542: sub generate_css_links {
543: my $links;
544: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile');
545: if ($css_href =~ /\S/) {
546: &Apache::lonxml::extlink($css_href);
547: $links .=
548: '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />';
549: }
550: return $links;
551: }
552:
553: #-- <body> tag (end tag required)
554: sub start_body {
555: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
556: my $currentstring = '';
557:
558: if ($target eq 'web' || $target eq 'webgrade') {
559: if ($Apache::lonhomework::parsing_a_problem) {
560: &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
561: return '';
562: }
563:
564: if (&is_inside_of($tagstack, "head")) {
565: &end_head(@_);
566: }
567:
568: my $extra_head = &generate_css_links();
569:
570: # Breadcrumbs
571: &Apache::lonhtmlcommon::clear_breadcrumbs();
572: if ($env{'request.state'} eq 'construct') {
573: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
574: &Apache::lonhtmlcommon::add_breadcrumb({
575: 'text' => 'Authoring Space',
576: 'href' => &Apache::loncommon::authorspace($url),
577: });
578: &Apache::lonhtmlcommon::add_breadcrumb({
579: 'text' => 'HTML Editor',
580: 'href' => '',
581: });
582: # breadcrumbs (and tools) will be created
583: # in start_page->bodytag->innerregister
584: } else {
585: # FIXME Where are we?
586: }
587:
588: $currentstring =
589: &Apache::loncommon::start_page($Apache::londefdef::title,
590: $Apache::londefdef::head
591: .$extra_head,
592: {'add_entries' => $token->[2],
593: # 'no_title' => 1,
594: 'force_register' => 1});
595:
596: my $header = '';
597: if ($env{'request.state'} ne 'published' &&
598: $env{'request.state'} ne 'construct') {
599: $header=&Apache::lonmenu::constspaceform();
600: }
601: if ($env{'request.state'} ne 'published') {
602: unless ($env{'form.inhibitmenu'} eq 'yes') {
603: $header.=&edit_controls();
604: }
605: }
606: if ($env{'request.state'} eq 'construct') {
607: unless ($env{'form.inhibitmenu'} eq 'yes') {
608: $currentstring.=&Apache::loncommon::head_subbox(
609: &Apache::loncommon::CSTR_pageheader()
610: .$header);
611: }
612: } elsif ($env{'request.state'} eq 'edit') {
613: $currentstring.=&Apache::loncommon::head_subbox($header);
614: }
615: $currentstring.=&Apache::lonxml::message_location();
616: } elsif ($target eq 'tex') {
617: $currentstring = ''; # '\begin{document}' is in header.
618: }
619:
620: return $currentstring;
621: }
622:
623: sub edit_controls {
624: my ($nochgview) = @_;
625: my $result .= '
626: <form method="post" action="">
627: <div class="LC_edit_problem_header">';
628: unless ($nochgview) {
629: $result .= '
630: <div class="LC_edit_problem_header_row1">'.
631: &Apache::lonxml::renderingoptions().'
632: <input type="submit" name="changeproblemmode" value="'.&mt('Change View').'" />
633: </div>';
634: }
635: $result .= '
636: <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
637: if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
638: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
639: if ($url =~ /\.html?$/i) {
640: my ($cdom,$cnum);
641: if ($env{'request.course.id'}) {
642: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
643: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
644: if ($env{'request.filename'} =~ m{/userfiles/supplemental/default|\d+/}) {
645: if (&Apache::lonnet::is_course_upload($env{'request.filename'},
646: $cnum,$cdom)) {
647: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
648: ['folderpath','title']);
649: }
650: }
651: }
652: my ($symb,$itemtitle,$displayfile,$caller);
653: if ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}) {
654: $itemtitle = &mt('Syllabus');
655: $caller = "/public/$cdom/$cnum/syllabus";
656: } else {
657: $caller = $url;
658: ($symb,$itemtitle,$displayfile) =
659: &Apache::lonxml::get_courseupload_hierarchy($url,
660: $env{'form.folderpath'},
661: $env{'form.title'});
662: }
663: if (($symb ne '') || ($env{'httpref.'.$url} ne '') ||
664: ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/})) {
665: $result .= (' ' x 3).
666: &Apache::lonhtmlcommon::dependencies_button()."\n".
667: &Apache::lonhtmlcommon::dependencycheck_js($symb,
668: $itemtitle,$url,$env{'form.folderpath'},$caller)."\n";
669: }
670: }
671: }
672: $result .= '</div>
673: </div>
674: </form>
675: ';
676: return $result;
677: }
678:
679: sub end_body {
680: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
681: my $currentstring = &end_p(); # Close off unclosed <p>
682: if ($target eq 'web' || $target eq 'webgrade') {
683: $currentstring .= &Apache::loncommon::end_page({'discussion' => 1});
684: } elsif ($target eq 'tex') {
685: $currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';
686: }
687: return $currentstring;
688: }
689:
690: # \begin{center} causes a new paragprah spacing that looks odd inside
691: # of a table cell. Same at the end of a \center but with a slightly
692: # larger space .. hence center_correction and center_end_correction.
693: #
694: sub center_correction { return '\vspace*{-6 mm}'; }
695: sub center_end_correction { return '\vspace*{-7 mm}'; }
696:
697: #-- <center> tag (end tag required)
698: sub start_center {
699: my ($target,$token,$tagstack) = @_;
700: my $currentstring = &end_p(); # Close off any prior para.
701: if ($target eq 'web' || $target eq 'webgrade') {
702: $currentstring .= $token->[4];
703: } elsif ($target eq 'tex') {
704: if (&is_inside_of($tagstack, "table")) {
705: $currentstring .= ¢er_correction();
706: }
707: $currentstring .= '\begin{center}';
708: }
709: return $currentstring;
710: }
711:
712: sub end_center {
713: my ($target,$token,$tagstack) = @_;
714: my $currentstring = '';
715: if ($target eq 'web' || $target eq 'webgrade') {
716: $currentstring = $token->[2];
717: } elsif ($target eq 'tex') {
718: $currentstring = '\end{center}';
719: if (&is_inside_of($tagstack, "table")) {
720: $currentstring .= ¢er_end_correction();
721: }
722: }
723: return $currentstring;
724: }
725:
726: #-- <b> tag (end tag required)
727: # NOTE: In TeX mode disables internal <p>
728: sub start_b {
729: my ($target,$token) = @_;
730: my $currentstring = '';
731: if ($target eq 'web' || $target eq 'webgrade') {
732: $currentstring = $token->[4];
733: } elsif ($target eq 'tex') {
734: &disable_para();
735: $currentstring .= '\textbf{';
736: }
737: return $currentstring;
738: }
739:
740: sub end_b {
741: my ($target,$token) = @_;
742: my $currentstring = '';
743: if ($target eq 'web' || $target eq 'webgrade') {
744: $currentstring = $token->[2];
745: } elsif ($target eq 'tex') {
746: &enable_para();
747: $currentstring = '}';
748: }
749: return $currentstring;
750: }
751:
752: #-- <strong> tag (end tag required)
753: # NOTE: in TeX mode disables internal <p>
754: sub start_strong {
755: my ($target,$token) = @_;
756: my $currentstring = '';
757: if ($target eq 'web' || $target eq 'webgrade') {
758: $currentstring = $token->[4];
759: } elsif ($target eq 'tex') {
760: &disable_para();
761: $currentstring = '\textbf{';
762: }
763: return $currentstring;
764: }
765:
766: sub end_strong {
767: my ($target,$token) = @_;
768: my $currentstring = '';
769: if ($target eq 'web' || $target eq 'webgrade') {
770: $currentstring = $token->[2];
771: } elsif ($target eq 'tex') {
772: &enable_para();
773: $currentstring = '}';
774: }
775: return $currentstring;
776: }
777:
778: #-- <h1> tag (end tag required)
779: sub start_h1 {
780: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
781: my $currentstring = &end_p(); # Close off any prior para.
782: if ($target eq 'web' || $target eq 'webgrade') {
783: $currentstring .= $token->[4];
784: } elsif ($target eq 'tex') {
785: my $pre;
786: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
787: if ($align eq 'center') {
788: $pre='\begin{center}';
789: } elsif ($align eq 'left') {
790: $pre='\rlap{';
791: } elsif ($align eq 'right') {
792: $pre=' \hfill \llap{';
793: }
794: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
795: if (not defined $TeXsize) {$TeXsize="large";}
796: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
797: } elsif ($target eq 'meta') {
798: $currentstring.='<subject>';
799: &start_output($target);
800: }
801: return $currentstring;
802: }
803:
804: sub end_h1 {
805: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
806: my $currentstring = '';
807: if ($target eq 'web' || $target eq 'webgrade') {
808: $currentstring .= $token->[2];
809: } elsif ($target eq 'tex') {
810: my $post='\vskip 0 mm ';
811: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
812: if ($align eq 'center') {
813: $post='\end{center}';
814: } elsif ($align eq 'left') {
815: $post='} \hfill'.'\vskip 0 mm ';
816: } elsif ($align eq 'right') {
817: $post='}'.'\vskip 0 mm ';
818: }
819: $currentstring .= '}}'.$post;
820: } elsif ($target eq 'meta') {
821: &end_output($target);
822: $currentstring='</subject>';
823: }
824: return $currentstring;
825: }
826:
827: #-- <h2> tag
828: sub start_h2 {
829: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
830: my $currentstring = &end_p(); # Close off any prior para.
831: if ($target eq 'web' || $target eq 'webgrade') {
832: $currentstring .= $token->[4];
833: } elsif ($target eq 'tex') {
834: my $pre;
835: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
836: if ($align eq 'center') {
837: $pre='\begin{center}';
838: } elsif ($align eq 'left') {
839: $pre='\rlap{';
840: } elsif ($align eq 'right') {
841: $pre=' \hfill \llap{';
842: }
843: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
844: if (not defined $TeXsize) {$TeXsize="large";}
845: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
846: }
847: return $currentstring;
848: }
849:
850: sub end_h2 {
851: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
852: my $currentstring = '';
853: if ($target eq 'web' || $target eq 'webgrade') {
854: $currentstring .= $token->[2];
855: } elsif ($target eq 'tex') {
856: my $post='\vskip 0 mm ';
857: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
858: if ($align eq 'center') {
859: $post='\end{center}';
860: } elsif ($align eq 'left') {
861: $post='} \hfill'.'\vskip 0 mm ';
862: } elsif ($align eq 'right') {
863: $post='}'.'\vskip 0 mm ';
864: }
865: $currentstring .= '}}'.$post;
866: }
867: return $currentstring;
868: }
869:
870: #-- <h3> tag
871: sub start_h3 {
872: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
873: my $currentstring = &end_p(); # Close off any prior para.
874: if ($target eq 'web' || $target eq 'webgrade') {
875: $currentstring .= $token->[4];
876: } elsif ($target eq 'tex') {
877: my $pre;
878: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
879: if ($align eq 'center') {
880: $pre='\begin{center}';
881: } elsif ($align eq 'left') {
882: $pre='\rlap{';
883: } elsif ($align eq 'right') {
884: $pre=' \hfill \llap{';
885: }
886: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
887: if (not defined $TeXsize) {$TeXsize="large";}
888: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
889: }
890: return $currentstring;
891: }
892:
893: sub end_h3 {
894: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
895: my $currentstring = '';
896: if ($target eq 'web' || $target eq 'webgrade') {
897: $currentstring .= $token->[2];
898: } elsif ($target eq 'tex') {
899: my $post='\vskip 0 mm ';
900: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
901: if ($align eq 'center') {
902: $post='\end{center}';
903: } elsif ($align eq 'left') {
904: $post='} \hfill'.'\vskip 0 mm ';
905: } elsif ($align eq 'right') {
906: $post='}'.'\vskip 0 mm ';
907: }
908: $currentstring .= '}}'.$post;
909: }
910: return $currentstring;
911: }
912:
913: #-- <h4> tag
914: sub start_h4 {
915: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
916: my $currentstring = &end_p(); # Close off any prior para.
917: if ($target eq 'web' || $target eq 'webgrade') {
918: $currentstring .= $token->[4];
919: } elsif ($target eq 'tex') {
920: my $pre;
921: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
922: if ($align eq 'center') {
923: $pre='\begin{center}';
924: } elsif ($align eq 'left') {
925: $pre='\rlap{';
926: } elsif ($align eq 'right') {
927: $pre=' \hfill \llap{';
928: }
929: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
930: if (not defined $TeXsize) {$TeXsize="large";}
931: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
932: }
933: return $currentstring;
934: }
935:
936: sub end_h4 {
937: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
938: my $currentstring = '';
939: if ($target eq 'web' || $target eq 'webgrade') {
940: $currentstring .= $token->[2];
941: } elsif ($target eq 'tex') {
942: my $post='\vskip 0 mm ';
943: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
944: if ($align eq 'center') {
945: $post='\end{center}';
946: } elsif ($align eq 'left') {
947: $post='} \hfill'.'\vskip 0 mm ';
948: } elsif ($align eq 'right') {
949: $post='}'.'\vskip 0 mm ';
950: }
951: $currentstring .= '}}'.$post;
952: }
953: return $currentstring;
954: }
955:
956: #-- <h5> tag
957: sub start_h5 {
958: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
959: my $currentstring = &end_p(); # Close off any prior paras.
960: if ($target eq 'web' || $target eq 'webgrade') {
961: $currentstring .= $token->[4];
962: } elsif ($target eq 'tex') {
963: my $pre;
964: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
965: if ($align eq 'center') {
966: $pre='\begin{center}';
967: } elsif ($align eq 'left') {
968: $pre='\rlap{';
969: } elsif ($align eq 'right') {
970: $pre=' \hfill \llap{';
971: }
972: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
973: if (not defined $TeXsize) {$TeXsize="large";}
974: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
975: }
976: return $currentstring;
977: }
978:
979: sub end_h5 {
980: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
981: my $currentstring = '';
982: if ($target eq 'web' || $target eq 'webgrade') {
983: $currentstring .= $token->[2];
984: } elsif ($target eq 'tex') {
985: my $post='\vskip 0 mm ';
986: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
987: if ($align eq 'center') {
988: $post='\end{center}';
989: } elsif ($align eq 'left') {
990: $post='} \hfill'.'\vskip 0 mm ';
991: } elsif ($align eq 'right') {
992: $post='}'.'\vskip 0 mm ';
993: }
994: $currentstring .= '}}'.$post;
995: }
996: return $currentstring;
997: }
998:
999: #-- <h6> tag
1000: sub start_h6 {
1001: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1002: my $currentstring = &end_p(); # Close off any prior paras.
1003: if ($target eq 'web' || $target eq 'webgrade') {
1004: $currentstring .= $token->[4];
1005: } elsif ($target eq 'tex') {
1006: my $pre;
1007: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1008: if ($align eq 'center') {
1009: $pre='\begin{center}';
1010: } elsif ($align eq 'left') {
1011: $pre='\rlap{';
1012: } elsif ($align eq 'right') {
1013: $pre=' \hfill \llap{';
1014: }
1015: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
1016: if (not defined $TeXsize) {$TeXsize="large";}
1017: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
1018: }
1019: return $currentstring;
1020: }
1021:
1022: sub end_h6 {
1023: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1024: my $currentstring = '';
1025: if ($target eq 'web' || $target eq 'webgrade') {
1026: $currentstring .= $token->[2];
1027: } elsif ($target eq 'tex') {
1028: my $post='\vskip 0 mm ';
1029: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1030: if ($align eq 'center') {
1031: $post='\end{center}';
1032: } elsif ($align eq 'left') {
1033: $post='} \hfill'.'\vskip 0 mm ';
1034: } elsif ($align eq 'right') {
1035: $post='}'.'\vskip 0 mm ';
1036: }
1037: $currentstring .= '}}'.$post;
1038: }
1039: return $currentstring;
1040: }
1041:
1042: #--- <cite> tag (end tag required)
1043: sub start_cite {
1044: my ($target,$token) = @_;
1045: my $currentstring = '';
1046: if ($target eq 'web' || $target eq 'webgrade') {
1047: $currentstring .= $token->[4];
1048: } elsif ($target eq 'tex') {
1049: $currentstring .= '\textit{';
1050: }
1051: return $currentstring;
1052: }
1053:
1054: sub end_cite {
1055: my ($target,$token) = @_;
1056: my $currentstring = '';
1057: if ($target eq 'web' || $target eq 'webgrade') {
1058: $currentstring .= $token->[2];
1059: } elsif ($target eq 'tex') {
1060: $currentstring .= '}';
1061: }
1062: return $currentstring;
1063: }
1064:
1065: #-- <i> tag (end tag required)
1066: sub start_i {
1067: my ($target,$token) = @_;
1068: my $currentstring = '';
1069: if ($target eq 'web' || $target eq 'webgrade') {
1070: $currentstring .= $token->[4];
1071: } elsif ($target eq 'tex') {
1072: $currentstring .= '\textit{';
1073: }
1074: return $currentstring;
1075: }
1076:
1077: sub end_i {
1078: my ($target,$token) = @_;
1079: my $currentstring = '';
1080: if ($target eq 'web' || $target eq 'webgrade') {
1081: $currentstring .= $token->[2];
1082: } elsif ($target eq 'tex') {
1083: $currentstring .= '}';
1084: }
1085: return $currentstring;
1086: }
1087:
1088: #-- <address> tag (end tag required)
1089: sub start_address {
1090: my ($target,$token) = @_;
1091: my $currentstring = '';
1092: if ($target eq 'web' || $target eq 'webgrade') {
1093: $currentstring .= $token->[4];
1094: } elsif ($target eq 'tex') {
1095: $currentstring .= '\textit{';
1096: }
1097: return $currentstring;
1098: }
1099:
1100: sub end_address {
1101: my ($target,$token) = @_;
1102: my $currentstring = '';
1103: if ($target eq 'web' || $target eq 'webgrade') {
1104: $currentstring .= $token->[2];
1105: } elsif ($target eq 'tex') {
1106: $currentstring .= '}';
1107: }
1108: return $currentstring;
1109: }
1110:
1111: #-- <dfn> tag (end tag required)
1112: sub start_dfn {
1113: my ($target,$token) = @_;
1114: my $currentstring = '';
1115: if ($target eq 'web' || $target eq 'webgrade') {
1116: $currentstring .= $token->[4];
1117: } elsif ($target eq 'tex') {
1118: $currentstring .= '\textit{';
1119: }
1120: return $currentstring;
1121: }
1122:
1123: sub end_dfn {
1124: my ($target,$token) = @_;
1125: my $currentstring = '';
1126: if ($target eq 'web' || $target eq 'webgrade') {
1127: $currentstring .= $token->[2];
1128: } elsif ($target eq 'tex') {
1129: $currentstring .= '}';
1130: }
1131: return $currentstring;
1132: }
1133:
1134: #-- <tt> tag (end tag required)
1135: sub start_tt {
1136: my ($target,$token) = @_;
1137: my $currentstring = '';
1138: if ($target eq 'web' || $target eq 'webgrade') {
1139: $currentstring .= $token->[4];
1140: } elsif ($target eq 'tex') {
1141: $currentstring .= '\texttt{';
1142: }
1143: return $currentstring;
1144: }
1145:
1146: sub end_tt {
1147: my ($target,$token) = @_;
1148: my $currentstring = '';
1149: if ($target eq 'web' || $target eq 'webgrade') {
1150: $currentstring .= $token->[2];
1151: } elsif ($target eq 'tex') {
1152: $currentstring .= '}';
1153: }
1154: return $currentstring;
1155: }
1156:
1157: #-- <kbd> tag (end tag required)
1158: sub start_kbd {
1159: my ($target,$token) = @_;
1160: my $currentstring = '';
1161: if ($target eq 'web' || $target eq 'webgrade') {
1162: $currentstring .= $token->[4];
1163: } elsif ($target eq 'tex') {
1164: $currentstring .= '\texttt{';
1165: }
1166: return $currentstring;
1167: }
1168:
1169: sub end_kbd {
1170: my ($target,$token) = @_;
1171: my $currentstring = '';
1172: if ($target eq 'web' || $target eq 'webgrade') {
1173: $currentstring .= $token->[2];
1174: } elsif ($target eq 'tex') {
1175: $currentstring .= '}';
1176: }
1177: return $currentstring;
1178: }
1179:
1180: #-- <code> tag (end tag required)
1181: sub start_code {
1182: my ($target,$token) = @_;
1183: my $currentstring = '';
1184: if ($target eq 'web' || $target eq 'webgrade') {
1185: $currentstring .= $token->[4];
1186: } elsif ($target eq 'tex') {
1187: $currentstring .= '\texttt{';
1188: }
1189: return $currentstring;
1190: }
1191:
1192: sub end_code {
1193: my ($target,$token) = @_;
1194: my $currentstring = '';
1195: if ($target eq 'web' || $target eq 'webgrade') {
1196: $currentstring .= $token->[2];
1197: } elsif ($target eq 'tex') {
1198: $currentstring .= '}';
1199: }
1200: return $currentstring;
1201: }
1202:
1203: #-- <em> tag (end tag required)
1204: sub start_em {
1205: my ($target,$token) = @_;
1206: my $currentstring = '';
1207: if ($target eq 'web' || $target eq 'webgrade') {
1208: $currentstring .= $token->[4];
1209: } elsif ($target eq 'tex') {
1210: $currentstring .= '\emph{';
1211: }
1212: return $currentstring;
1213: }
1214:
1215: sub end_em {
1216: my ($target,$token) = @_;
1217: my $currentstring = '';
1218: if ($target eq 'web' || $target eq 'webgrade') {
1219: $currentstring .= $token->[2];
1220: } elsif ($target eq 'tex') {
1221: $currentstring .= '}';
1222: }
1223: return $currentstring;
1224: }
1225:
1226: #-- <q> tag (end tag required)
1227: sub start_q {
1228: my ($target,$token) = @_;
1229: my $currentstring = '';
1230: if ($target eq 'web' || $target eq 'webgrade') {
1231: $currentstring .= $token->[4];
1232: } elsif ($target eq 'tex') {
1233: $currentstring .= '\emph{';
1234: }
1235: return $currentstring;
1236: }
1237:
1238: sub end_q {
1239: my ($target,$token) = @_;
1240: my $currentstring = '';
1241: if ($target eq 'web' || $target eq 'webgrade') {
1242: $currentstring .= $token->[2];
1243: } elsif ($target eq 'tex') {
1244: $currentstring .= '}';
1245: }
1246: return $currentstring;
1247: }
1248:
1249: # <p> is a bit strange since it does not require a closing </p>
1250: # However in latex, we must often output closing stuff to end
1251: # environments and {}'s etc. Therefore we do all the work
1252: # of figuring out the ending strings in the start tag processing,
1253: # and provide a mechanism to output the stop text external
1254: # to tag processing.
1255: #
1256: {
1257:
1258: my $closing_string = ''; # String required to close <p>
1259:
1260: # Some tags are <p> fragile meaning that <p> inside of them
1261: # does not work within TeX mode. This is managed via the
1262: # counter below:
1263: #
1264:
1265: my $para_disabled = 0;
1266:
1267: sub disable_para {
1268: $para_disabled++;
1269: }
1270: sub enable_para {
1271: $para_disabled--;
1272: }
1273:
1274:
1275: #-- <p> tag (end tag optional)
1276: #optional attribute - align="center|left|right"
1277: sub start_p {
1278: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1279: my $currentstring = '';
1280: if ($target eq 'web' || $target eq 'webgrade') {
1281: $currentstring .= &end_p(); # close off prior para if in progress.
1282: $currentstring .= $token->[4];
1283: if (! ($currentstring =~ /\//)) {
1284: $closing_string = '</p>'; # Deal correctly with <p /> e.g.
1285: }
1286: } elsif ($target eq 'tex' && !$para_disabled) {
1287:
1288: $currentstring .= &end_p(); # close off prior para if in progress.
1289: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1290: if ($align eq 'center') {
1291: $currentstring .='\begin{center}\par ';
1292: $closing_string = '\end{center}';
1293: if (&is_inside_of($tagstack, "table")) {
1294: $currentstring = ¢er_correction().$currentstring;
1295: }
1296: } elsif ($align eq 'right') {
1297: $currentstring.="\n".'{\flushright ';
1298: # $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
1299: $closing_string= "}\n";
1300: } elsif ($align eq 'left') {
1301: $currentstring.= "\n".'{\flushleft ';
1302: # $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{{';
1303: $closing_string = "}\n";
1304: } else {
1305: $currentstring.='\par ';
1306: if (&is_inside_of($tagstack, 'table')) {
1307: $closing_string = '\vskip 0pt'; # Seems to be consistent with <p> in tables.
1308: } else {
1309: $closing_string = '\strut\\\\\strut ';
1310: }
1311: }
1312:
1313: }
1314: return $currentstring;
1315: }
1316: #
1317: # End paragraph processing just requires that we output the
1318: # closing string that was saved and blank it.
1319: sub end_p {
1320: # Note only 'tex' mode uses disable_para and enable_para
1321: # so we don't need to know the target in the check below:
1322:
1323: if (!$para_disabled) {
1324: my $current_string = $closing_string;
1325: $closing_string = ''; # Not in a para anymore.
1326: return $current_string;
1327: } else {
1328: return '';
1329: }
1330:
1331: }
1332: }
1333: #-- <br> tag (end tag forbidden)
1334: sub start_br {
1335: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1336: my $currentstring = '';
1337: if ($target eq 'web' || $target eq 'webgrade') {
1338: $currentstring .= $token->[4];
1339: } elsif ($target eq 'tex') {
1340: my @tempo=@$tagstack;
1341: my $signal=0;
1342: # Not going to factor this to is_inside_of since that would require
1343: # multiple stack traversals.
1344: #
1345: for (my $i=$#tempo;$i>=0;$i--) {
1346: if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
1347: ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul')) {
1348: $signal=1;
1349: }
1350: if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
1351: $signal = 1;
1352: }
1353: }
1354: if ($signal != 1) {
1355: $currentstring .= '\strut \\\\ \strut ';
1356: }
1357:
1358: }
1359: return $currentstring;
1360: }
1361:
1362: sub end_br {
1363: my ($target,$token) = @_;
1364: my $currentstring = '';
1365: if ($target eq 'web' || $target eq 'webgrade') {
1366: $currentstring .= $token->[2];
1367: }
1368: return $currentstring;
1369: }
1370:
1371: #-- <big> tag (end tag required)
1372: sub start_big {
1373: my ($target,$token) = @_;
1374: my $currentstring = '';
1375: if ($target eq 'web' || $target eq 'webgrade') {
1376: $currentstring .= $token->[4];
1377: } elsif ($target eq 'tex') {
1378: $currentstring .= '{\large ';
1379: }
1380: return $currentstring;
1381: }
1382:
1383: sub end_big {
1384: my ($target,$token) = @_;
1385: my $currentstring = '';
1386: if ($target eq 'web' || $target eq 'webgrade') {
1387: $currentstring .= $token->[2];
1388: } elsif ($target eq 'tex') {
1389: $currentstring .= '}';
1390: }
1391: return $currentstring;
1392: }
1393:
1394: #-- <small> tag (end tag required)
1395: sub start_small {
1396: my ($target,$token) = @_;
1397: my $currentstring = '';
1398: if ($target eq 'web' || $target eq 'webgrade') {
1399: $currentstring .= $token->[4];
1400: } elsif ($target eq 'tex') {
1401: $currentstring .= '{\footnotesize ';
1402: }
1403: return $currentstring;
1404: }
1405:
1406: sub end_small {
1407: my ($target,$token) = @_;
1408: my $currentstring = '';
1409: if ($target eq 'web' || $target eq 'webgrade') {
1410: $currentstring .= $token->[2];
1411: } elsif ($target eq 'tex') {
1412: $currentstring .= '}';
1413: }
1414: return $currentstring;
1415: }
1416:
1417: #-- <basefont> tag (end tag forbidden)
1418: sub start_basefont {
1419: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1420: my $currentstring = '';
1421: if ($target eq 'web' || $target eq 'webgrade') {
1422: $currentstring = $token->[4];
1423: } elsif ($target eq 'tex') {
1424: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1425: if (defined $basesize) {
1426: $currentstring = '{\\'.$basesize.' ';
1427: }
1428: }
1429: return $currentstring;
1430: }
1431:
1432: sub end_basefont {
1433: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1434: my $currentstring = '';
1435: if ($target eq 'web' || $target eq 'webgrade') {
1436: $currentstring = $token->[4];
1437: } elsif ($target eq 'tex') {
1438: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1439: if (defined $basesize) {
1440: $currentstring = '}';
1441: }
1442: }
1443: return $currentstring;
1444: }
1445:
1446: #-- <font> tag (end tag required)
1447: sub start_font {
1448: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1449: my $currentstring = '';
1450: if ($target eq 'web' || $target eq 'webgrade') {
1451: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1452: $currentstring = $token->[4];
1453: } elsif ($target eq 'tex') {
1454: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1455: if (defined $fontsize) {
1456: $currentstring = '{\\'.$fontsize.' ';
1457: }
1458: }
1459: return $currentstring;
1460: }
1461:
1462: sub end_font {
1463: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1464: my $currentstring = '';
1465: if ($target eq 'web' || $target eq 'webgrade') {
1466: $currentstring = $token->[2];
1467: } elsif ($target eq 'tex') {
1468: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1469: if (defined $fontsize) {
1470: $currentstring = '}';
1471: }
1472: }
1473: return $currentstring;
1474: }
1475:
1476: #-- <strike> tag (end tag required)
1477: sub start_strike {
1478: my ($target,$token) = @_;
1479: my $currentstring = '';
1480: if ($target eq 'web' || $target eq 'webgrade') {
1481: $currentstring .= $token->[4];
1482: } elsif ($target eq 'tex') {
1483: &Apache::lonxml::startredirection();
1484: }
1485: return $currentstring;
1486: }
1487:
1488: sub end_strike {
1489: my ($target,$token) = @_;
1490: my $currentstring = '';
1491: if ($target eq 'web' || $target eq 'webgrade') {
1492: $currentstring .= $token->[2];
1493: } elsif ($target eq 'tex') {
1494: $currentstring=&Apache::lonxml::endredirection();
1495: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1496: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1497: $currentstring=~s/(\S)\s*$/$1\}/;
1498: }
1499: return $currentstring;
1500: }
1501:
1502: #-- <s> tag (end tag required)
1503: sub start_s {
1504: my ($target,$token) = @_;
1505: my $currentstring = '';
1506: if ($target eq 'web' || $target eq 'webgrade') {
1507: $currentstring .= $token->[4];
1508: } elsif ($target eq 'tex') {
1509: &Apache::lonxml::startredirection();
1510: }
1511: return $currentstring;
1512: }
1513:
1514: sub end_s {
1515: my ($target,$token) = @_;
1516: my $currentstring = '';
1517: if ($target eq 'web' || $target eq 'webgrade') {
1518: $currentstring .= $token->[2];
1519: } elsif ($target eq 'tex') {
1520: $currentstring=&Apache::lonxml::endredirection();
1521: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1522: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1523: $currentstring=~s/(\S)\s*$/$1\}/;
1524: }
1525: return $currentstring;
1526: }
1527:
1528: #-- <sub> tag (end tag required)
1529: sub start_sub {
1530: my ($target,$token) = @_;
1531: my $currentstring = '';
1532: if ($target eq 'web' || $target eq 'webgrade') {
1533: $currentstring .= $token->[4];
1534: } elsif ($target eq 'tex') {
1535: $currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{';
1536: }
1537: return $currentstring;
1538: }
1539:
1540: sub end_sub {
1541: my ($target,$token) = @_;
1542: my $currentstring = '';
1543: if ($target eq 'web' || $target eq 'webgrade') {
1544: $currentstring .= $token->[2];
1545: } elsif ($target eq 'tex') {
1546: $currentstring .= '}}';
1547: }
1548: return $currentstring;
1549: }
1550:
1551: #-- <sup> tag (end tag required)
1552: sub start_sup {
1553: my ($target,$token) = @_;
1554: my $currentstring = '';
1555: if ($target eq 'web' || $target eq 'webgrade') {
1556: $currentstring .= $token->[4];
1557: } elsif ($target eq 'tex') {
1558: $currentstring .= '\raisebox{\smallskipamount}{\scriptsize{';
1559: }
1560: return $currentstring;
1561: }
1562:
1563: sub end_sup {
1564: my ($target,$token) = @_;
1565: my $currentstring = '';
1566: if ($target eq 'web' || $target eq 'webgrade') {
1567: $currentstring .= $token->[2];
1568: } elsif ($target eq 'tex') {
1569: $currentstring .= '}}';
1570: }
1571: return $currentstring;
1572: }
1573:
1574: #-- <hr> tag (end tag forbidden)
1575: sub start_hr {
1576: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1577: my $currentstring = &end_p(); # End enclosing para.
1578: if ($target eq 'web' || $target eq 'webgrade') {
1579: $currentstring .= $token->[4];
1580: } elsif ($target eq 'tex') {
1581:
1582: # <hr /> can't be inside of <sup><sub> thank you LaTeX.
1583: #
1584: my $restart_sub = 0;
1585: my $restart_sup = 0;
1586:
1587: # Since <sub> and <sup> are simple tags it's ok to turn off/on
1588: # using the start_ stop_ functions.. those tags only care about
1589: # $target.
1590:
1591: if (&is_inside_of($tagstack, "sub")) {
1592: $restart_sub = 1;
1593: $currentstring .= &end_sub($target, $token, $tagstack,
1594: $parstack, $parser, $safeeval);
1595: }
1596: if (&is_inside_of($tagstack, "sup")) {
1597: $restart_sup = 1;
1598: $currentstring .= &end_sup($target, $token, $tagstack,
1599: $parstack, $parser, $safeeval);
1600: }
1601:
1602: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1603: if (defined $LaTeXwidth) {
1604: if ($LaTeXwidth=~/^%/) {
1605: substr($LaTeXwidth,0,1)='';
1606: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1607: }
1608: } else {
1609: $LaTeXwidth ='0.9\textwidth';
1610: }
1611: my ($pre,$post);
1612: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1613: if (($align eq 'center') || (not defined $align)) {
1614: $pre=''; $post='';
1615: } elsif ($align eq 'left') {
1616: $pre='\rlap{'; $post='} \hfill';
1617: } elsif ($align eq 'right') {
1618: $pre=' \hfill \llap{'; $post='}';
1619: }
1620: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1621: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1622: # Turn stuff back on that we can't be inside of.
1623:
1624: if ($restart_sub) {
1625: $currentstring .= &start_sub($target, $token, $tagstack,
1626: $parstack, $parser, $safeeval);
1627: }
1628: if ($restart_sup) {
1629: $currentstring .= &start_sup($target, $token, $tagstack,
1630: $parstack, $parser, $safeeval);
1631: }
1632: }
1633: return $currentstring;
1634: }
1635:
1636: sub end_hr {
1637: my ($target,$token) = @_;
1638: my $currentstring = '';
1639: if ($target eq 'web' || $target eq 'webgrade') {
1640: $currentstring .= $token->[2];
1641: }
1642: return $currentstring;
1643: }
1644:
1645: #-- <div> tag (end tag required)
1646: {
1647:
1648: # Since div can be nested, the stack below is used
1649: # in 'tex' mode to store the ending strings
1650: # for the div stack.
1651:
1652: my @div_end_stack;
1653:
1654: sub start_div {
1655: my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
1656: my $currentstring = &end_p(); # Close enclosing para.
1657: if ($target eq 'web' || $target eq 'webgrade') {
1658: $currentstring .= $token->[4];
1659: }
1660: if ($target eq 'tex') {
1661: # 4 possible alignments: left, right, center, and -missing-.
1662: # If inside a table row, we must let the table logic
1663: # do the alignment, however.
1664: #
1665:
1666: my $endstring = '';
1667:
1668: my $align = lc(&Apache::lonxml::get_param('align', $parstack,
1669: $safeeval, undef, 1));
1670: if ($align eq 'center') {
1671: $currentstring .= '\begin{center}';
1672: $endstring = '\end{center}';
1673: if (&is_inside_of($tagstack, "table")) {
1674: $currentstring = ¢er_correction().$currentstring;
1675: $endstring .= ¢er_end_correction();
1676: }
1677: }
1678: elsif ($align eq 'right') {
1679: $currentstring .= '\begin{flushright}';
1680: $endstring .= '\end{flushright}';
1681: } elsif ($align eq 'left') {
1682: $currentstring .= '\begin{flushleft}';
1683: $endstring = '\end{flushleft}';
1684: } else {
1685:
1686: }
1687: $currentstring .= "\n"; # For human readability.
1688: $endstring = "\n$endstring\n"; # For human readability
1689: push(@div_end_stack, $endstring);
1690: }
1691: return $currentstring;
1692: }
1693:
1694: sub end_div {
1695: my ($target,$token) = @_;
1696: my $currentstring = '';
1697: if ($target eq 'web' || $target eq 'webgrade') {
1698: $currentstring .= $token->[2];
1699: }
1700: if ($target eq 'tex') {
1701: my $endstring = pop @div_end_stack;
1702: $currentstring .= $endstring;
1703: }
1704: return $currentstring;
1705: }
1706: }
1707:
1708: #-- <a> tag (end tag required)
1709: sub start_a {
1710: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1711: my $currentstring = '';
1712: if ($target eq 'web' || $target eq 'webgrade') {
1713: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
1714: undef,1);
1715: $currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href});
1716: if ($href =~ /\S/) {
1717: if ($href !~ m{^https?://}) {
1718: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
1719: my $linkurl;
1720: if ($href =~ m{^/uploaded/}) {
1721: $linkurl = $href;
1722: } elsif ($href =~ m{^[^/]}) {
1723: my $path = $url;
1724: $path =~ s{[^/]*$}{};
1725: $linkurl = $path.$href;
1726: }
1727: if ($linkurl =~ m{^/uploaded/}) {
1728: if (!&Apache::lonnet::allowed('bre',$linkurl)) {
1729: if (&Apache::lonnet::is_on_map($url)) {
1730: &Apache::lonxml::extlink($linkurl);
1731: } elsif ($env{'request.course.id'}) {
1732: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1733: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1734: if ($linkurl =~ m{^([^/]|/uploaded/$cdom/$cnum/docs/)}) {
1735: my $cleanhref = &clean_docs_httpref($linkurl,$url,$cdom,$cnum);
1736: if ($cleanhref) {
1737: &Apache::lonxml::extlink($cleanhref);
1738: }
1739: }
1740: }
1741: }
1742: }
1743: }
1744: }
1745: }
1746: return $currentstring;
1747: }
1748:
1749: sub end_a {
1750: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1751: my $currentstring = '';
1752: if ($target eq 'web' || $target eq 'webgrade') {
1753: $currentstring .= $token->[2];
1754: }
1755: if ($target eq 'tex') {
1756: my $href =
1757: &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1758: my $name =
1759: &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1760: my $uriprint =
1761: &Apache::lonxml::get_param('uriprint',$parstack,$safeeval,undef,1);
1762: my $anchorprint =
1763: &Apache::lonxml::get_param('anchorprint',$parstack,$safeeval,undef,1);
1764: if (($href =~ /\S/) && ($uriprint=~/^on|uriprint|yes|1$/i)) {
1765: $href =~ s/([^\\])%/$1\\\%/g;
1766: # Substitute special symbols... and allow line breaks at each /
1767: #
1768: $href = &Apache::lonxml::latex_special_symbols($href);
1769: $href =~ s/\//\/\\-/g; # Map / to /\- to allow hyphenation.
1770: $currentstring .= ' ({\tt URI:'.$href.'})';
1771: } elsif (($name =~ /\S/) && ($anchorprint=~/^on|anchorprint|yes|1$/i)) {
1772: $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})';
1773: } else {
1774: $currentstring.='';
1775: }
1776: }
1777: return $currentstring;
1778: }
1779:
1780: #-- <li> tag (end tag optional)
1781: sub start_li {
1782: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1783: my $currentstring = '';
1784: if ($target eq 'web' || $target eq 'webgrade') {
1785: $currentstring = $token->[4];
1786: } elsif ($target eq 'tex') {
1787: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1788: my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
1789: #FIXME need to support types i and I
1790: if ($type=~/disc/) {
1791: $currentstring .= ' \item[$\bullet$] ';
1792: } elsif ($type=~/circle/) {
1793: $currentstring .= ' \item[$\circ$] ';
1794: } elsif ($type=~/square/) {
1795: $currentstring .= ' \item[$\diamond$] ';
1796: } elsif ($type eq '1') {
1797: $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
1798: } elsif ($type eq 'A') {
1799: $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
1800: } elsif ($type eq 'a') {
1801: $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]';
1802: } elsif ($value ne '') {
1803: $currentstring .= ' \item['.$value.'] ';
1804: } else {
1805: $currentstring .= ' \item ';
1806: }
1807: $Apache::londefdef::list_index++;
1808: }
1809: return $currentstring;
1810: }
1811:
1812: sub end_li {
1813: my ($target,$token) = @_;
1814: my $currentstring = &end_p(); # In case there's a <p> in the <li>
1815: if ($target eq 'web' || $target eq 'webgrade') {
1816: $currentstring .= $token->[2];
1817: }
1818: return $currentstring;
1819: }
1820:
1821: #-- <u> tag (end tag required)
1822: sub start_u {
1823: my ($target,$token) = @_;
1824: my $currentstring = '';
1825: if ($target eq 'web' || $target eq 'webgrade') {
1826: $currentstring .= $token->[4];
1827: } elsif ($target eq 'tex') {
1828: &Apache::lonxml::startredirection();
1829: }
1830: return $currentstring;
1831: }
1832:
1833: sub end_u {
1834: my ($target,$token) = @_;
1835: my $currentstring = '';
1836: if ($target eq 'web' || $target eq 'webgrade') {
1837: $currentstring .= $token->[2];
1838: } elsif ($target eq 'tex') {
1839: $currentstring=&Apache::lonxml::endredirection();
1840: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1841: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1842: $currentstring=~s/(\S)\s*$/$1\}/;
1843: }
1844: return $currentstring;
1845: }
1846:
1847: #-- <ul> tag (end tag required)
1848: sub start_ul {
1849: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1850: my $currentstring = &end_p(); # Close off enclosing list.
1851: if ($target eq 'web' || $target eq 'webgrade') {
1852: $currentstring .= $token->[4];
1853: } elsif ($target eq 'tex') {
1854: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1855: $Apache::londefdef::list_index=0;
1856: if ($TeXtype eq 'disc') {
1857: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
1858: '\renewcommand{\labelitemii}{$\bullet$}'.
1859: '\renewcommand{\labelitemiii}{$\bullet$}'.
1860: '\renewcommand{\labelitemiv}{$\bullet$}';
1861: } elsif ($TeXtype eq 'circle') {
1862: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
1863: '\renewcommand{\labelitemii}{$\circ$}'.
1864: '\renewcommand{\labelitemiii}{$\circ$}'.
1865: '\renewcommand{\labelitemiv}{$\circ$}';
1866: } elsif ($TeXtype eq 'square') {
1867: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
1868: '\renewcommand{\labelitemii}{$\diamond$}'.
1869: '\renewcommand{\labelitemiii}{$\diamond$}'.
1870: '\renewcommand{\labelitemiv}{$\diamond$}';
1871: }
1872: $currentstring .= '\strut \begin{itemize}';
1873: }
1874: return $currentstring;
1875: }
1876:
1877: sub end_ul {
1878: my ($target,$token) = @_;
1879: my $currentstring = '';
1880: if ($target eq 'web' || $target eq 'webgrade') {
1881: $currentstring = $token->[2];
1882: } elsif ($target eq 'tex') {
1883: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
1884: '\renewcommand{\labelitemii}{$\bullet$}'.
1885: '\renewcommand{\labelitemiii}{$\bullet$}'.
1886: '\renewcommand{\labelitemiv}{$\bullet$}\strut ';
1887: }
1888: return $currentstring;
1889: }
1890:
1891: #-- <menu> tag (end tag required)
1892: sub start_menu {
1893: my ($target,$token) = @_;
1894: my $currentstring = '';
1895: if ($target eq 'web' || $target eq 'webgrade') {
1896: $currentstring = $token->[4];
1897: } elsif ($target eq 'tex') {
1898: $currentstring = " \\begin{itemize} ";
1899: }
1900: return $currentstring;
1901: }
1902:
1903: sub end_menu {
1904: my ($target,$token) = @_;
1905: my $currentstring = '';
1906: if ($target eq 'web' || $target eq 'webgrade') {
1907: $currentstring = $token->[2];
1908: } elsif ($target eq 'tex') {
1909: $currentstring = " \\end{itemize}";
1910: }
1911: return $currentstring;
1912: }
1913:
1914: #-- <dir> tag (end tag required)
1915: sub start_dir {
1916: my ($target,$token) = @_;
1917: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1918: if ($target eq 'web' || $target eq 'webgrade') {
1919: $currentstring .= $token->[4];
1920: } elsif ($target eq 'tex') {
1921: $currentstring .= " \\begin{itemize} ";
1922: }
1923: return $currentstring;
1924: }
1925:
1926: sub end_dir {
1927: my ($target,$token) = @_;
1928: my $currentstring = '';
1929: if ($target eq 'web' || $target eq 'webgrade') {
1930: $currentstring = $token->[2];
1931: } elsif ($target eq 'tex') {
1932: $currentstring = " \\end{itemize}";
1933: }
1934: return $currentstring;
1935: }
1936:
1937: #-- <ol> tag (end tag required)
1938: sub start_ol {
1939: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1940: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1941: if ($target eq 'web' || $target eq 'webgrade') {
1942: $currentstring .= $token->[4];
1943: } elsif ($target eq 'tex') {
1944: $Apache::londefdef::list_index=0;
1945: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1946: if ($type eq '1') {
1947: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1948: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1949: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1950: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1951: } elsif ($type eq 'A') {
1952: $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
1953: '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
1954: '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
1955: '\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1956: } elsif ($type eq 'a') {
1957: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
1958: '\renewcommand{\labelenumii}{\alph{enumii}.}'.
1959: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
1960: '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
1961: } elsif ($type eq 'i') {
1962: $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'.
1963: '\renewcommand{\labelenumii}{\roman{enumii}.}'.
1964: '\renewcommand{\labelenumiii}{\roman{enumiii}.}'.
1965: '\renewcommand{\labelenumiv}{\roman{enumiv}.}';
1966: } elsif ($type eq 'I') {
1967: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
1968: '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
1969: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
1970: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
1971: }
1972: $currentstring .= '\strut \begin{enumerate}';
1973: }
1974: return $currentstring;
1975: }
1976:
1977: sub end_ol {
1978: my ($target,$token) = @_;
1979: my $currentstring = '';
1980: if ($target eq 'web' || $target eq 'webgrade') {
1981: $currentstring = $token->[2];
1982: } elsif ($target eq 'tex') {
1983: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1984: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1985: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1986: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
1987: }
1988: return $currentstring;
1989: }
1990:
1991: #-- <dl> tag (end tag required)
1992: sub start_dl {
1993: my ($target,$token) = @_;
1994: my $currentstring = &end_p(); # In case there's a <p> unclosed prior to the list.
1995: if ($target eq 'web' || $target eq 'webgrade') {
1996: $currentstring .= $token->[4];
1997: } elsif ($target eq 'tex') {
1998: $currentstring .= '\begin{description}';
1999: $Apache::londefdef::DL++;
2000: push(@Apache::londefdef::description,[]);
2001: $Apache::londefdef::DD[$Apache::londefdef::DL]=0;
2002: $Apache::londefdef::DT[$Apache::londefdef::DL]=0;
2003: $Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
2004: }
2005: return $currentstring;
2006: }
2007:
2008: sub end_dl {
2009: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2010: my $currentstring = '';
2011: if ($target eq 'web' || $target eq 'webgrade') {
2012: $currentstring = $token->[2];
2013: } elsif ($target eq 'tex') {
2014: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2015: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
2016: foreach my $element (@{$Apache::londefdef::description[-1]}) {
2017: $currentstring.=' '.$element.' ';
2018: }
2019: pop(@Apache::londefdef::description);
2020: $currentstring.='\end{description}';
2021: delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
2022: delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
2023: delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
2024: $Apache::londefdef::DL--;
2025: }
2026: return $currentstring;
2027: }
2028:
2029: #-- <dt> tag (end tag optional)
2030: sub start_dt {
2031: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2032: my $currentstring='';
2033: if ($target eq 'web' || $target eq 'webgrade') {
2034: $currentstring = $token->[4];
2035: } elsif ($target eq 'tex') {
2036: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2037: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
2038: &Apache::lonxml::startredirection();
2039: $Apache::londefdef::DT[-1]++;
2040: $Apache::londefdef::seenDT[-1]=1;
2041: }
2042: return $currentstring;
2043: }
2044:
2045: sub end_dt {
2046: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2047: my $currentstring = '';
2048: if ($target eq 'web' || $target eq 'webgrade') {
2049: $currentstring = $token->[2];
2050: } elsif ($target eq 'tex') {
2051: if ($Apache::londefdef::DT[-1]) {
2052: my $data=&item_cleanup();
2053: push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
2054: $Apache::londefdef::DT[-1]--;
2055: }
2056: }
2057: return $currentstring;
2058: }
2059:
2060: sub item_cleanup {
2061: my $item=&Apache::lonxml::endredirection();
2062: $item=~s/\\begin{center}//g;
2063: $item=~s/\\end{center}//g;
2064: return $item;
2065: }
2066:
2067: #-- <dd> tag (end tag optional)
2068: sub start_dd {
2069: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2070: my $currentstring = '';
2071: if ($target eq 'web' || $target eq 'webgrade') {
2072: $currentstring = $token->[4];
2073: } elsif ($target eq 'tex') {
2074: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2075: if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
2076: if (!$Apache::londefdef::seenDT[-1]) {
2077: push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
2078: }
2079: push(@{$Apache::londefdef::description[-1]},'');
2080: $Apache::londefdef::description[-1]->[-1].=' \strut ';
2081: $Apache::londefdef::DD[-1]++;
2082: &Apache::lonxml::startredirection();
2083: }
2084: return $currentstring;
2085: }
2086:
2087: sub end_dd {
2088: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2089: my $currentstring = '';
2090: if ($target eq 'web' || $target eq 'webgrade') {
2091: $currentstring = $token->[2];
2092: } elsif ($target eq 'tex') {
2093: $Apache::londefdef::description[-1]->[-1].=
2094: &Apache::lonxml::endredirection().' \vskip 0mm ';
2095: $Apache::londefdef::DD[-1]--;
2096: }
2097: return $currentstring;
2098: }
2099:
2100: #-- <table> tag (end tag required)
2101: # <table> also ends any prior <p> that is not closed.
2102: # but, unless I allow <p>'s to nest, that's the
2103: # only way I could think of to allow <p> in
2104: # <tr> <th> bodies
2105: #
2106: #list of supported attributes: border,width,TeXwidth,TeXtheme
2107: # align
2108: sub start_table {
2109: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2110: my $textwidth = '';
2111: my $currentstring = &end_p();
2112: if ($target eq 'web' || $target eq 'webgrade') {
2113: $currentstring .= $token->[4];
2114: } elsif ($target eq 'tex') {
2115: &disable_para(); # Can't have paras in a table.
2116:
2117: # Get the parameters that we can do something about:
2118:
2119: my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
2120: my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
2121: my $theme = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
2122: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
2123: my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);
2124:
2125: # The only thing that needs any figuring out is the width.. and then only if it is
2126: # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
2127: #
2128:
2129: my $table = new Apache::lontable();
2130: if ((defined $border) && ($border > 0)) {
2131: # &Apache::lonnet::logthis("Turning on table borders: $border");
2132: $table->table_border(1);
2133: if (!defined $cell_border) {
2134: $table->cell_border(1); # Default for rules is all if rules not defined.
2135: }
2136: }
2137:
2138: if ((defined $cell_border)) {
2139: if ($cell_border eq 'all') {
2140: $table->cell_border(1);
2141: } elsif ($cell_border eq 'rows') {
2142: $table->cell_border(2);
2143: } elsif ($cell_border eq 'cols') {
2144: $table->cell_border(3);
2145: } elsif($cell_border eq 'groups') {
2146: $table->cell_border(4);
2147: } else {
2148: $table->cell_border(0);
2149: }
2150: }
2151: if (defined $theme) {
2152: $table->theme($theme);
2153: }
2154: if (defined $align) {
2155: $table->alignment($align);
2156: }
2157:
2158: # Missing width is most of page width
2159:
2160: if (!(defined $width)) {
2161: $width = '70%';
2162: }
2163:
2164: # If a percentage, need to calculate what this means in terms of
2165: # page width:
2166:
2167: if ($width =~ /%$/) {
2168: my $textwidth = &recalc($env{'form.textwidth'}); # Page width in mm.
2169: $width =~ s/%//;
2170: $width = $width * $textwidth / 100.0;
2171: $width .= " mm";
2172: $table->width($width);
2173: }
2174:
2175: push(@Apache::londefdef::table, $table);
2176: $currentstring.=' \keephidden{NEW TABLE ENTRY}';
2177:
2178: }
2179: return $currentstring;
2180: }
2181:
2182: sub end_table {
2183: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2184: my $currentstring = '';
2185: if ($target eq 'web' || $target eq 'webgrade') {
2186: $currentstring = $token->[2];
2187: } elsif ($target eq 'tex') {
2188:
2189:
2190: my $table = pop(@Apache::londefdef::table);
2191: my $t = $table->generate();
2192: # &Apache::lonnet::logthis("Generating string");
2193: $currentstring = $t->generate_string();
2194: # &Apache::lonnet::logthis("Generated: $currentstring");
2195: &enable_para();
2196:
2197: }
2198: return $currentstring;
2199: }
2200:
2201: #-- <tr> tag (end tag optional)
2202: sub start_tr {
2203: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2204: my $currentstring = '';
2205: if ($target eq 'web' || $target eq 'webgrade') {
2206: $currentstring = $token->[4];
2207: } elsif ($target eq 'tex') {
2208:
2209: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
2210: $Apache::londefdef::table[-1]->start_row();
2211:
2212: if ($align ne '') {
2213: $Apache::londefdef::table[-1]->configure_row({default_halign => $align});
2214: }
2215:
2216: #---------------------------------------------------------------
2217: # Old table code.
2218: #---------------------------------------------------------------
2219:
2220: if (0) {
2221: $Apache::londefdef::table[-1]{'row_number'}++;
2222: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
2223: if ($alignchar ne '') {
2224: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
2225: } else {
2226: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2227: }
2228: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2229: #
2230: # Need to save the number of table columns to preserve the max # columns.
2231: #
2232: $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
2233: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
2234: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2235: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2236: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2237: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2238: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
2239: }
2240: }
2241: return $currentstring;
2242: }
2243:
2244: sub end_tr {
2245: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2246: my $currentstring = &end_p(); # Close any pending <p> in the row.
2247: if ($target eq 'web' || $target eq 'webgrade') {
2248: $currentstring .= $token->[2];
2249: } elsif ($target eq 'tex') {
2250:
2251: # In case the user is missing a </td> or </th> tag:
2252:
2253: if ($Apache::londefdef::TD_redirection) {
2254: &end_td_tex($parstack,$parser,$safeeval);
2255: }
2256: $Apache::londefdef::table[-1]->end_row();
2257:
2258: #-----------------------------------------------
2259: # Old table code
2260: #-----------------------------------------------
2261:
2262: if (0) {
2263: if ($Apache::londefdef::TD_redirection) {
2264: &end_td_tex($parstack,$parser,$safeeval);
2265: }
2266: # Counter columns must be the maximum number of columns seen
2267: # in the table so far so:
2268: if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
2269: $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
2270: }
2271: }
2272:
2273:
2274: }
2275: return $currentstring;
2276: }
2277:
2278: #-- <td> tag (end tag optional)
2279: sub start_td {
2280: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2281: my $currentstring = '';
2282: if ($target eq 'web' || $target eq 'webgrade') {
2283: $currentstring = $token->[4];
2284: } elsif ($target eq 'tex') {
2285: $Apache::londefdef::TD_redirection = 1;
2286: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
2287: }
2288: return $currentstring;
2289: }
2290:
2291: sub tag_check {
2292: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2293: my @ar=@$parstack;
2294: for (my $i=$#ar-1;$i>=0;$i--) {
2295: if (lc($$tagstack[$i]) eq $good_tag) {
2296: &start_td_tex($parstack,$parser,$safeeval);
2297: last;
2298: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2299: splice @ar, $i+1;
2300: &end_td_tex(\@ar,$parser,$safeeval);
2301: &start_td_tex($parstack,$parser,$safeeval);
2302: last;
2303: }
2304: }
2305: return '';
2306: }
2307:
2308: #
2309: # Factor out cell configuration hash generation:
2310: #
2311:
2312: sub cell_config_hash {
2313: my ($align, $rowspan, $colspan, $width) = @_;
2314: if ($rowspan ne '') {
2315: $rowspan =~ s/^\s+|\s+$//g;
2316: }
2317: if ($colspan ne '') {
2318: $colspan =~ s/^\s+|\s+$//g;
2319: }
2320: my %config;
2321: if ($align ne '') {
2322: $config{'halign'} = $align;
2323: }
2324: if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
2325: $config{'colspan'} = $colspan;
2326: }
2327: if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
2328: $config{'rowspan'} = $rowspan;
2329: }
2330: if ($width ne '') {
2331: $config{'width'} = $width;
2332: }
2333: return \%config;
2334: }
2335:
2336: sub start_td_tex {
2337: my ($parstack,$parser,$safeeval) = @_;
2338:
2339: # At this stage, an empty cell is created with the
2340: # appropriate rowspan/colspan and alignment
2341: # attributes, but empty of text. end_td_tex will
2342: # fetch the contents from the recursive parse and
2343: # fill the cell with them:
2344: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval);
2345: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
2346: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
2347: my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
2348: my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
2349:
2350: my $table = $Apache::londefdef::table[-1];
2351: $table->add_cell('', $config);
2352:
2353:
2354: #------------------------------------------------
2355: # Old table code.
2356: #------------------------------------------------
2357:
2358: if (0) {
2359:
2360: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2361: if ($alignchar eq '') {
2362: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2363: }
2364: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2365: $Apache::londefdef::table[-1]{'counter_columns'}++;
2366: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2367: if (defined $TeXwidth) {
2368: my $current_length=&recalc($TeXwidth);
2369: $current_length=~/(\d+\.?\d*)/;
2370: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2371: }
2372: }
2373: &Apache::lonxml::startredirection();
2374: return '';
2375: }
2376:
2377: sub end_td_tex {
2378:
2379: my $text = &Apache::lonxml::endredirection();
2380: my $table = $Apache::londefdef::table[-1];
2381: $table->append_cell_text($text);
2382:
2383: #-------------------------------------------------
2384: # Old table code
2385: #-------------------------------------------------
2386:
2387: if (0) {
2388: my ($parstack,$parser,$safeeval) = @_;
2389: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2390: my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
2391: my $data = &Apache::lonxml::endredirection();
2392:
2393: # The rowspan array of the table indicates which cells are part of a span.
2394: # n indicates the start of a span set of n rows.
2395: # ^ indicates a cell that continues a span set.
2396: # _ indicates the cell is at the bottom of a span set.
2397: # If this and subsequent cells are part of a rowspan, we must
2398: # push along the row until we find one that is not.
2399:
2400: while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
2401: && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
2402: # Part of a span.
2403: push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
2404: $current_column++;
2405: }
2406: $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
2407:
2408:
2409: # Get the column and row spans.
2410: # Colspan can be done via \multicolumn if I can figure out the data structs.
2411:
2412: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
2413: if (!$colspan) {
2414: $colspan = 1;
2415: }
2416:
2417: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
2418: if (!$rowspan) {
2419: $rowspan = 1;
2420: }
2421:
2422:
2423:
2424: for (my $c = 0; $c < $colspan; $c++) {
2425: $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
2426: for (my $i = 1; $i < $rowspan; $i++) {
2427: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
2428: if ($i == ($rowspan-1)) {
2429: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
2430: }
2431: }
2432: }
2433:
2434: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2435: if (defined $TeXwidth) {
2436: for (my $c = 0; $c < $colspan; $c++) {
2437: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2438: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2439: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2440: }
2441: } else {
2442: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2443: my $garbage_data=$data;
2444: my $fwidth=0;
2445: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2446: my $current_length=&recalc($1);
2447: $current_length=~/(\d+\.?\d*)/;
2448: if ($fwidth<$1) {$fwidth=$1;}
2449: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2450: }
2451: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2452: my $current_length=$1;
2453: if ($fwidth<$current_length) {$fwidth=$current_length;}
2454: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2455: }
2456: for (my $c = 0; $c < $colspan; $c++) {
2457: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2458: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2459: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2460: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2461: }
2462: } elsif ($data=~/\\parbox\{\s*\d+\.?\d*\s*(mm|cm|in|pc|pt)*\s*\}/ or $data=~/\\epsfxsize\s*=\s*\d+\.?\d*\s*(mm|cm|in|pc|pt)*/) {
2463: my $garbage_data=$data;
2464: my $fwidth=0;
2465: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2466: my $current_length=&recalc($1);
2467: $current_length=~/(\d+\.?\d*)/;
2468: if ($fwidth<$1) {$fwidth=$1;}
2469: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2470: }
2471: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2472: my $current_length=&recalc($1);
2473: $current_length=~/(\d+\.?\d*)/;
2474: if ($fwidth<$1) {$fwidth=$1;}
2475: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2476: }
2477: for (my $c = 0; $c < $colspan; $c++) {
2478: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2479: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2480: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2481: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2482: }
2483: $data=~s/\\\\\s*$//;
2484: } else {
2485: $data=~s/^\s+(\S.*)/$1/;
2486: $data=~s/(.*\S)\s+$/$1/;
2487: $data=~s/(\s)+/$1/;
2488: my ($current_length,$min_length)=(0,0);
2489: if ($data=~/\\vskip/) {
2490: my $newdata=$data;
2491: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2492: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2493: foreach my $elementdata (@newdata) {
2494: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2495: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2496: my @words=split(/ /,$elementdata);
2497: foreach my $word (@words) {
2498: my $lengthword=2.5*&LATEX_length($word);
2499: if ($min_length<$lengthword) {$min_length=$lengthword;}
2500: }
2501: }
2502: } else {
2503: $current_length=2.5*&LATEX_length($data);
2504: my @words=split(/ /,$data);
2505: foreach my $word (@words) {
2506: my $lengthword=2*&LATEX_length($word);
2507: if ($min_length<$lengthword) {$min_length=$lengthword;}
2508: }
2509: }
2510: for (my $c = 0; $c < $colspan; $c++) {
2511: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2512: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2513: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2514: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2515: }
2516: }
2517: }
2518: # Substitute all of the tables nested in this cell in their appropriate places.
2519:
2520:
2521: my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
2522: for (my $in=0; $in<=$nested_count; $in++) {
2523: my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
2524: $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
2525: # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2526: $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
2527:
2528: }
2529: # Should be be killing off the 'include' elements as they're used up?
2530:
2531: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2532:
2533:
2534:
2535:
2536: # the colspan array will indicate how many columns will be spanned by this
2537: # cell..this requires that counter_columns also be adjusted accordingly
2538: # so that the next bunch of text goes in the right cell. Note that since
2539: # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
2540: #
2541:
2542: $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
2543: for (my $i = 0; $i < ($colspan -1); $i++) {
2544: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
2545: }
2546: for (my $r = 0; $r < $rowspan; $r++) {
2547: $Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
2548: # Put empty text in spanned cols.
2549:
2550: }
2551:
2552: }
2553:
2554: return '';
2555: }
2556:
2557: sub end_td {
2558: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2559: my $currentstring = '';
2560: if ($target eq 'web' || $target eq 'webgrade') {
2561: $currentstring = $token->[2];
2562: } elsif ($target eq 'tex') {
2563: $Apache::londefdef::TD_redirection =0;
2564: &end_td_tex($parstack,$parser,$safeeval);
2565: }
2566: return $currentstring;
2567: }
2568:
2569: #-- <th> tag (end tag optional)
2570: sub start_th {
2571: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2572: my $currentstring = '';
2573: if ($target eq 'web' || $target eq 'webgrade') {
2574: $currentstring = $token->[4];
2575: } elsif ($target eq 'tex') {
2576: $Apache::londefdef::TD_redirection = 1;
2577: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
2578: }
2579: return $currentstring;
2580: }
2581:
2582: sub tagg_check {
2583: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2584: my @ar=@$parstack;
2585: for (my $i=$#ar-1;$i>=0;$i--) {
2586: if (lc($$tagstack[$i]) eq $good_tag) {
2587: &start_th_tex($parstack,$parser,$safeeval);
2588: last;
2589: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2590: splice @ar, $i+1;
2591: &end_th_tex(\@ar,$parser,$safeeval);
2592: &start_th_tex($parstack,$parser,$safeeval);
2593: last;
2594: }
2595: }
2596: return '';
2597: }
2598:
2599: sub start_th_tex {
2600: my ($parstack,$parser,$safeeval) = @_;
2601:
2602: my $alignment = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef,1);
2603: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
2604: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
2605:
2606: my $config = cell_config_hash($alignment, $rowspan, $colspan);
2607: my $table = $Apache::londefdef::table[-1];
2608: $table->add_cell('\textbf{', $config);
2609:
2610: #-------------------------------------------------------------------------------------
2611: #
2612: # Old table code.
2613: #
2614: #--------------------------------------------------------------------------------------
2615:
2616: if (0) {
2617:
2618:
2619: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2620: if ($alignchar eq '') {
2621: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2622: }
2623: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2624: $Apache::londefdef::table[-1]{'counter_columns'}++;
2625: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2626: if (defined $TeXwidth) {
2627: my $current_length=&recalc($TeXwidth);
2628: $current_length=~/(\d+\.?\d*)/;
2629: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2630: }
2631: }
2632:
2633: # Accept xml until the </th> tag.
2634:
2635: &Apache::lonxml::startredirection();
2636: return '';
2637: }
2638:
2639: sub end_th_tex {
2640: my ($parstack,$parser,$safeeval) = @_;
2641:
2642: my $table = $Apache::londefdef::table[-1];
2643: my $text = &Apache::lonxml::endredirection();
2644: $table->append_cell_text($text.'}');
2645:
2646: #-----------------------------------------------------------------------------
2647: # Old table code:
2648: #-----------------------------------------------------------------------------
2649:
2650: if (0) {
2651: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2652: my $data=&Apache::lonxml::endredirection();
2653: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2654: if (defined $TeXwidth) {
2655: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2656: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2657: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2658: } else {
2659: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2660: my $garbage_data=$data;
2661: my $fwidth=0;
2662: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2663: my $current_length=&recalc($1);
2664: $current_length=~/(\d+\.?\d*)/;
2665: if ($fwidth<$1) {$fwidth=$1;}
2666: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2667: }
2668: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2669: my $current_length=$1;
2670: if ($fwidth<$current_length) {$fwidth=$current_length;}
2671: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2672: }
2673: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2674: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2675: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2676: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2677: } else {
2678: $data=~s/^\s+(\S.*)/$1/;
2679: $data=~s/(.*\S)\s+$/$1/;
2680: $data=~s/(\s)+/$1/;
2681: my ($current_length,$min_length)=(0,0);
2682: if ($data=~/\\vskip/) {
2683: my $newdata=$data;
2684: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2685: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2686: foreach my $elementdata (@newdata) {
2687: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2688: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2689: my @words=split(/ /,$elementdata);
2690: foreach my $word (@words) {
2691: my $lengthword=2.5*&LATEX_length($word);
2692: if ($min_length<$lengthword) {$min_length=$lengthword;}
2693: }
2694: }
2695: } else {
2696: $current_length=2.5*&LATEX_length($data);
2697: my @words=split(/ /,$data);
2698: foreach my $word (@words) {
2699: my $lengthword=2*&LATEX_length($word);
2700: if ($min_length<$lengthword) {$min_length=$lengthword;}
2701: }
2702: }
2703: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2704: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2705: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2706: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2707: }
2708: }
2709: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2710: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2711: }
2712: #make data bold
2713: $data='\textbf{'.$data.'}';
2714: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2715: }
2716: return'';
2717: }
2718:
2719: sub end_th {
2720: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2721: my $currentstring = &end_p(); # Close any open <p> in the row.
2722: if ($target eq 'web' || $target eq 'webgrade') {
2723: $currentstring .= $token->[2];
2724: } elsif ($target eq 'tex') {
2725: $Apache::londefdef::TD_redirection =0;
2726: &end_th_tex($parstack,$parser,$safeeval);
2727: }
2728: return $currentstring;
2729: }
2730:
2731: #-- <img> tag (end tag forbidden)
2732: #
2733: # Render the <IMG> tag.
2734: # <IMG> has the following attributes (in addition to the
2735: # standard HTML ones:
2736: # TeXwrap - Governs how the tex target will try to wrap text around
2737: # horizontally aligned images.
2738: # TeXwidth - The width of the image when rendered for print (mm).
2739: # TeXheight - The height of the image when rendered for print (mm)
2740: # (Note there seems to also be support for this as a % of page size)
2741: #
2742: sub start_img {
2743: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
2744: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2745: undef,1);
2746: if (! $src &&
2747: ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
2748: ) {
2749: my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
2750: return '';
2751: }
2752: &Apache::lonxml::extlink($src);
2753: my $currentstring = '';
2754: my $scaling = .3;
2755:
2756: # Render unto browsers that which are the browser's...
2757:
2758: if ($target eq 'web' || $target eq 'webgrade') {
2759: my $enc = ('yes' eq
2760: lc(&Apache::lonxml::get_param('encrypturl',$parstack,
2761: $safeeval)));
2762: $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
2763: $enc);
2764:
2765: # and render unto TeX that which is LaTeX
2766: } elsif ($target eq 'tex') {
2767: #
2768: # The alignment will require some superstructure to be put around
2769: # the \includegraphics stuff. At present we can only partially
2770: # simulate the alignments offered by html.
2771: #
2772: #
2773: my $align = lc(&Apache::lonxml::get_param('align',
2774: $parstack,
2775: $safeeval,
2776: undef,1));
2777: if(!$align) {
2778: $align = "bottom"; # This is html's default so it's ours too.
2779: }
2780: #
2781: &Apache::lonxml::debug("Alignemnt = $align");
2782: # LaTeX's image/text wrapping is really bad since it wants to
2783: # make figures float.
2784: # The user has the optional parameter (applicable only to l/r
2785: # alignment to use the picins/parpic directive to get wrapped text
2786: # this is also imperfect.. that's why we give them a choice...
2787: # so they can't yell at us for our choice.
2788: #
2789: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
2790: $parstack,
2791: $safeeval,
2792: undef,0);
2793: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
2794: if(!$latex_rendering) {
2795: $latex_rendering = "texwrap";
2796: }
2797: # using texwrap inside a table does not work. So, if after all of this,
2798: # texwrap is on, we turn it off if we detect we're in a table:
2799: #
2800: if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
2801: $latex_rendering = 'parpic';
2802: }
2803:
2804: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
2805:
2806: #if original bmp/gif/jpg/png file exist do following:
2807: my $origsrc=$src;
2808: my ($path,$file) = &get_eps_image($src);
2809: # &Apache::lonnet::logthis("Image source: $src result: $path $file");
2810: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2811: &Apache::lonxml::debug("path = $path file = $file src = $src");
2812: if (-e $src) {
2813: &Apache::lonxml::debug("$src exists");
2814: my ($height_param,$width_param)=
2815: &image_size($origsrc,0.3,$parstack,$safeeval);
2816: my $size;
2817: if ($width_param) { $size.='width='.$width_param.' mm,'; }
2818: if ($height_param) { $size.='height='.$height_param.' mm]'; }
2819: # Default size if not able to extract that (e.g. eps image).
2820:
2821: # &Apache::lonnet::logthis("Size = $size");
2822:
2823: $size='['.$size;
2824: $size=~s/,$/]/;
2825: $currentstring .= '\graphicspath{{'.$path.'}}'
2826: .'\includegraphics'.$size.'{'.$file.'} ';
2827: my $closure;
2828: ($currentstring, $closure) = &align_latex_image($align,
2829: $latex_rendering,
2830: $currentstring,
2831: $width_param,
2832: $height_param);
2833: $currentstring .= $closure;
2834:
2835: } else {
2836: &Apache::lonxml::debug("$src does not exist");
2837: #original image file doesn't exist so check the alt attribute
2838: my $alt =
2839: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2840: unless ($alt) {
2841: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2842: }
2843:
2844: if ($alt) { $currentstring .= ' '.$alt.' '; }
2845: }
2846:
2847: # And here's where the semi-quote breaks down: allow the user
2848: # to edit the beast as well by rendering the problem for edit:
2849: } elsif ($target eq 'edit') {
2850: my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
2851: $currentstring .=&Apache::edit::tag_start($target,$token);
2852: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2853: &Apache::edit::browse('src',undef,'alt',$only).' '.
2854: &Apache::edit::search('src',undef,'alt').'<br />';
2855: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2856: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2857: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2858: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2859: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
2860: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2861: ['','bottom','middle','top','left','right'],$token,5);
2862: $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
2863: ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
2864: my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
2865: my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
2866:
2867: $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
2868: ['no','yes'], $token, 2);
2869: if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
2870: $currentstring.='<br /><span class="LC_warning">'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'</span><br />';
2871: }
2872: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2873: my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
2874: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
2875: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
2876:
2877: if ($token->[2]{'src'}=~/\$/) {
2878: $currentstring.=&mt('Variable image source');
2879: } elsif ($token->[2]{'src'}=~/\S/) {
2880: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2881: if ($width) { $currentstring.=' width="'.$width.'" '; }
2882: if ($height) { $currentstring.=' height="'.$height.'" '; }
2883: $currentstring .= ' />';
2884: } else {
2885: $currentstring.=&mt("No image source specified");
2886: }
2887: } elsif ($target eq 'modified') {
2888: my ($osrc,$owidth,$oheight)=
2889: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2890: my $ctag=&Apache::edit::get_new_args($token,$parstack,
2891: $safeeval,'src','alt','align',
2892: 'TeXwidth','TeXheight', 'TeXwrap',
2893: 'width','height','encrypturl');
2894: my ($nsrc,$nwidth,$nheight)=
2895: ($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
2896: my $loc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$nsrc);
2897: &image_replication($loc);
2898: my ($iwidth,$iheight);
2899: if (-e $loc) {
2900: my $image = Image::Magick->new;
2901: $image->Read($loc);
2902: ($iwidth, $iheight) = ($image->Get('width'),
2903: $image->Get('height'));
2904: }
2905: if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
2906: # changed image or no size specified,
2907: # if they didn't explicitly change the
2908: # width or height use the ones from the image
2909: if ($iwidth && $iheight) {
2910: if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
2911: $token->[2]{'width'} = $iwidth;$ctag=1;
2912: }
2913: if ($oheight == $nheight || (!$nwidth && !$nheight)) {
2914: $token->[2]{'height'}=$iheight;$ctag=1;
2915: }
2916: }
2917: }
2918: my ($cwidth,$cheight)=($token->[2]{'width'},$token->[2]{'height'});
2919: # if we don't have a width or height
2920: if ($iwidth && $cwidth && !$cheight) {
2921: $token->[2]{'height'}=int(($cwidth/$iwidth)*$iheight);$ctag=1;
2922: }
2923: if ($iheight && $cheight && !$cwidth) {
2924: $token->[2]{'width'}=int(($cheight/$iheight)*$iwidth);$ctag=1;
2925: }
2926: if ($ctag) {$currentstring=&Apache::edit::rebuild_tag($token);}
2927: }
2928:
2929: return $currentstring;
2930: }
2931:
2932: sub end_img {
2933: my ($target,$token) = @_;
2934: my $currentstring = '';
2935: if ($target eq 'web' || $target eq 'webgrade') {
2936: $currentstring = $token->[2];
2937: } elsif ($target eq 'tex') {
2938: $currentstring = '';
2939: }
2940: return $currentstring;
2941: }
2942:
2943: #-- <applet> tag (end tag required)
2944: sub start_applet {
2945: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2946:
2947: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,undef,1);
2948: &Apache::lonxml::extlink($code);
2949: my $archive=&Apache::lonxml::get_param('archive',$parstack,$safeeval,
2950: undef,1);
2951: &Apache::lonxml::extlink($archive);
2952: my $currentstring = '';
2953: if ($target eq 'web' || $target eq 'webgrade') {
2954: $currentstring = $token->[4];
2955: } elsif ($target eq 'tex') {
2956: # Turn off some stuff we can't be inside thank you LaTeX
2957:
2958: my $restart_sub = 0;
2959: my $restart_sup = 0;
2960:
2961: # Since <sub> and <sup> are simple tags it's ok to turn off/on
2962: # using the start_ stop_ functions.. those tags only care about
2963: # $target.
2964:
2965: if (&is_inside_of($tagstack, "sub")) {
2966: $restart_sub = 1;
2967: $currentstring .= &end_sub($target, $token, $tagstack,
2968: $parstack, $parser, $safeeval);
2969: }
2970: if (&is_inside_of($tagstack, "sup")) {
2971: $restart_sup = 1;
2972: $currentstring .= &end_sup($target, $token, $tagstack,
2973: $parstack, $parser, $safeeval);
2974: }
2975:
2976: # Now process the applet; just replace it with its alt attribute.
2977:
2978: my $alttag= &Apache::lonxml::get_param('alt',$parstack,
2979: $safeeval,undef,1);
2980: unless ($alttag) {
2981: my $code=&Apache::lonxml::get_param('code',$parstack,$safeeval,
2982: undef,1);
2983: $alttag=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],
2984: $code);
2985: }
2986: $currentstring.='\begin{center} \fbox{Java Applet: '.$alttag.
2987: '.}\end{center}';
2988:
2989: # Turn stuff back on that we can't be inside of.
2990:
2991: if ($restart_sub) {
2992: $currentstring .= &start_sub($target, $token, $tagstack,
2993: $parstack, $parser, $safeeval);
2994: }
2995: if ($restart_sup) {
2996: $currentstring .= &start_sup($target, $token, $tagstack,
2997: $parstack, $parser, $safeeval);
2998: }
2999: }
3000: return $currentstring;
3001: }
3002:
3003: sub end_applet {
3004: my ($target,$token) = @_;
3005: my $currentstring = '';
3006: if ($target eq 'web' || $target eq 'webgrade') {
3007: $currentstring = $token->[2];
3008: } elsif ($target eq 'tex') {
3009: }
3010: return $currentstring;
3011: }
3012:
3013: #-- <embed> tag (end tag optional/required)
3014: sub start_embed {
3015: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3016: my $src=&Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3017: &Apache::lonxml::extlink($src);
3018: my $currentstring = '';
3019: if ($target eq 'web' || $target eq 'webgrade') {
3020: $currentstring=&Apache::lonenc::encrypt_ref($token,{'src'=>$src});
3021: } elsif ($target eq 'tex') {
3022: }
3023: return $currentstring;
3024: }
3025:
3026: sub end_embed {
3027: my ($target,$token) = @_;
3028: my $currentstring = '';
3029: if ($target eq 'web' || $target eq 'webgrade') {
3030: $currentstring = $token->[2];
3031: } elsif ($target eq 'tex') {
3032: # ./.
3033: }
3034: return $currentstring;
3035: }
3036:
3037: #-- <param> tag (end tag forbidden)
3038: sub start_param {
3039: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3040: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval,
3041: undef,1);
3042: if ($name =~/^cabbase$/i) {
3043: my $value=&Apache::lonxml::get_param('value',$parstack,
3044: $safeeval,undef,1);
3045: &Apache::lonxml::extlink($value);
3046: } elsif ($name eq 'flashvars') {
3047: if (lc(&Apache::lonxml::get_param('type',$parstack,$safeeval,-2,1))
3048: eq 'application/x-shockwave-flash') {
3049: my $launcher =
3050: &Apache::lonxml::get_param('data',$parstack,$safeeval,-2,1);
3051: if ($launcher) {
3052: &Apache::lonxml::extlink($launcher);
3053: }
3054: my $flashvars=&Apache::lonxml::get_param('value',$parstack,
3055: $safeeval,undef,1);
3056: if ($flashvars ne '') {
3057: foreach my $item (split(/\&/,$flashvars)) {
3058: my ($key,$value)=split(/=/,$item,2);
3059: if ($key eq 'content') {
3060: if ($value ne '') {
3061: my ($dir) = ($launcher =~ m{(.+/)[^/]+$});
3062: &Apache::lonxml::extlink($dir.$value);
3063: }
3064: } elsif ($key eq 'thumb') {
3065: if ($value ne '') {
3066: &Apache::lonxml::extlink($value);
3067: }
3068: }
3069: }
3070: }
3071: }
3072: }
3073: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3074: if ($src ne '') {
3075: &Apache::lonxml::extlink($src);
3076: }
3077: my $currentstring = '';
3078: if ($target eq 'web' || $target eq 'webgrade') {
3079: my %toconvert;
3080: if ($src) { $toconvert{'src'}= $src; }
3081: if ($name=~/^cabbase$/i) {
3082: $toconvert{'value'}=&Apache::lonxml::get_param('value',$parstack,
3083: $safeeval,undef,1);
3084: }
3085: $currentstring = &Apache::lonenc::encrypt_ref($token,\%toconvert);
3086: } elsif ($target eq 'tex') {
3087: }
3088: return $currentstring;
3089: }
3090:
3091: sub end_param {
3092: my ($target,$token) = @_;
3093: my $currentstring = '';
3094: if ($target eq 'web' || $target eq 'webgrade') {
3095: $currentstring = $token->[2];
3096: } elsif ($target eq 'tex') {
3097: }
3098: return $currentstring;
3099: }
3100:
3101: #-- <allow> tag
3102: sub start_allow {
3103: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3104: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,undef,1);
3105: &Apache::lonxml::extlink($src);
3106:
3107: if ($target eq 'tex') { &image_replication($src); }
3108: my $result;
3109: if ($target eq 'edit') {
3110: $result .=&Apache::edit::tag_start($target,$token);
3111: $result .=&Apache::edit::text_arg('File Spec:','src',$token,70);
3112: $result .=&Apache::edit::end_row();#.&Apache::edit::start_spanning_row();
3113: } elsif ($target eq 'modified') {
3114: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
3115: $safeeval,'src');
3116: if ($constructtag) { $result = &Apache::edit::rebuild_tag($token); }
3117: }
3118: return $result;
3119: }
3120:
3121: sub end_allow {
3122: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3123: if ( $target eq 'edit') { return (&Apache::edit::end_table()); }
3124: return '';
3125: }
3126:
3127: #-- Frames (end tag required)
3128: #-- <frameset>
3129: sub start_frameset {
3130: my ($target,$token) = @_;
3131: my $currentstring = ''; # Close any pending para.
3132: if ($target eq 'web' || $target eq 'webgrade') {
3133: $currentstring =
3134: &Apache::loncommon::start_page($Apache::londefdef::title,
3135: $Apache::londefdef::head,
3136: {'add_entries' => $token->[2],
3137: # 'no_title' => 1,
3138: 'force_register' => 1,
3139: 'frameset' => 1,});
3140:
3141: }
3142: return $currentstring;
3143: }
3144:
3145: sub end_frameset {
3146: my ($target,$token) = @_;
3147: my $currentstring = '';
3148: if ($target eq 'web' || $target eq 'webgrade') {
3149: $currentstring = $token->[2];
3150: }
3151: return $currentstring;
3152: }
3153:
3154: #-- <xmp> (end tag required)
3155: sub start_xmp {
3156: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3157: my $currentstring = '';
3158: if ($target eq 'web' || $target eq 'webgrade') {
3159: $currentstring .= $token->[4];
3160: } elsif ($target eq 'tex') {
3161: $currentstring .= '\begin{verbatim}';
3162: }
3163: return $currentstring;
3164: }
3165:
3166: sub end_xmp {
3167: my ($target,$token) = @_;
3168: my $currentstring = '';
3169: if ($target eq 'web' || $target eq 'webgrade') {
3170: $currentstring .= $token->[2];
3171: } elsif ($target eq 'tex') {
3172: $currentstring .= '\end{verbatim}';
3173: }
3174: return $currentstring;
3175: }
3176:
3177: #-- <pre> (end tag required)
3178: sub start_pre {
3179: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3180: my $currentstring = &end_p(); # close off pending <p>
3181: if ($target eq 'web' || $target eq 'webgrade') {
3182: $currentstring .= $token->[4];
3183: } elsif ($target eq 'tex') {
3184: $currentstring .= '\begin{verbatim}';
3185: &Apache::lonxml::disable_LaTeX_substitutions();
3186: }
3187: return $currentstring;
3188: }
3189:
3190: sub end_pre {
3191: my ($target,$token) = @_;
3192: my $currentstring = '';
3193: if ($target eq 'web' || $target eq 'webgrade') {
3194: $currentstring .= $token->[2];
3195: } elsif ($target eq 'tex') {
3196: $currentstring .= '\end{verbatim}';
3197: &Apache::lonxml::enable_LaTeX_substitutions();
3198: }
3199: return $currentstring;
3200: }
3201:
3202: #-- <insert>
3203: sub start_insert {
3204: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3205: my $currentstring = '';
3206: if ($target eq 'web' || $target eq 'webgrade') {
3207: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3208: $currentstring .= '<b>'.$display.'</b>';;
3209: }
3210: return $currentstring;
3211: }
3212:
3213: sub end_insert {
3214: my ($target,$token) = @_;
3215: my $currentstring = '';
3216: if ($target eq 'web' || $target eq 'webgrade') {
3217: $currentstring .= '';
3218: }
3219: return $currentstring;
3220: }
3221:
3222: #-- <externallink>
3223: sub start_externallink {
3224: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3225: my $currentstring = '';
3226: if ($target eq 'web' || $target eq 'webgrade') {
3227: my $display = &Apache::lonxml::get_param('display',$parstack,$safeeval,undef,1);
3228: $currentstring .= '<b>'.$display.'</b>';;
3229: }
3230: return $currentstring;
3231: }
3232:
3233: sub end_externallink {
3234: my ($target,$token) = @_;
3235: my $currentstring = '';
3236: if ($target eq 'web' || $target eq 'webgrade') {
3237: $currentstring .= '';
3238: }
3239: return $currentstring;
3240: }
3241:
3242: #-- <blankspace heigth="">
3243: sub start_blankspace {
3244: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3245: my $currentstring = &end_p(); # closes off any unclosed <p>
3246: if ($target eq 'tex') {
3247: my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1);
3248: $currentstring .= '\vskip '.$howmuch.' ';
3249: }
3250: return $currentstring;
3251: }
3252:
3253: sub end_blankspace {
3254: my ($target,$token) = @_;
3255: my $currentstring = '';
3256: if ($target eq 'tex') {
3257: $currentstring .= '';
3258: }
3259: return $currentstring;
3260: }
3261:
3262: #-- <abbr> tag (end tag required)
3263: sub start_abbr {
3264: my ($target,$token) = @_;
3265: my $currentstring = '';
3266: if ($target eq 'web' || $target eq 'webgrade') {
3267: $currentstring = $token->[4];
3268: }
3269: return $currentstring;
3270: }
3271:
3272: sub end_abbr {
3273: my ($target,$token) = @_;
3274: my $currentstring = '';
3275: if ($target eq 'web' || $target eq 'webgrade') {
3276: $currentstring = $token->[2];
3277: }
3278: return $currentstring;
3279: }
3280:
3281: #-- <acronym> tag (end tag required)
3282: sub start_acronym {
3283: my ($target,$token) = @_;
3284: my $currentstring = '';
3285: if ($target eq 'web' || $target eq 'webgrade') {
3286: $currentstring = $token->[4];
3287: }
3288: return $currentstring;
3289: }
3290:
3291: sub end_acronym {
3292: my ($target,$token) = @_;
3293: my $currentstring = '';
3294: if ($target eq 'web' || $target eq 'webgrade') {
3295: $currentstring = $token->[2];
3296: }
3297: return $currentstring;
3298: }
3299:
3300: #-- <area> tag (end tag forbidden)
3301: sub start_area {
3302: my ($target,$token) = @_;
3303: my $currentstring = '';
3304: if ($target eq 'web' || $target eq 'webgrade') {
3305: $currentstring = $token->[4];
3306: }
3307: return $currentstring;
3308: }
3309:
3310: sub end_area {
3311: my ($target,$token) = @_;
3312: my $currentstring = '';
3313: if ($target eq 'web' || $target eq 'webgrade') {
3314: $currentstring = $token->[2];
3315: }
3316: return $currentstring;
3317: }
3318:
3319: #-- <base> tag (end tag forbidden)
3320: sub start_base {
3321: my ($target,$token) = @_;
3322: my $currentstring = '';
3323: if ($target eq 'web' || $target eq 'webgrade') {
3324: $currentstring = $token->[4];
3325: }
3326: return $currentstring;
3327: }
3328:
3329: sub end_base {
3330: my ($target,$token) = @_;
3331: my $currentstring = '';
3332: if ($target eq 'web' || $target eq 'webgrade') {
3333: $currentstring = $token->[2];
3334: }
3335: return $currentstring;
3336: }
3337:
3338: #-- <bdo> tag (end tag required)
3339: sub start_bdo {
3340: my ($target,$token) = @_;
3341: my $currentstring = '';
3342: if ($target eq 'web' || $target eq 'webgrade') {
3343: $currentstring = $token->[4];
3344: }
3345: return $currentstring;
3346: }
3347:
3348: sub end_bdo {
3349: my ($target,$token) = @_;
3350: my $currentstring = '';
3351: if ($target eq 'web' || $target eq 'webgrade') {
3352: $currentstring = $token->[2];
3353: }
3354: return $currentstring;
3355: }
3356:
3357: #-- <bgsound> tag (end tag optional)
3358: sub start_bgsound {
3359: my ($target,$token) = @_;
3360: my $currentstring = '';
3361: if ($target eq 'web' || $target eq 'webgrade') {
3362: $currentstring = $token->[4];
3363: }
3364: return $currentstring;
3365: }
3366:
3367: sub end_bgsound {
3368: my ($target,$token) = @_;
3369: my $currentstring = '';
3370: if ($target eq 'web' || $target eq 'webgrade') {
3371: $currentstring = $token->[2];
3372: }
3373: return $currentstring;
3374: }
3375:
3376: #-- <blink> tag (end tag required)
3377: sub start_blink {
3378: my ($target,$token) = @_;
3379: my $currentstring = '';
3380: if ($target eq 'web' || $target eq 'webgrade') {
3381: $currentstring = $token->[4];
3382: }
3383: return $currentstring;
3384: }
3385:
3386: sub end_blink {
3387: my ($target,$token) = @_;
3388: my $currentstring = '';
3389: if ($target eq 'web' || $target eq 'webgrade') {
3390: $currentstring = $token->[2];
3391: }
3392: return $currentstring;
3393: }
3394:
3395: #-- <blockquote> tag (end tag required)
3396: sub start_blockquote {
3397: my ($target,$token) = @_;
3398: my $currentstring = &end_p(); # Close any unclosed <p>
3399: if ($target eq 'web' || $target eq 'webgrade') {
3400: $currentstring .= $token->[4];
3401: }
3402: if ($target eq 'tex') {
3403: $currentstring .= '\begin{quote}';
3404: }
3405: return $currentstring;
3406: }
3407:
3408: sub end_blockquote {
3409: my ($target,$token) = @_;
3410: my $currentstring = '';
3411: if ($target eq 'web' || $target eq 'webgrade') {
3412: $currentstring = $token->[2];
3413: }
3414: if ($target eq 'tex') {
3415: $currentstring = '\end{quote}';
3416: }
3417: return $currentstring;
3418: }
3419:
3420: #-- <button> tag (end tag required)
3421: sub start_button {
3422: my ($target,$token) = @_;
3423: my $currentstring = '';
3424: if ($target eq 'web' || $target eq 'webgrade') {
3425: $currentstring = $token->[4];
3426: }
3427: return $currentstring;
3428: }
3429:
3430: sub end_button {
3431: my ($target,$token) = @_;
3432: my $currentstring = '';
3433: if ($target eq 'web' || $target eq 'webgrade') {
3434: $currentstring = $token->[2];
3435: }
3436: return $currentstring;
3437: }
3438:
3439: #-- <caption> tag (end tag required)
3440: sub start_caption {
3441: my ($target,$token) = @_;
3442: my $currentstring = '';
3443: if ($target eq 'web' || $target eq 'webgrade') {
3444: $currentstring = $token->[4];
3445: }
3446: return $currentstring;
3447: }
3448:
3449: sub end_caption {
3450: my ($target,$token) = @_;
3451: my $currentstring = '';
3452: if ($target eq 'web' || $target eq 'webgrade') {
3453: $currentstring = $token->[2];
3454: }
3455: return $currentstring;
3456: }
3457:
3458: #-- <col> tag (end tag forbdden)
3459: sub start_col {
3460: my ($target,$token) = @_;
3461: my $currentstring = '';
3462: if ($target eq 'web' || $target eq 'webgrade') {
3463: $currentstring = $token->[4];
3464: }
3465: return $currentstring;
3466: }
3467:
3468: sub end_col {
3469: my ($target,$token) = @_;
3470: my $currentstring = '';
3471: if ($target eq 'web' || $target eq 'webgrade') {
3472: $currentstring = $token->[2];
3473: }
3474: return $currentstring;
3475: }
3476:
3477: #-- <colgroup tag (end tag optional)
3478: sub start_colgroup {
3479: my ($target,$token,$tagstack, $parstack, $parser, $safeeval, $style) = @_;
3480: my $currentstring = '';
3481: if ($target eq 'web' || $target eq 'webgrade') {
3482: $currentstring = $token->[4];
3483: }
3484: if ($target eq 'tex') {
3485: # TODO: Ensure this tag is in a table:
3486:
3487: # Fetch the attributes and build the hash for the
3488: # call to define_colgroup.
3489:
3490: my $span = &Apache::lonxml::get_param('span', $parstack, $safeeval);
3491: my $halign = &Apache::lonxml::get_param('halign', $parstack, $safeeval);
3492:
3493: my %colgroup_params;
3494: if ($span ne '') {
3495: $colgroup_params{'span'} = $span;
3496: }
3497: if ($halign ne '') {
3498: $colgroup_params{'halign'} = $halign;
3499: }
3500:
3501: my $table = $Apache::londefdef::table[-1];
3502: $table->define_colgroup(\%colgroup_params);
3503:
3504: }
3505: return $currentstring;
3506: }
3507:
3508: sub end_colgroup {
3509: my ($target,$token) = @_;
3510: my $currentstring = '';
3511: if ($target eq 'web' || $target eq 'webgrade') {
3512: $currentstring = $token->[2];
3513: }
3514: return $currentstring;
3515: }
3516:
3517:
3518: #-- <del> tag (end tag required)
3519: sub start_del {
3520: my ($target,$token) = @_;
3521: my $currentstring = '';
3522: if ($target eq 'web' || $target eq 'webgrade') {
3523: $currentstring = $token->[4];
3524: } elsif ($target eq 'tex') {
3525: &disable_para();
3526: $currentstring .= '\st{';
3527: }
3528: return $currentstring;
3529: }
3530:
3531: sub end_del {
3532: my ($target,$token) = @_;
3533: my $currentstring = '';
3534: if ($target eq 'web' || $target eq 'webgrade') {
3535: $currentstring = $token->[2];
3536: } elsif ($target eq 'tex') {
3537: &enable_para();
3538: $currentstring = '}';
3539: }
3540: return $currentstring;
3541: }
3542:
3543: #-- <fieldset> tag (end tag required)
3544: sub start_fieldset {
3545: my ($target,$token) = @_;
3546: my $currentstring = '';
3547: if ($target eq 'web' || $target eq 'webgrade') {
3548: $currentstring = $token->[4];
3549: }
3550: return $currentstring;
3551: }
3552:
3553: sub end_fieldset {
3554: my ($target,$token) = @_;
3555: my $currentstring = '';
3556: if ($target eq 'web' || $target eq 'webgrade') {
3557: $currentstring = $token->[2];
3558: }
3559: return $currentstring;
3560: }
3561:
3562: #-- <frame> tag (end tag forbidden)
3563: sub start_frame {
3564: my ($target,$token) = @_;
3565: my $currentstring = '';
3566: if ($target eq 'web' || $target eq 'webgrade') {
3567: $currentstring = $token->[4];
3568: }
3569: return $currentstring;
3570: }
3571:
3572: sub end_frame {
3573: my ($target,$token) = @_;
3574: my $currentstring = '';
3575: if ($target eq 'web' || $target eq 'webgrade') {
3576: $currentstring = $token->[2];
3577: }
3578: return $currentstring;
3579: }
3580:
3581: #-- <iframe> tag (end tag required)
3582: sub start_iframe {
3583: my ($target,$token) = @_;
3584: my $currentstring = '';
3585: if ($target eq 'web' || $target eq 'webgrade') {
3586: my ($src,$url,$query);
3587: if ($token->[2]->{'src'}) {
3588: $src = $token->[2]->{'src'};
3589: } elsif ($token->[2]->{'SRC'}) {
3590: $src = $token->[2]->{'SRC'};
3591: }
3592: if ($src) {
3593: ($url,$query) = ($src =~ /^([^?]+)\??([^?]*)$/);
3594: if ($query =~ /inhibitmenu=yes/) {
3595: $currentstring = $token->[4];
3596: } else {
3597: my $inhibit;
3598: if ($url =~ m{^[^/.].*\.x?html?$}) {
3599: $inhibit = 1;
3600: } elsif ($url =~ m{^/(uploaded|res)/.*\.x?html?$}) {
3601: $inhibit = 1;
3602: }
3603: if ($inhibit) {
3604: $currentstring = '<iframe ';
3605: foreach my $attrib (@{$token->[3]}) {
3606: if (lc($attrib) eq 'src') {
3607: if ($query) {
3608: $query.='&inhibitmenu=yes';
3609: } else {
3610: $query = 'inhibitmenu=yes';
3611: }
3612: $currentstring .= 'src="'.$url.'?'.$query.'" ';
3613: } else {
3614: $currentstring .= lc($attrib).'="'.$token->[2]->{$attrib}.'" ';
3615: }
3616: }
3617: $currentstring =~ s/\s+$//;
3618: if ($token->[4] =~ m{/>$}) {
3619: $currentstring .= ' />';
3620: } else {
3621: $currentstring .= '>';
3622: }
3623: } else {
3624: $currentstring = $token->[4];
3625: }
3626: }
3627: if (($url !~ m{^https?://}) && ($env{'request.course.id'})) {
3628: my $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
3629: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
3630: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
3631: if ($url =~ m{^([^/]|/uploaded/)}) {
3632: my $cleanhref = &clean_docs_httpref($url,$docuri,$cdom,$cnum);
3633: if ($cleanhref) {
3634: &Apache::lonxml::extlink($cleanhref);
3635: }
3636: } elsif (($url =~ m{/res/$LONCAPA::domain_re/}) && ($docuri =~ m{^\Q/uploaded/$cdom/$cnum/docs/\E})) {
3637: if (!&Apache::lonnet::allowed('bre',$url)) {
3638: if (&Apache::lonnet::is_on_map($url)) {
3639: &Apache::lonxml::extlink($url);
3640: }
3641: }
3642: }
3643: }
3644: } else {
3645: $currentstring = $token->[4];
3646: }
3647: }
3648: return $currentstring;
3649: }
3650:
3651: sub end_iframe {
3652: my ($target,$token) = @_;
3653: my $currentstring = '';
3654: if ($target eq 'web' || $target eq 'webgrade') {
3655: $currentstring = $token->[2];
3656: }
3657: return $currentstring;
3658: }
3659:
3660: #-- <ins> tag (end tag required)
3661: sub start_ins {
3662: my ($target,$token) = @_;
3663: my $currentstring = '';
3664: if ($target eq 'web' || $target eq 'webgrade') {
3665: $currentstring = $token->[4];
3666: }
3667: return $currentstring;
3668: }
3669:
3670: sub end_ins {
3671: my ($target,$token) = @_;
3672: my $currentstring = '';
3673: if ($target eq 'web' || $target eq 'webgrade') {
3674: $currentstring = $token->[2];
3675: }
3676: return $currentstring;
3677: }
3678:
3679: #-- <isindex> tag (end tag forbidden)
3680: sub start_isindex {
3681: my ($target,$token) = @_;
3682: my $currentstring = '';
3683: if ($target eq 'web' || $target eq 'webgrade') {
3684: $currentstring = $token->[4];
3685: }
3686: return $currentstring;
3687: }
3688:
3689: sub end_isindex {
3690: my ($target,$token) = @_;
3691: my $currentstring = '';
3692: if ($target eq 'web' || $target eq 'webgrade') {
3693: $currentstring = $token->[2];
3694: }
3695: return $currentstring;
3696: }
3697:
3698: #-- <keygen> tag (end tag forbidden)
3699: sub start_keygen {
3700: my ($target,$token) = @_;
3701: my $currentstring = '';
3702: if ($target eq 'web' || $target eq 'webgrade') {
3703: $currentstring = $token->[4];
3704: }
3705: return $currentstring;
3706: }
3707:
3708: sub end_keygen {
3709: my ($target,$token) = @_;
3710: my $currentstring = '';
3711: if ($target eq 'web' || $target eq 'webgrade') {
3712: $currentstring = $token->[2];
3713: }
3714: return $currentstring;
3715: }
3716:
3717: #-- <label> tag
3718: sub start_label {
3719: my ($target,$token) = @_;
3720: my $currentstring = '';
3721: if ($target eq 'web' || $target eq 'webgrade') {
3722: $currentstring = $token->[4];
3723: }
3724: return $currentstring;
3725: }
3726:
3727: sub end_label {
3728: my ($target,$token) = @_;
3729: my $currentstring = '';
3730: if ($target eq 'web' || $target eq 'webgrade') {
3731: $currentstring = $token->[2];
3732: }
3733: return $currentstring;
3734: }
3735:
3736: #-- <layer> tag (end tag required)
3737: sub start_layer {
3738: my ($target,$token) = @_;
3739: my $currentstring = '';
3740: if ($target eq 'web' || $target eq 'webgrade') {
3741: $currentstring = $token->[4];
3742: }
3743: return $currentstring;
3744: }
3745:
3746: sub end_layer {
3747: my ($target,$token) = @_;
3748: my $currentstring = '';
3749: if ($target eq 'web' || $target eq 'webgrade') {
3750: $currentstring = $token->[2];
3751: }
3752: return $currentstring;
3753: }
3754:
3755: #-- <legend> tag (end tag required)
3756: sub start_legend {
3757: my ($target,$token) = @_;
3758: my $currentstring = '';
3759: if ($target eq 'web' || $target eq 'webgrade') {
3760: $currentstring = $token->[4];
3761: }
3762: return $currentstring;
3763: }
3764:
3765: sub end_legend {
3766: my ($target,$token) = @_;
3767: my $currentstring = '';
3768: if ($target eq 'web' || $target eq 'webgrade') {
3769: $currentstring = $token->[2];
3770: }
3771: return $currentstring;
3772: }
3773:
3774: #-- <link> tag (end tag forbidden)
3775: sub start_link {
3776: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
3777: my $currentstring = '';
3778: if ($target eq 'web' || $target eq 'webgrade') {
3779: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
3780: undef,1);
3781: &Apache::lonxml::extlink($href);
3782: $currentstring = $token->[4];
3783: }
3784: return $currentstring;
3785: }
3786:
3787: sub end_link {
3788: my ($target,$token) = @_;
3789: my $currentstring = '';
3790: if ($target eq 'web' || $target eq 'webgrade') {
3791: $currentstring = $token->[2];
3792: }
3793: return $currentstring;
3794: }
3795:
3796: #-- <marquee> tag (end tag optional)
3797: sub start_marquee {
3798: my ($target,$token) = @_;
3799: my $currentstring = '';
3800: if ($target eq 'web' || $target eq 'webgrade') {
3801: $currentstring = $token->[4];
3802: }
3803: return $currentstring;
3804: }
3805:
3806: sub end_marquee {
3807: my ($target,$token) = @_;
3808: my $currentstring = '';
3809: if ($target eq 'web' || $target eq 'webgrade') {
3810: $currentstring = $token->[2];
3811: }
3812: return $currentstring;
3813: }
3814:
3815: #-- <multicol> tag (end tag required)
3816: sub start_multicol {
3817: my ($target,$token) = @_;
3818: my $currentstring = &end_p(); # Close any pending <p>
3819: if ($target eq 'web' || $target eq 'webgrade') {
3820: $currentstring .= $token->[4];
3821: }
3822: return $currentstring;
3823: }
3824:
3825: sub end_multicol {
3826: my ($target,$token) = @_;
3827: my $currentstring = '';
3828: if ($target eq 'web' || $target eq 'webgrade') {
3829: $currentstring = $token->[2];
3830: }
3831: return $currentstring;
3832: }
3833:
3834: #-- <nobr> tag (end tag required)
3835: sub start_nobr {
3836: my ($target,$token) = @_;
3837: my $currentstring = '';
3838: if ($target eq 'web' || $target eq 'webgrade') {
3839: $currentstring = $token->[4];
3840: } elsif ($target eq 'tex') {
3841: $currentstring='\mbox{';
3842: }
3843: return $currentstring;
3844: }
3845:
3846: sub end_nobr {
3847: my ($target,$token) = @_;
3848: my $currentstring = '';
3849: if ($target eq 'web' || $target eq 'webgrade') {
3850: $currentstring = $token->[2];
3851: } elsif ($target eq 'tex') {
3852: $currentstring='}';
3853: }
3854: return $currentstring;
3855: }
3856:
3857: #-- <noembed> tag (end tag required)
3858: sub start_noembed {
3859: my ($target,$token) = @_;
3860: my $currentstring = '';
3861: if ($target eq 'web' || $target eq 'webgrade') {
3862: $currentstring = $token->[4];
3863: }
3864: return $currentstring;
3865: }
3866:
3867: sub end_noembed {
3868: my ($target,$token) = @_;
3869: my $currentstring = '';
3870: if ($target eq 'web' || $target eq 'webgrade') {
3871: $currentstring = $token->[2];
3872: }
3873: return $currentstring;
3874: }
3875:
3876: #-- <noframes> tag (end tag required)
3877: sub start_noframes {
3878: my ($target,$token) = @_;
3879: my $currentstring = '';
3880: if ($target eq 'web' || $target eq 'webgrade') {
3881: $currentstring = $token->[4];
3882: }
3883: return $currentstring;
3884: }
3885:
3886: sub end_noframes {
3887: my ($target,$token) = @_;
3888: my $currentstring = '';
3889: if ($target eq 'web' || $target eq 'webgrade') {
3890: $currentstring = $token->[2];
3891: }
3892: return $currentstring;
3893: }
3894:
3895: #-- <nolayer> tag (end tag required)
3896: sub start_nolayer {
3897: my ($target,$token) = @_;
3898: my $currentstring = '';
3899: if ($target eq 'web' || $target eq 'webgrade') {
3900: $currentstring = $token->[4];
3901: }
3902: return $currentstring;
3903: }
3904:
3905: sub end_nolayer {
3906: my ($target,$token) = @_;
3907: my $currentstring = '';
3908: if ($target eq 'web' || $target eq 'webgrade') {
3909: $currentstring = $token->[2];
3910: }
3911: return $currentstring;
3912: }
3913:
3914: #-- <noscript> tag (end tag required)
3915: sub start_noscript {
3916: my ($target,$token) = @_;
3917: my $currentstring = '';
3918: if ($target eq 'web' || $target eq 'webgrade') {
3919: $currentstring = $token->[4];
3920: }
3921: return $currentstring;
3922: }
3923:
3924: sub end_noscript {
3925: my ($target,$token) = @_;
3926: my $currentstring = '';
3927: if ($target eq 'web' || $target eq 'webgrade') {
3928: $currentstring = $token->[2];
3929: }
3930: return $currentstring;
3931: }
3932:
3933: #-- <object> tag (end tag required)
3934: sub start_object {
3935: my ($target,$token) = @_;
3936: my $currentstring = '';
3937: if ($target eq 'web' || $target eq 'webgrade') {
3938: $currentstring = $token->[4];
3939: }
3940: return $currentstring;
3941: }
3942:
3943: sub end_object {
3944: my ($target,$token) = @_;
3945: my $currentstring = '';
3946: if ($target eq 'web' || $target eq 'webgrade') {
3947: $currentstring = $token->[2];
3948: }
3949: return $currentstring;
3950: }
3951:
3952: #-- <optgroup> tag (end tag required)
3953: sub start_optgroup {
3954: my ($target,$token) = @_;
3955: my $currentstring = '';
3956: if ($target eq 'web' || $target eq 'webgrade') {
3957: $currentstring = $token->[4];
3958: }
3959: return $currentstring;
3960: }
3961:
3962: sub end_optgroup {
3963: my ($target,$token) = @_;
3964: my $currentstring = '';
3965: if ($target eq 'web' || $target eq 'webgrade') {
3966: $currentstring = $token->[2];
3967: }
3968: return $currentstring;
3969: }
3970:
3971: #-- <samp> tag (end tag required)
3972: sub start_samp {
3973: my ($target,$token) = @_;
3974: my $currentstring = '';
3975: if ($target eq 'web' || $target eq 'webgrade') {
3976: $currentstring = $token->[4];
3977: } elsif ($target eq 'tex') {
3978: $currentstring='\texttt{';
3979: }
3980: return $currentstring;
3981: }
3982:
3983: sub end_samp {
3984: my ($target,$token) = @_;
3985: my $currentstring = '';
3986: if ($target eq 'web' || $target eq 'webgrade') {
3987: $currentstring = $token->[2];
3988: } elsif ($target eq 'tex') {
3989: $currentstring='}';
3990: }
3991: return $currentstring;
3992: }
3993:
3994: #-- <server> tag
3995: sub start_server {
3996: my ($target,$token) = @_;
3997: my $currentstring = '';
3998: if ($target eq 'web' || $target eq 'webgrade') {
3999: $currentstring = $token->[4];
4000: }
4001: return $currentstring;
4002: }
4003:
4004: sub end_server {
4005: my ($target,$token) = @_;
4006: my $currentstring = '';
4007: if ($target eq 'web' || $target eq 'webgrade') {
4008: $currentstring = $token->[2];
4009: }
4010: return $currentstring;
4011: }
4012:
4013: #-- <spacer> tag (end tag forbidden)
4014: sub start_spacer {
4015: my ($target,$token) = @_;
4016: my $currentstring = &end_p(); # Close off any open <p> tag.
4017: if ($target eq 'web' || $target eq 'webgrade') {
4018: $currentstring .= $token->[4];
4019: }
4020: return $currentstring;
4021: }
4022:
4023: sub end_spacer {
4024: my ($target,$token) = @_;
4025: my $currentstring = '';
4026: if ($target eq 'web' || $target eq 'webgrade') {
4027: $currentstring = $token->[2];
4028: }
4029: return $currentstring;
4030: }
4031:
4032: #-- <span> tag (end tag required)
4033: sub start_span {
4034: my ($target,$token) = @_;
4035: my $currentstring = '';
4036: if ($target eq 'web' || $target eq 'webgrade') {
4037: $currentstring = $token->[4];
4038: }
4039: return $currentstring;
4040: }
4041:
4042: sub end_span {
4043: my ($target,$token) = @_;
4044: my $currentstring = '';
4045: if ($target eq 'web' || $target eq 'webgrade') {
4046: $currentstring = $token->[2];
4047: }
4048: return $currentstring;
4049: }
4050:
4051: #-- <tbody> tag (end tag optional)
4052: sub start_tbody {
4053: my ($target,$token) = @_;
4054: my $currentstring = '';
4055: if ($target eq 'web' || $target eq 'webgrade') {
4056: $currentstring = $token->[4];
4057: }
4058: if ($target eq 'tex') {
4059: # TODO: Ensure this tag is within a table:
4060:
4061: my $table = $Apache::londefdef::table[-1];
4062: $table->start_body();
4063: }
4064: return $currentstring;
4065: }
4066:
4067: sub end_tbody {
4068: my ($target,$token) = @_;
4069: my $currentstring = '';
4070: if ($target eq 'web' || $target eq 'webgrade') {
4071: $currentstring = $token->[2];
4072: }
4073: if($target eq 'tex') {
4074: # TODO: Ensure this tag is within a table:
4075:
4076: my $table = $Apache::londefdef::table[-1];
4077: $table->end_body();
4078: }
4079: return $currentstring;
4080: }
4081:
4082: #-- <tfoot> tag (end tag optional)
4083: sub start_tfoot {
4084: my ($target,$token) = @_;
4085: my $currentstring = '';
4086: if ($target eq 'web' || $target eq 'webgrade') {
4087: $currentstring = $token->[4];
4088: }
4089: if ($target eq 'tex') {
4090: # TODO: ensure this is within a table tag.
4091: my $table = $Apache::londefdef::table[-1];
4092: $table->start_foot();
4093: }
4094: return $currentstring;
4095: }
4096:
4097: sub end_tfoot {
4098: my ($target,$token) = @_;
4099: my $currentstring = '';
4100: if ($target eq 'web' || $target eq 'webgrade') {
4101: $currentstring = $token->[2];
4102: }
4103: if ($target eq 'tex') {
4104: # TODO: Ensure this is in side a table
4105: my $table = $Apache::londefdef::table[-1];
4106: $table->end_foot();
4107: }
4108: return $currentstring;
4109: }
4110:
4111: #-- <thead> tag (end tag optional)
4112: sub start_thead {
4113: my ($target,$token) = @_;
4114: my $currentstring = '';
4115: if ($target eq 'web' || $target eq 'webgrade') {
4116: $currentstring = $token->[4];
4117: }
4118: if ($target eq 'tex') {
4119: # Assume we're in a table... TODO: Verify that and ignore tag if not.
4120: my $table = $Apache::londefdef::table[-1];
4121: $table->start_head();
4122: }
4123: return $currentstring;
4124: }
4125:
4126: sub end_thead {
4127: my ($target,$token) = @_;
4128: my $currentstring = '';
4129: if ($target eq 'web' || $target eq 'webgrade') {
4130: $currentstring = $token->[2];
4131: }
4132: if ($target eq 'tex') {
4133: # TODO: Verify we are in a table and ignore tag if not.
4134:
4135: my $table = $Apache::londefdef::table[-1];
4136: $table->end_head();
4137: }
4138: return $currentstring;
4139: }
4140:
4141: #-- <var> tag
4142: sub start_var {
4143: my ($target,$token) = @_;
4144: my $currentstring = '';
4145: if ($target eq 'web' || $target eq 'webgrade') {
4146: $currentstring = $token->[4];
4147: } elsif ($target eq 'tex') {
4148: $currentstring = '\textit{';
4149: }
4150: return $currentstring;
4151: }
4152:
4153: sub end_var {
4154: my ($target,$token) = @_;
4155: my $currentstring = '';
4156: if ($target eq 'web' || $target eq 'webgrade') {
4157: $currentstring = $token->[2];
4158: } elsif ($target eq 'tex') {
4159: $currentstring = '}';
4160: }
4161: return $currentstring;
4162: }
4163:
4164: #-- <wbr> tag (end tag forbidden)
4165: sub start_wbr {
4166: my ($target,$token) = @_;
4167: my $currentstring = '';
4168: if ($target eq 'web' || $target eq 'webgrade') {
4169: $currentstring = $token->[4];
4170: }
4171: return $currentstring;
4172: }
4173:
4174: sub end_wbr {
4175: my ($target,$token) = @_;
4176: my $currentstring = '';
4177: if ($target eq 'web' || $target eq 'webgrade') {
4178: $currentstring = $token->[2];
4179: }
4180: return $currentstring;
4181: }
4182:
4183: #-- <hideweboutput> tag
4184: sub start_hideweboutput {
4185: my ($target,$token) = @_;
4186: if ($target eq 'web' || $target eq 'webgrade') {
4187: &Apache::lonxml::startredirection();
4188: }
4189: return '';
4190: }
4191:
4192: sub end_hideweboutput {
4193: my ($target,$token) = @_;
4194: my $currentstring = '';
4195: if ($target eq 'web' || $target eq 'webgrade') {
4196: $currentstring = &Apache::lonxml::endredirection();
4197: }
4198: return '';
4199: }
4200:
4201:
4202: sub image_replication {
4203: my $src = shift;
4204: if (not -e $src) { &Apache::lonnet::repcopy($src); }
4205: #replicates eps or ps
4206: my $epssrc = my $pssrc = $src;
4207: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
4208: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
4209: if (not -e $epssrc && not -e $pssrc) {
4210: my $result=&Apache::lonnet::repcopy($epssrc);
4211: if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
4212: }
4213: return '';
4214: }
4215:
4216:
4217:
4218: sub resize_image {
4219: my ($height_param, $width_param, $scaling,
4220: $parstack, $safeeval, $depth, $cis) = @_;
4221:
4222: # First apply the scaling...
4223:
4224: $height_param = $height_param * $scaling;
4225: $width_param = $width_param * $scaling;
4226:
4227: #do we have any specified LaTeX size of the picture?
4228: my $toget='TeXwidth';
4229: if ($cis) {
4230: $toget=lc($toget);
4231: }
4232: my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
4233: $safeeval,$depth,$cis);
4234: $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
4235: my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
4236: $safeeval,$depth,$cis);
4237: #do we have any specified web size of the picture?
4238: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
4239: $depth,1);
4240: if ($TeXwidth) {
4241: my $old_width_param=$width_param;
4242: if ($TeXwidth=~/(\d+)\s*\%/) {
4243: $width_param = $1*$env{'form.textwidth'}/100;
4244: } else {
4245: $width_param = $TeXwidth;
4246: }
4247: if ($TeXheight) {
4248: $height_param = $TeXheight;
4249: } elsif ($old_width_param) {
4250: $height_param=$TeXwidth/$old_width_param*$height_param;
4251: }
4252: } elsif ($TeXheight) {
4253: $height_param = $TeXheight;
4254: if ($height_param) {
4255: $width_param = $TeXheight/$height_param*$width_param;
4256: }
4257: } elsif ($width) {
4258: my $old_width_param=$width_param;
4259: $width_param = $width*$scaling;
4260: if ($old_width_param) {
4261: $height_param=$width_param/$old_width_param*$height_param;
4262: }
4263: }
4264: if ($width_param > $env{'form.textwidth'}) {
4265: my $old_width_param=$width_param;
4266: $width_param =0.95*$env{'form.textwidth'};
4267: if ($old_width_param) {
4268: $height_param=$width_param/$old_width_param*$height_param;
4269: }
4270: }
4271:
4272: return ($height_param, $width_param);
4273: }
4274:
4275: sub image_size {
4276: my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
4277:
4278: #size of image from gif/jpg/jpeg/png
4279: my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4280: if (-e $ressrc) {
4281: $src = $ressrc;
4282: }
4283: my $image = Image::Magick->new;
4284: my $current_figure = $image->Read($src);
4285: my $width_param = $image->Get('width');
4286: my $height_param = $image->Get('height');
4287: &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
4288: undef($image);
4289:
4290: ($height_param, $width_param) = &resize_image($height_param, $width_param,
4291: $scaling, $parstack, $safeeval,
4292: $depth, $cis);
4293:
4294: return ($height_param, $width_param);
4295: }
4296:
4297: sub image_width {
4298: my ($height, $width) = &image_size(@_);
4299: return $width;
4300: }
4301: # Not yet 100% sure this is correct in all circumstances..
4302: # due to my uncertainty about mods to image_size.
4303: #
4304: sub image_height {
4305: my ($height, $width) = &image_size(@_);
4306: return $height;
4307: }
4308:
4309: sub get_eps_image {
4310: my ($src)=@_;
4311: my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
4312:
4313: # In order to prevent the substitution of the alt text, we need to
4314: # be sure the orig_src file is on system now so:
4315:
4316: if (! -e $orig_src) {
4317: &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
4318: }
4319: &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
4320: my ($spath, $sname, $sext) = &fileparse($src, qr/\.(bmp|gif|png|jpg|jpeg)/i);
4321: $src=~s/\.(bmp|gif|png|jpg|jpeg)$/\.eps/i;
4322: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4323: &Apache::lonxml::debug("Filelocation gives: $src");
4324: if (! -e $src) {
4325: &Apache::lonxml::debug("$src does not exist");
4326: if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
4327: &Apache::lonxml::debug("Repcopy of $src failed (1)");
4328: #if replication failed try to find ps file
4329: $src=~s/\.eps$/\.ps/;
4330: &Apache::lonxml::debug("Now looking for $src");
4331: #if no ps file try to replicate it.
4332: my $didrepcopy = &Apache::lonnet::repcopy($src);
4333: &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
4334: if ( (not -e $src) ||
4335: ($didrepcopy ne 'ok')) {
4336: &Apache::lonxml::debug("Failed to find or replicate $src");
4337:
4338: #if replication failed try to produce eps file dynamically
4339: $src=~s/\.ps$/\.eps/;
4340: if (open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat")) {
4341: my $newsrc=$orig_src;
4342: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4343: &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
4344: print FILE ("$newsrc\n");
4345: close(FILE);
4346: }
4347: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4348: $src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
4349: if ($sext ne "") { # Put the ext. back in to uniquify.
4350: $src =~ s/\.eps$/$sext.eps/;
4351: }
4352:
4353: }
4354:
4355: }
4356: } else {
4357: # If the postscript file has spaces in its name,
4358: # LaTeX will gratuitiously vomit. Therefore
4359: # queue such files for copy with " " replaced by "_".
4360: # printout.pm will know them by their .ps or .eps extensions.
4361: my $newsrc = $orig_src;
4362: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4363: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
4364: print FILE "$src\n";
4365: close FILE;
4366: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4367: $src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
4368: }
4369: my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
4370: $path =~ s/ /\_/g;
4371: $file =~ s/ /\_/g;
4372: &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
4373: return ($path.'/',$file);
4374: }
4375:
4376: sub eps_generation {
4377: my ($src,$file,$width_param) = @_;
4378: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
4379: if (open(my $tmpfile,">>$filename")) {
4380: print $tmpfile "$src\n";
4381: close($tmpfile);
4382: }
4383: my $newsrc = $src;
4384: $newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
4385: $newsrc=~s{/home/httpd/html/res}{};
4386: $newsrc=~s{/home/httpd/html/priv/[^/]+/($LONCAPA::username_re)/}{/$1/};
4387: $newsrc=~s{/\./}{/};
4388: $newsrc=~s{/([^/]+)\.(ps|eps)}{/};
4389: if ($newsrc=~m{/home/httpd/lonUsers/}) {
4390: $newsrc=~s{/home/httpd/lonUsers}{};
4391: $newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/};
4392: }
4393: if ($newsrc=~m{/userfiles/}) {
4394: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4395: } else {
4396: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4397: }
4398: }
4399:
4400: sub file_path {
4401: my $src=shift;
4402: my ($file,$path);
4403: if ($src =~ m!(.*)/([^/]*)$!) {
4404: $file = $2;
4405: $path = $1.'/';
4406: }
4407: return $file,$path;
4408: }
4409:
4410:
4411: sub recalc {
4412: my $argument = shift;
4413: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
4414: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
4415: my $value=$1;
4416: my $units=$2;
4417: if ($units eq 'cm') {
4418: $value*=10;
4419: } elsif ($units eq 'in') {
4420: $value*=25.4;
4421: } elsif ($units eq 'pc') {
4422: $value*=(25.4*12/72.27);
4423: } elsif ($units eq 'pt') {
4424: $value*=(25.4/72.27);
4425: }
4426: return $value.' mm';
4427: }
4428:
4429: sub LATEX_length {
4430: my $garbage=shift;
4431: $garbage=~s/^\s+$//;
4432: $garbage=~s/^\s+(\S.*)/$1/;#space before
4433: $garbage=~s/(.*\S)\s+$/$1/;#space after
4434: $garbage=~s/(\s)+/$1/;#only one space
4435: $garbage=~s/(\\begin{([^\}]+)}|\\end{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
4436: $garbage=~s/(\$\_\{|\$\_|\$\^{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
4437: $garbage=~s/([^\\])\$/$1/g;#$
4438: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
4439: $garbage=~s/(\\alpha|\\beta|\\gamma|\\delta|\\epsilon|\\verepsilon|\\zeta|\\eta|\\theta|\\vartheta|\\iota|\\kappa|\\lambda|\\mu|\\nu|\\xi|\\pi|\\varpi|\\rho|\\varrho|\\sigma|\\varsigma|\\tau|\\upsilon|\\phi|\\varphi|\\chi|\\psi|\\omega|\\Gamma|\\Delta|\\Theta|\\Lambda|\\Xi|\\Pi|\\Sigma|\\Upsilon|\\Phi|\\Psi|\\Omega)/1/g;
4440: $garbage=~s/(\\pm|\\mp|\\times|\\div|\\cdot|\\ast|\\star|\\dagger|\\ddagger|\\amalg|\\cap|\\cup|\\uplus|\\sqcap|\\sqcup|\\vee|\\wedge|\\oplus|\\ominus|\\otimes|\\circ|\\bullet|\\diamond|\\lhd|\\rhd|\\unlhd|\\unrhd|\\oslash|\\odot|\\bigcirc|\\Box|\\Diamond|\\bigtriangleup|\\bigtriangledown|\\triangleleft|\\triangleright|\\setminus|\\wr)/1/g;
4441: $garbage=~s/(\\le|\\ll|\\leq|\\ge|\\geq|\\gg|\\neq|\\doreq|\\sim|\\simeq|\\subset|\\subseteq|\\sqsubset|\\sqsubseteq|\\in|\\vdash|\\models|\\supset|\\supseteq|\\sqsupset|\\sqsupseteq|\\ni|\\dash|\\perp|\\approx|\\cong|\\equiv|\\propto|\\prec|\\preceq|\\parallel|\\asymp|\\smile|\\frown|\\bowtie|\\succ|\\succeq|\\mid)/1/g;
4442: $garbage=~s/(\\not<|\\\\not\\le|\\not\\prec|\\not\\preceq|\\not\\subset|\\not\\subseteq|\\not\\sqsubseteq|\\not\\in|\\not>|\\not\\ge|\\not\\succ|\\notsucceq|\\not\\supset|\\notsupseteq|\\not\\sqsupseteq|\\notin|\\not=|\\not\\equiv|\\not\\sim|\\not\\simeq|\\not\\approx|\\not\\cong|\\not\\asymp)/1/g;
4443: $garbage=~s/(\\leftarrow|\\gets|\\Leftarrow|\\rightarrow|\\to|\\Rightarrow|\\leftrightarrow|\\Leftrightarrow|\\mapsto|\\hookleftarrow|\\leftharpoonup|\\leftkarpoondown|\\rightleftharpoons|\\longleftarrow|\\Longleftarrow|\\longrightarrow|\\Longrightarrow|\\longleftrightarrow|\\Longleftrightarrow|\\longmapsto|\\hookrightarrow|\\rightharpoonup|\\rightharpoondown|\\uparrow|\\Uparrow|\\downarrow|\\Downarrow|\\updownarrow|\\Updownarrow|\\nearrow|\\searrow|\\swarrow|\\nwarrow)/11/g;
4444: $garbage=~s/(\\aleph|\\hbar|\\imath|\\jmath|\\ell|\\wp|\\Re|\\Im|\\mho|\\prime|\\emptyset|\\nabla|\\surd|\\partial|\\top|\\bot|\\vdash|\\dashv|\\forall|\\exists|\\neg|\\flat|\\natural|\\sharp|\\\||\\angle|\\backslash|\\Box|\\Diamond|\\triangle|\\clubsuit|\\diamondsuit|\\heartsuit|\\spadesuit|\\Join|\\infty)/11/g;
4445: $garbage=~s/(\\hat{([^}]+)}|\\check{([^}]+)}|\\dot{([^}]+)}|\\breve{([^}]+)}|\\acute{([^}]+)}|\\ddot{([^}]+)}|\\grave{([^}]+)}|\\tilde{([^}]+)}|\\mathring{([^}]+)}|\\bar{([^}]+)}|\\vec{([^}]+)})/$1/g;
4446: #remove some other LaTeX command
4447: $garbage=~s|\\(\w+)\\|\\|g;
4448: $garbage=~s|\\(\w+)(\s*)|$2|g;
4449: $garbage=~s|\+|11|g;
4450: my $value=length($garbage);
4451: return $value;
4452: }
4453:
4454:
4455: sub align_latex_image {
4456: my ($align, $latex_rendering, $image, $width, $height) = @_;
4457: my $currentstring; # The 1/2 wrapped image.
4458: my $closure; # The closure of the wrappage.
4459:
4460: # if it's none just return it back
4461: if ($latex_rendering eq 'none') {
4462: return ($image,'');
4463: }
4464:
4465: # If there's an alignment specification we need to honor it here.
4466: # For the horizontal alignments, we will also honor the
4467: # value of the latex specfication. The default is parbox,
4468: # and that's used for illegal values too.
4469: #
4470: # Even though we set a default alignment value, the user
4471: # could have given us an illegal value. In that case we
4472: # just use the default alignment of bottom..
4473: $currentstring = '';
4474: if ($align eq "top") {
4475: $currentstring .= '\raisebox{-'.$height.'mm}{'.$image;
4476: $closure = '}';
4477: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
4478: my $offset = $height/2;
4479: $currentstring .= '\raisebox{-'.$offset.'mm}{'.$image;
4480: $closure = '}';
4481: } elsif ($align eq "left") {
4482: if ($latex_rendering eq "parpic") {
4483: $currentstring .= '\parpic[l]{'.$image;
4484: $closure = '}';
4485: } elsif ($latex_rendering eq "parbox") {
4486: $currentstring .= '\begin{minipage}[l]{'.$width.'mm}'
4487: .$image;
4488: $closure = '\end{minipage}';
4489: } elsif ($latex_rendering eq "wrapfigure"
4490: || $latex_rendering ne 'none') { # wrapfig render
4491: $currentstring .=
4492: '\begin{wrapfigure}{l}{'.$width.'mm}'
4493: .'\scalebox{1.0}{'.$image;
4494: $closure = '}\end{wrapfigure}';
4495: }
4496: } elsif ($align eq "right") {
4497: if ($latex_rendering eq "parpic") {
4498: $currentstring .= '\parpic[r]{'.$image;
4499: $closure = '}';
4500: } elsif ($latex_rendering eq "parbox") {
4501: $currentstring .= '\begin{minipage}[r]{'.$width.'mm}'
4502: .$image;
4503: $closure = '\end{minipage}';
4504: } elsif ($latex_rendering eq "wrapfigure"
4505: || $latex_rendering ne 'none') { # wrapfig render
4506: $currentstring .=
4507: '\begin{wrapfigure}{r}{'.$width.'mm}'
4508: .'\scalebox{1.0}{'.$image;
4509: $closure = '}\end{wrapfigure}';
4510: }
4511: } else { # Bottom is also default.
4512: # $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
4513: $currentstring .= "{$image";
4514: $closure = '}';
4515: }
4516: return ($currentstring, $closure);
4517: }
4518:
4519:
4520: sub is_inside_of {
4521: my ($tagstack, $tag) = @_;
4522: my @stack = @$tagstack;
4523: for (my $i = ($#stack - 1); $i >= 0; $i--) {
4524: if ($stack[$i] eq $tag) {
4525: return 1;
4526: }
4527: }
4528: return 0;
4529: }
4530:
4531:
4532: #
4533: # This sub provides the typical LaTeX prefix matter for tex output:
4534: #
4535: sub latex_header {
4536: my ($mode) = @_;
4537: my $currentstring = '';
4538:
4539: $currentstring .=
4540: "\n% &Apache::lonxml::londefdef \n" .
4541: '\documentclass[letterpaper,twoside]{article}\raggedbottom';
4542: if (($env{'form.latex_type'}=~'batchmode') ||
4543: (!$env{'request.role.adv'}) ||
4544: ($mode eq 'batchmode')) {$currentstring .='\batchmode';}
4545: $currentstring .= '\newcommand{\keephidden}[1]{}'.
4546: '\renewcommand{\deg}{$^{\circ}$}'.
4547: '\usepackage{multirow}'.
4548: '\usepackage{longtable}'.
4549: '\usepackage{textcomp}'.
4550: '\usepackage{makeidx}'.
4551: '\usepackage[dvips]{graphicx}'.
4552: '\usepackage{wrapfig}'.
4553: '\usepackage{picins}'.
4554: '\usepackage[T1]{fontenc}'."\n".
4555: '\usepackage{lmodern}'."\n".
4556: '\usepackage[postscript]{ucs}'."\n".
4557: '\usepackage[utf8x]{inputenc}'."\n".
4558: '\usepackage{pifont}' ."\n".
4559: '\usepackage{latexsym}'."\n".
4560: '\usepackage{epsfig}'.
4561: "\\usepackage{xtab}\n".
4562: "\\usepackage{tabularx}\n".
4563: "\\usepackage{booktabs}\n".
4564: "\\usepackage{array}\n".
4565: "\\usepackage{colortbl}\n".
4566: "\\usepackage{xcolor}\n".
4567: '\usepackage{calc}'.
4568: '\usepackage{amsmath}'.
4569: '\usepackage{soul}'.
4570: '\usepackage{amssymb}'.
4571: '\usepackage{amsfonts}'.
4572: '\usepackage{amsthm}'.
4573: '\usepackage{amscd}'
4574: .'\usepackage{picins}\usepackage{calc}'."\n". # From lonprintout.pm
4575: '\usepackage[T1]{fontenc}'."\n".
4576: '\usepackage{lmodern}'."\n".
4577: '\usepackage[postscript]{ucs}'."\n".
4578: '\usepackage[utf8x]{inputenc}'."\n".
4579: '\usepackage{pifont}' . "\n";
4580:
4581: if($env{'form.pdfFormFields'} eq 'yes') {
4582: $currentstring .= '\usepackage{hyperref}'.
4583: '\usepackage{eforms}'.
4584: '\usepackage{tabularx}';
4585: }
4586:
4587: $currentstring .= '\newenvironment{choicelist}{\begin{list}{}{\setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.05in}\setlength{\itemsep}{0.022in}\setlength{\parsep}{0in}\setlength{\belowdisplayskip}{0.04in}\setlength{\abovedisplayskip}{0.05in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.04in}}}{\end{list}}'.
4588: '\renewenvironment{theindex}{\begin{list}{}{{\vskip 1mm \noindent \large\textbf{Index}} \newline \setlength{\rightmargin}{0in}\setlength{\leftmargin}{0.13in}\setlength{\topsep}{0.01in}\setlength{\itemsep}{0.1in}\setlength{\parsep}{-0.02in}\setlength{\belowdisplayskip}{0.01in}\setlength{\abovedisplayskip}{0.01in}\setlength{\abovedisplayshortskip}{-0.04in}\setlength{\belowdisplayshortskip}{0.01in}}}{\end{list}}';
4589: $currentstring .= '\begin{document}';
4590:
4591: return $currentstring;
4592:
4593: }
4594:
4595: sub clean_docs_httpref {
4596: my ($href,$docuri,$cdom,$cnum) = @_;
4597: if ($docuri eq '') {
4598: &Apache::lonnet::hreflocation('',$env{'request.filename'});
4599: }
4600: if ($cdom eq '') {
4601: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4602: }
4603: if ($cnum eq '') {
4604: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4605: }
4606: my $cleanhref;
4607: if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum/docs/\E)(.+/)[^/]+$}) {
4608: my $prefix = $1;
4609: my $relpath = $2;
4610: my ($hrefpath,$fname);
4611: if ($href =~ m{^/}) {
4612: if ($href =~ m{^\Q$prefix\E(.+/)([^/]+)$}) {
4613: $hrefpath = $1;
4614: $fname = $2;
4615: } else {
4616: return $cleanhref;
4617: }
4618: } else {
4619: if ($href =~ m{/}) {
4620: (my $path,$fname) = ($href =~ m{^(.*)/([^/]*)$});
4621: $hrefpath = $relpath.$path;
4622: if ($path eq '') {
4623: $hrefpath =~ s{/$}{};
4624: }
4625: } else {
4626: $fname = $href;
4627: $hrefpath = $relpath;
4628: $hrefpath =~ s{/$}{};
4629: }
4630: }
4631: if ($fname ne '') {
4632: my $cleanrelpath;
4633: foreach my $dir (split(/\//,$hrefpath)) {
4634: next if ($dir eq '.');
4635: if ($dir eq '..') {
4636: $cleanrelpath =~ s{([^/]+/)$}{};
4637: } else {
4638: $cleanrelpath .= $dir.'/';
4639: }
4640: }
4641: if ($cleanrelpath ne '') {
4642: $cleanhref = $prefix.$cleanrelpath.$fname;
4643: } else {
4644: $cleanhref = $prefix.$fname;
4645: }
4646: }
4647: }
4648: return $cleanhref;
4649: }
4650:
4651: =pod
4652:
4653: =head1 NAME
4654:
4655: Apache::londefdef.pm
4656:
4657: =head1 SYNOPSIS
4658:
4659: Tags Default Definition Module
4660:
4661: This is part of the LearningOnline Network with CAPA project
4662: described at http://www.lon-capa.org.
4663:
4664:
4665: =head1 NOTABLE SUBROUTINES
4666:
4667: =over
4668:
4669: =item start_hideweboutput()
4670:
4671: =item end_hideweboutput()
4672:
4673: =item image_replication()
4674:
4675: =item resize_image()
4676:
4677: Get correct sizing parameter for an image given
4678: it's initial ht. and wid. This allows sizing of
4679: images that are generated on-the-fly (e.g. gnuplot)
4680: as well as serving as a utility for image_size.
4681:
4682: Parameter:
4683: height_param
4684: width_param - Initial picture dimensions.
4685: scaling - A scale factor.
4686: parstack, - the current stack of tag attributes
4687: from the xml parser
4688: safeeval, - pointer to the safespace
4689: depth, - from what level in the stack to look for attributes
4690: (assumes -1 if unspecified)
4691: cis - look for attrubutes case insensitively
4692: (assumes false)
4693:
4694: Returns:
4695: height, width - new dimensions.
4696:
4697: =item image_size()
4698:
4699: =item image_width()
4700:
4701: =item image_height()
4702:
4703: =item get_eps_image()
4704:
4705: =item eps_generation()
4706:
4707: =item file_path()
4708:
4709: =item recalc()
4710:
4711: Converts a measurement in to mm from any of
4712: the other valid LaTeX units of measure.
4713: If the units of measure are missing from the
4714: parameter, it is assumed to be in and returned
4715: with mm units of measure
4716:
4717: =item LATEX_length()
4718:
4719: =item align_latex_image()
4720:
4721: Wrap image 'stuff' inside of the LaTeX required to implement
4722: alignment:
4723: align_tex_image(align, latex_rendering, image)
4724: Where:
4725: align - The HTML alignment specification.
4726: latex_rendering - rendering hint for latex.
4727: image - The LaTeX needed to insert the image itsef.
4728: width,height - dimensions of the image.
4729: Returns:
4730: The 1/2 wrapped image and the stuff required to close the
4731: wrappage. This allows e.g. randomlabel to insert more stuff
4732: into the closure.
4733:
4734:
4735: =item is_inside_of($tagstack, $tag)
4736: This sub returns true if the current state of Xml processing is inside of the tag.
4737: Parameters:
4738: tagstack - The tagstack from the parser.
4739: tag - The tag (without the <>'s.).
4740: Sample usage:
4741: if (is_inside_of($tagstack "table")) {
4742: I'm in a table....
4743: }
4744:
4745: =item clean_docs_httpref($href,$docuri,$cdom,$cnum)
4746: HTML pages uploaded to a course which contain dependencies either from iframes,
4747: javascript files or objects (FlashPlayerSwf, MediaSrc, XMPSrc, ConfigurationSrc,
4748: and PosterImageSrc) for which dependency is another file uploaded to the same
4749: course.
4750:
4751: Required input:
4752: href - dependency (either a relative URL, or an absolute URL)
4753: Optional inputs:
4754: docuri - URL of HTML page containing the dependency
4755: cdom - Course domain
4756: cnum - CourseID
4757:
4758: Output:
4759: returns an absolute URL constructed from the href provided, and the calling context.
4760: (this will be null, if the URL does not begin: /uploaded/$cdom/$cnum/docs/).
4761:
4762: =back
4763:
4764: =cut
4765:
4766:
4767: 1;
4768: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>