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