1: # The LearningOnline Network with CAPA
2: # Tags Default Definition Module
3: #
4: # $Id: londefdef.pm,v 1.456.2.6.2.1 2023/07/10 02:23:29 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: } elsif (($env{'browser.type'} eq 'safari') && ($env{'form.editxmltext'}) &&
103: (($env{'form.problemmode'} eq 'view') || ($env{'form.problemmode'} eq 'discard'))) {
104: my $delimiter;
105: if ($inside =~ /\$$/) {
106: $delimiter = '$';
107: } elsif ($inside =~ /\\([)\]])$/) {
108: $delimiter = $1;
109: }
110: if ($delimiter) {
111: &Apache::lonxml::warning(&mt('Insert a space between [_1] and [_2].',
112: $delimiter,'</m>'));
113: }
114: }
115: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
116: if ($eval eq 'on') {
117: $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]);
118: #&Apache::lonxml::debug("M is evaluated to:$inside:");
119: }
120: my $tex = $inside;
121: my $display=&Apache::lonxml::get_param('display',$parstack,$safeeval);
122: $currentstring = &Apache::lontexconvert::converted(\$inside,$display);
123: if ($Apache::lontexconvert::errorstring) {
124: my $errormsg='<pre>'.&HTML::Entities::encode($Apache::lontexconvert::errorstring,'<>&"').'</pre> occurred while attempting to convert this TeX: <pre>';
125: $tex = &HTML::Entities::encode($tex,'<>&"');
126: my ($linenumber) =
127: ($Apache::lontexconvert::errorstring =~ /Line (\d+)/);
128: if (defined($linenumber)) {
129: my @tex=split("\n",$tex);
130: $tex[$linenumber]='<b><font color="red">'.
131: $tex[$linenumber].'</font></b>';
132: $tex=join("\n",@tex);
133: }
134: &Apache::lonxml::warning($errormsg.$tex.'</pre>');
135: $Apache::lontexconvert::errorstring='';
136: }
137: #&Apache::lonxml::debug("M is ends with:$currentstring:");
138: $Apache::lonxml::post_evaluate=0;
139: } elsif ($target eq 'tex') {
140:
141: $currentstring = $inside;
142: my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval);
143: if ($eval eq 'on') {
144: $currentstring=&Apache::run::evaluate($currentstring,$safeeval,$$parstack[-1]);
145: }
146: if ($currentstring=~/^(\s*\\\\\s*)*$/) {$currentstring = ' \vskip 0 mm ';}
147: # detect simple math mode entry exits, and convert them
148: # to use \ensuremath ... unless there's a \verb inside.
149: if (! ($currentstring=~/\\verb/)) {
150: if ($currentstring=~/^\s*\$[^\$].*\$\s*$/) {
151: $currentstring=~s/^(\s*)\$/$1/;
152: $currentstring=~s/\$(\s*)$/$1/;
153: $currentstring='\ensuremath{'.$currentstring.'}';
154: }
155: }
156: $Apache::lonxml::post_evaluate=0;
157: }
158: return $currentstring;
159: }
160:
161: sub end_m {
162: my ($target,$token) = @_;
163: my $currentstring = '';
164: if ($target eq 'tex') {
165: $currentstring = "";
166: }
167: return $currentstring;
168: }
169:
170: sub start_tthoption {
171: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
172: my $result;
173: if ($target eq 'web' || $target eq 'webgrade') {
174: my $inside = &Apache::lonxml::get_all_text("/tthoption",$parser,
175: $style);
176: $inside=~s/^\s*//;
177: if ($env{'browser.mathml'}) {
178: &tth::ttmoptions($inside);
179: } else {
180: &tth::tthoptions($inside);
181: }
182: }
183: return $result;
184: }
185:
186: sub end_tthoption {
187: my ($target,$token) = @_;
188: my $result;
189: return $result;
190: }
191:
192: #-- <html> tag (end tag optional)
193: sub start_html {
194: my ($target,$token) = @_;
195: my $currentstring = '';
196: if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) {
197: # start_body() takes care of emitting the <html>
198: } elsif ($target eq 'tex') {
199:
200: $currentstring .= &latex_header();
201: }
202: return $currentstring;
203: }
204:
205: sub end_html {
206: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
207: my $currentstring = '';
208: if ($target eq 'web' || $target eq 'webgrade') {
209: # end_body takes care of the </html>
210: }
211: return $currentstring;
212: }
213:
214: #-- <head> tag (end tag optional)
215: sub start_head {
216: my ($target,$token) = @_;
217: my $currentstring = '';
218: if ($target eq 'web' || $target eq 'webgrade') {
219: &Apache::lonxml::startredirection();
220: }
221: return $currentstring;
222: }
223:
224: sub end_head {
225: my ($target,$token) = @_;
226: my $currentstring = '';
227: if (($target eq 'web' && $env{'request.state'} eq 'published') ||
228: ($target eq 'webgrade' && $env{'request.state'} eq 'published')) {
229: # in case there is a </head> but no <head>
230: if ($Apache::lonxml::redirection) {
231: $Apache::londefdef::head = &Apache::lonxml::endredirection();
232: }
233: }
234: return $currentstring;
235: }
236:
237: #-- <map> tag (end tag required)
238: sub start_map {
239: my ($target,$token) = @_;
240: my $currentstring = '';
241: if ($target eq 'web' || $target eq 'webgrade') {
242: $currentstring = $token->[4];
243: }
244: return $currentstring;
245: }
246:
247: sub end_map {
248: my ($target,$token) = @_;
249: my $currentstring = '';
250: if ($target eq 'web' || $target eq 'webgrade') {
251: $currentstring = $token->[2];
252: }
253: return $currentstring;
254: }
255:
256: #-- <select> tag (end tag required)
257: sub start_select {
258: my ($target,$token) = @_;
259: my $currentstring = '';
260: if ($target eq 'web' || $target eq 'webgrade') {
261: $currentstring = $token->[4];
262: } elsif ($target eq 'tex') {
263: $Apache::londefdef::select=0;
264: }
265: return $currentstring;
266: }
267:
268: sub end_select {
269: my ($target,$token) = @_;
270: my $currentstring = '';
271: if ($target eq 'web' || $target eq 'webgrade') {
272: $currentstring = $token->[2];
273: }
274: return $currentstring;
275: }
276:
277: #-- <option> tag (end tag optional)
278: sub start_option {
279: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
280: my $currentstring = '';
281: if ($target eq 'web' || $target eq 'webgrade') {
282: $currentstring = $token->[4];
283: } elsif ($target eq 'tex') {
284: $Apache::londefdef::select++;
285: if ($Apache::londefdef::select == 1) {
286: $currentstring='\noindent\fbox{'.&Apache::lonxml::get_param('value',$parstack,$safeeval).'}\keephidden{';
287: } else {
288: $currentstring='\keephidden{';
289: }
290: }
291: return $currentstring;
292: }
293:
294: sub end_option {
295: my ($target,$token) = @_;
296: my $currentstring = '';
297: if ($target eq 'web' || $target eq 'webgrade') {
298: $currentstring = $token->[2];
299: } elsif ($target eq 'tex') {
300: $currentstring='}';
301: }
302: return $currentstring;
303: }
304:
305: #-- <input> tag (end tag forbidden)
306: sub start_input {
307: my ($target,$token) = @_;
308: my $currentstring = '';
309: if ($target eq 'web' || $target eq 'webgrade') {
310: $currentstring = $token->[4];
311: }
312: return $currentstring;
313: }
314:
315: sub end_input {
316: my ($target,$token) = @_;
317: my $currentstring = '';
318: if ($target eq 'web' || $target eq 'webgrade') {
319: $currentstring = $token->[2];
320: }
321: return $currentstring;
322: }
323:
324: #-- <textarea> tag (end tag required)
325: sub start_textarea {
326: my ($target,$token) = @_;
327: my $currentstring = '';
328: if ($target eq 'web' || $target eq 'webgrade') {
329: $currentstring = $token->[4];
330: }
331: return $currentstring;
332: }
333:
334: sub end_textarea {
335: my ($target,$token) = @_;
336: my $currentstring = '';
337: if ($target eq 'web' || $target eq 'webgrade') {
338: $currentstring = $token->[2];
339: }
340: return $currentstring;
341: }
342:
343: #-- <form> tag (end tag required)
344: sub start_form {
345: my ($target,$token) = @_;
346: my $currentstring = '';
347: if ($target eq 'web' || $target eq 'webgrade') {
348: $currentstring = $token->[4];
349: }
350: return $currentstring;
351: }
352:
353: sub end_form {
354: my ($target,$token) = @_;
355: my $currentstring = '';
356: if ($target eq 'web' || $target eq 'webgrade') {
357: $currentstring = $token->[2];
358: }
359: return $currentstring;
360: }
361:
362: #-- <title> tag (end tag required)
363: sub start_title {
364: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
365: my $currentstring = '';
366: if ($target eq 'web' || $target eq 'webgrade') {
367: $Apache::londefdef::title =
368: &Apache::lonxml::get_all_text('/title',$parser,$style);
369: } elsif ($target eq 'tex') {
370: $currentstring .= '\keephidden{Title of the document: ';
371: }
372: if ($target eq 'meta') {
373: $currentstring='<title>';
374: &start_output($target);
375: }
376: return $currentstring;
377: }
378:
379: sub end_title {
380: my ($target,$token) = @_;
381: my $currentstring = '';
382: if ($target eq 'web' || $target eq 'webgrade') {
383: # start_title takes care of swallowing the title
384: } elsif ($target eq 'tex') {
385: $currentstring .= '}';
386: }
387: if ($target eq 'meta') {
388: &end_output($target);
389: $currentstring='</title>';
390: }
391: return $currentstring;
392: }
393:
394: #-- <meta> tag (end tag forbidden)
395: sub start_meta {
396: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
397: my $currentstring = '';
398: if ($target eq 'web' || $target eq 'webgrade') {
399: my $args='';
400: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
401: if ($args eq '') {
402: &Apache::lonxml::get_all_text("/meta",$parser,$style);
403: } else {
404: $currentstring = $token->[4];
405: }
406: if ($env{'form.grade_imsexport'}) {
407: $currentstring = '';
408: }
409: } elsif ($target eq 'meta') {
410: unless (&Apache::lonxml::get_param
411: ('http-equiv',$parstack,$safeeval,undef,1)) {
412: my $name=$token->[2]->{'name'};
413: $name=~tr/A-Z/a-z/;
414: $name=~s/\s/\_/gs;
415: $name=~s/\W//gs;
416: if ($name) {
417: $currentstring='<'.$name;
418: my $display=&Apache::lonxml::get_param
419: ('display',$parstack,$safeeval,undef,1);
420: if ($display) {
421: $display=~s/\"/\'/g;
422: $currentstring.=' display="'.$display.'"';
423: }
424: $currentstring.='>'.
425: &Apache::lonxml::get_param
426: ('content',$parstack,$safeeval,undef,1).
427: '</'.$name.'>';
428: }
429: my $display=&Apache::lonxml::get_param
430: ('display',$parstack,$safeeval,undef,1);
431: if ($display) {
432: $display=&HTML::Entities::encode($display,'<>&"');
433: $currentstring.='<'.$name.'.display>'.$display.
434: '</'.$name.'.display>';
435: }
436: }
437: } elsif ($target eq 'tex') {
438: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
439: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
440: if ((not defined $content) && (not defined $name)) {
441: &Apache::lonxml::startredirection();
442: }
443: } elsif ($target eq 'edit') {
444: $currentstring .= &Apache::edit::tag_start($target,$token);
445: $currentstring .= &Apache::edit::text_arg('Name:','name',$token,30);
446: $currentstring .= &Apache::edit::text_arg('Content:','content',$token,70);
447: $currentstring .= &Apache::edit::end_row();
448: } elsif ($target eq 'modified') {
449: my $constructtag =
450: &Apache::edit::get_new_args($token,$parstack,$safeeval,
451: 'name','content');
452: if ($constructtag) { $currentstring = &Apache::edit::rebuild_tag($token); }
453: }
454: return $currentstring;
455: }
456:
457: sub end_meta {
458: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
459: my $currentstring = '';
460: if ($target eq 'web' || $target eq 'webgrade') {
461: my $args='';
462: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
463: if ($args ne '') {
464: $currentstring = $token->[4];
465: }
466: } elsif ($target eq 'tex') {
467: my $content=&Apache::lonxml::get_param('content',$parstack,$safeeval);
468: my $name=&Apache::lonxml::get_param('name',$parstack,$safeeval);
469: if ((not defined $content) && (not defined $name)) {
470: &Apache::lonxml::endredirection();
471: }
472: }
473: return $currentstring;
474: }
475:
476: sub insert_meta {
477: return '
478: <meta />';
479: }
480:
481: #-- <start> tag
482: sub start_style {
483: my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style) = @_;
484: my $currentstring = '';
485:
486: if ($target eq 'tex') {
487: Apache::lonxml::startredirection();
488: } else {
489: $currentstring = $token->[4];
490: }
491:
492: return $currentstring;
493: }
494:
495: sub end_style {
496: my ($target, $token, $tagstack, $parstack, $parser, $safeeval) = @_;
497: my $currentstring = '';
498:
499: if ($target eq 'tex') {
500: Apache::lonxml::endredirection();
501: } else {
502: $currentstring = $token->[2];
503: }
504: return $currentstring;
505: }
506:
507: # accessrule
508: sub start_accessrule {
509: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
510: my $currentstring = '';
511: my $eff =&Apache::lonxml::get_param('effect',$parstack,$safeeval,undef,1);
512: my $realm=&Apache::lonxml::get_param('realm', $parstack,$safeeval,undef,1);
513: my $role =&Apache::lonxml::get_param('role', $parstack,$safeeval,undef,1);
514: my $type =&Apache::lonxml::get_param('type', $parstack,$safeeval,undef,1);
515:
516: my ($dom,$crs,$sec,$separator);
517: if ($type eq 'user') {
518: ($dom,$crs,$sec)=split(m{/},$realm);
519: $crs = &LONCAPA::clean_username($crs);
520: $separator = '/';
521: } else {
522: ($dom,$crs,$sec)=split(/\_/,$realm);
523: $crs = &LONCAPA::clean_courseid($crs);
524: $separator = '_';
525: }
526: $dom = &LONCAPA::clean_domain($dom);
527:
528: $sec =~s/\W//;
529: $realm = $dom;
530: if ($crs =~ /\S/) { $realm .= $separator.$crs; }
531: if ($sec =~ /\S/) { $realm .= $separator.$sec; }
532: $role=~s/\W//g;
533:
534: if ($target eq 'web') {
535: my $args='';
536: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
537: if ($args eq '') {
538: &Apache::lonxml::get_all_text("/accessrule",$parser,$style);
539: } else {
540: $currentstring = $token->[4];
541: }
542: }
543: if ($target eq 'meta') {
544: $currentstring='<rule>'.$eff.':'.$realm.':'.$role.':'.$type.'</rule>';
545: }
546: return $currentstring;
547: }
548:
549: sub end_accessrule {
550: my ($target,$token,$tagstack,$parstack,$parser) = @_;
551: my $currentstring = '';
552: if ($target eq 'web') {
553: my $args='';
554: if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
555: if ($args ne '') {
556: $currentstring = $token->[4];
557: }
558: }
559: return $currentstring;
560: }
561:
562: sub generate_css_links {
563: my $links;
564: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile');
565: if ($css_href =~ /\S/) {
566: &Apache::lonxml::extlink($css_href);
567: $links .=
568: '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />';
569: }
570: return $links;
571: }
572:
573: #-- <body> tag (end tag required)
574: sub start_body {
575: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
576: my $currentstring = '';
577:
578: if ($target eq 'web' || $target eq 'webgrade') {
579: if ($Apache::lonhomework::parsing_a_problem) {
580: &Apache::lonxml::warning("<body> tag found inside of <problem> tag this can cause problems.");
581: return '';
582: }
583:
584: if (&is_inside_of($tagstack, "head")) {
585: &end_head(@_);
586: }
587:
588: my $extra_head = &generate_css_links();
589:
590: # Breadcrumbs
591: &Apache::lonhtmlcommon::clear_breadcrumbs();
592: if ($env{'request.state'} eq 'construct') {
593: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
594: &Apache::lonhtmlcommon::add_breadcrumb({
595: 'text' => 'Authoring Space',
596: 'href' => &Apache::loncommon::authorspace($url),
597: });
598: &Apache::lonhtmlcommon::add_breadcrumb({
599: 'text' => 'HTML Editor',
600: 'href' => '',
601: });
602: # breadcrumbs (and tools) will be created
603: # in start_page->bodytag->innerregister
604: } else {
605: # FIXME Where are we?
606: }
607:
608: my $args = {'add_entries' => $token->[2],
609: 'force_register' => 1,};
610: if ($target eq 'web') {
611: $args->{'print_suppress'} = 1;
612: if ($env{'request.use_absolute'}) {
613: $args->{'use_absolute'} = $env{'request.use_absolute'};
614: }
615: }
616: $currentstring =
617: &Apache::loncommon::start_page($Apache::londefdef::title,
618: $Apache::londefdef::head
619: .$extra_head,$args);
620: my $header = '';
621: if ($env{'request.state'} ne 'published' &&
622: $env{'request.state'} ne 'construct') {
623: $header=&Apache::lonmenu::constspaceform();
624: }
625: if ($env{'request.state'} ne 'published') {
626: unless ($env{'form.inhibitmenu'} eq 'yes') {
627: $header.=&edit_controls();
628: }
629: }
630: if ($env{'request.state'} eq 'construct') {
631: unless ($env{'form.inhibitmenu'} eq 'yes') {
632: $currentstring.=&Apache::loncommon::head_subbox(
633: &Apache::loncommon::CSTR_pageheader()
634: .$header);
635: }
636: } elsif ($env{'request.state'} eq 'edit') {
637: $currentstring.=&Apache::loncommon::head_subbox($header);
638: }
639: $currentstring.=&Apache::lonxml::message_location();
640: } elsif ($target eq 'tex') {
641: $currentstring = ''; # '\begin{document}' is in header.
642: }
643:
644: return $currentstring;
645: }
646:
647: sub edit_controls {
648: my ($nochgview) = @_;
649: my $result .= '
650: <form method="post" action="">
651: <div class="LC_edit_problem_header">';
652: unless ($nochgview) {
653: $result .= '
654: <div class="LC_edit_problem_header_row1">'.
655: &Apache::lonxml::renderingoptions().'
656: <input type="submit" name="changeproblemmode" value="'.&mt('Change View').'" />
657: </div>';
658: }
659: $result .= '
660: <div><input type="submit" name="editmode" accesskey="e" value="'.&mt('Edit').'" />';
661: if (($env{'request.course.id'}) && ($env{'form.forceedit'})) {
662: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
663: if ($url =~ /\.html?$/i) {
664: my ($cdom,$cnum);
665: if ($env{'request.course.id'}) {
666: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
667: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
668: if ($env{'request.filename'} =~ m{/userfiles/supplemental/default|\d+/}) {
669: if (&Apache::lonnet::is_course_upload($env{'request.filename'},
670: $cnum,$cdom)) {
671: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
672: ['folderpath','title']);
673: }
674: }
675: }
676: my ($symb,$itemtitle,$displayfile,$caller);
677: if ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/}) {
678: $itemtitle = &mt('Syllabus');
679: $caller = "/public/$cdom/$cnum/syllabus";
680: } else {
681: $caller = $url;
682: ($symb,$itemtitle,$displayfile) =
683: &Apache::lonxml::get_courseupload_hierarchy($url,
684: $env{'form.folderpath'},
685: $env{'form.title'});
686: }
687: if (($symb ne '') || ($env{'httpref.'.$url} ne '') ||
688: ($url =~ m{^/uploaded/$cdom/$cnum/portfolio/syllabus/})) {
689: $result .= (' ' x 3).
690: &Apache::lonhtmlcommon::dependencies_button()."\n".
691: &Apache::lonhtmlcommon::dependencycheck_js($symb,
692: $itemtitle,$url,$env{'form.folderpath'},$caller)."\n";
693: }
694: }
695: }
696: $result .= '</div>
697: </div>
698: </form>
699: ';
700: return $result;
701: }
702:
703: sub end_body {
704: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
705: my $currentstring = &end_p(); # Close off unclosed <p>
706: if ($target eq 'web' || $target eq 'webgrade') {
707: $currentstring .= &Apache::loncommon::end_page({'discussion' => 1});
708: } elsif ($target eq 'tex') {
709: $currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}';
710: }
711: return $currentstring;
712: }
713:
714: # \begin{center} causes a new paragprah spacing that looks odd inside
715: # of a table cell. Same at the end of a \center but with a slightly
716: # larger space .. hence center_correction and center_end_correction.
717: #
718: sub center_correction { return '\vspace*{-6 mm}'; }
719: sub center_end_correction { return '\vspace*{-7 mm}'; }
720:
721: #-- <center> tag (end tag required)
722: sub start_center {
723: my ($target,$token,$tagstack) = @_;
724: my $currentstring = &end_p(); # Close off any prior para.
725: if ($target eq 'web' || $target eq 'webgrade') {
726: $currentstring .= $token->[4];
727: } elsif ($target eq 'tex') {
728: if (&is_inside_of($tagstack, "table")) {
729: $currentstring .= ¢er_correction();
730: }
731: $currentstring .= '\begin{center}';
732: }
733: return $currentstring;
734: }
735:
736: sub end_center {
737: my ($target,$token,$tagstack) = @_;
738: my $currentstring = '';
739: if ($target eq 'web' || $target eq 'webgrade') {
740: $currentstring = $token->[2];
741: } elsif ($target eq 'tex') {
742: $currentstring = '\end{center}';
743: if (&is_inside_of($tagstack, "table")) {
744: $currentstring .= ¢er_end_correction();
745: }
746: }
747: return $currentstring;
748: }
749:
750: #-- <b> tag (end tag required)
751: # NOTE: In TeX mode disables internal <p>
752: sub start_b {
753: my ($target,$token) = @_;
754: my $currentstring = '';
755: if ($target eq 'web' || $target eq 'webgrade') {
756: $currentstring = $token->[4];
757: } elsif ($target eq 'tex') {
758: &disable_para();
759: $currentstring .= '\textbf{';
760: }
761: return $currentstring;
762: }
763:
764: sub end_b {
765: my ($target,$token) = @_;
766: my $currentstring = '';
767: if ($target eq 'web' || $target eq 'webgrade') {
768: $currentstring = $token->[2];
769: } elsif ($target eq 'tex') {
770: &enable_para();
771: $currentstring = '}';
772: }
773: return $currentstring;
774: }
775:
776: #-- <strong> tag (end tag required)
777: # NOTE: in TeX mode disables internal <p>
778: sub start_strong {
779: my ($target,$token) = @_;
780: my $currentstring = '';
781: if ($target eq 'web' || $target eq 'webgrade') {
782: $currentstring = $token->[4];
783: } elsif ($target eq 'tex') {
784: &disable_para();
785: $currentstring = '\textbf{';
786: }
787: return $currentstring;
788: }
789:
790: sub end_strong {
791: my ($target,$token) = @_;
792: my $currentstring = '';
793: if ($target eq 'web' || $target eq 'webgrade') {
794: $currentstring = $token->[2];
795: } elsif ($target eq 'tex') {
796: &enable_para();
797: $currentstring = '}';
798: }
799: return $currentstring;
800: }
801:
802: #-- <h1> tag (end tag required)
803: sub start_h1 {
804: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
805: my $currentstring = &end_p(); # Close off any prior para.
806: if ($target eq 'web' || $target eq 'webgrade') {
807: $currentstring .= $token->[4];
808: } elsif ($target eq 'tex') {
809: my $pre;
810: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
811: if ($align eq 'center') {
812: $pre='\begin{center}';
813: } elsif ($align eq 'left') {
814: $pre='\rlap{';
815: } elsif ($align eq 'right') {
816: $pre=' \hfill \llap{';
817: }
818: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
819: if (not defined $TeXsize) {$TeXsize="large";}
820: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
821: } elsif ($target eq 'meta') {
822: $currentstring.='<subject>';
823: &start_output($target);
824: }
825: return $currentstring;
826: }
827:
828: sub end_h1 {
829: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
830: my $currentstring = '';
831: if ($target eq 'web' || $target eq 'webgrade') {
832: $currentstring .= $token->[2];
833: } elsif ($target eq 'tex') {
834: my $post='\vskip 0 mm ';
835: my $align=lc(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1));
836: if ($align eq 'center') {
837: $post='\end{center}';
838: } elsif ($align eq 'left') {
839: $post='} \hfill'.'\vskip 0 mm ';
840: } elsif ($align eq 'right') {
841: $post='}'.'\vskip 0 mm ';
842: }
843: $currentstring .= '}}'.$post;
844: } elsif ($target eq 'meta') {
845: &end_output($target);
846: $currentstring='</subject>';
847: }
848: return $currentstring;
849: }
850:
851: #-- <h2> tag
852: sub start_h2 {
853: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
854: my $currentstring = &end_p(); # Close off any prior para.
855: if ($target eq 'web' || $target eq 'webgrade') {
856: $currentstring .= $token->[4];
857: } elsif ($target eq 'tex') {
858: my $pre;
859: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
860: if ($align eq 'center') {
861: $pre='\begin{center}';
862: } elsif ($align eq 'left') {
863: $pre='\rlap{';
864: } elsif ($align eq 'right') {
865: $pre=' \hfill \llap{';
866: }
867: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
868: if (not defined $TeXsize) {$TeXsize="large";}
869: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
870: }
871: return $currentstring;
872: }
873:
874: sub end_h2 {
875: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
876: my $currentstring = '';
877: if ($target eq 'web' || $target eq 'webgrade') {
878: $currentstring .= $token->[2];
879: } elsif ($target eq 'tex') {
880: my $post='\vskip 0 mm ';
881: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
882: if ($align eq 'center') {
883: $post='\end{center}';
884: } elsif ($align eq 'left') {
885: $post='} \hfill'.'\vskip 0 mm ';
886: } elsif ($align eq 'right') {
887: $post='}'.'\vskip 0 mm ';
888: }
889: $currentstring .= '}}'.$post;
890: }
891: return $currentstring;
892: }
893:
894: #-- <h3> tag
895: sub start_h3 {
896: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
897: my $currentstring = &end_p(); # Close off any prior para.
898: if ($target eq 'web' || $target eq 'webgrade') {
899: $currentstring .= $token->[4];
900: } elsif ($target eq 'tex') {
901: my $pre;
902: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
903: if ($align eq 'center') {
904: $pre='\begin{center}';
905: } elsif ($align eq 'left') {
906: $pre='\rlap{';
907: } elsif ($align eq 'right') {
908: $pre=' \hfill \llap{';
909: }
910: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
911: if (not defined $TeXsize) {$TeXsize="large";}
912: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
913: }
914: return $currentstring;
915: }
916:
917: sub end_h3 {
918: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
919: my $currentstring = '';
920: if ($target eq 'web' || $target eq 'webgrade') {
921: $currentstring .= $token->[2];
922: } elsif ($target eq 'tex') {
923: my $post='\vskip 0 mm ';
924: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
925: if ($align eq 'center') {
926: $post='\end{center}';
927: } elsif ($align eq 'left') {
928: $post='} \hfill'.'\vskip 0 mm ';
929: } elsif ($align eq 'right') {
930: $post='}'.'\vskip 0 mm ';
931: }
932: $currentstring .= '}}'.$post;
933: }
934: return $currentstring;
935: }
936:
937: #-- <h4> tag
938: sub start_h4 {
939: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
940: my $currentstring = &end_p(); # Close off any prior para.
941: if ($target eq 'web' || $target eq 'webgrade') {
942: $currentstring .= $token->[4];
943: } elsif ($target eq 'tex') {
944: my $pre;
945: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
946: if ($align eq 'center') {
947: $pre='\begin{center}';
948: } elsif ($align eq 'left') {
949: $pre='\rlap{';
950: } elsif ($align eq 'right') {
951: $pre=' \hfill \llap{';
952: }
953: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
954: if (not defined $TeXsize) {$TeXsize="large";}
955: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
956: }
957: return $currentstring;
958: }
959:
960: sub end_h4 {
961: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
962: my $currentstring = '';
963: if ($target eq 'web' || $target eq 'webgrade') {
964: $currentstring .= $token->[2];
965: } elsif ($target eq 'tex') {
966: my $post='\vskip 0 mm ';
967: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
968: if ($align eq 'center') {
969: $post='\end{center}';
970: } elsif ($align eq 'left') {
971: $post='} \hfill'.'\vskip 0 mm ';
972: } elsif ($align eq 'right') {
973: $post='}'.'\vskip 0 mm ';
974: }
975: $currentstring .= '}}'.$post;
976: }
977: return $currentstring;
978: }
979:
980: #-- <h5> tag
981: sub start_h5 {
982: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
983: my $currentstring = &end_p(); # Close off any prior paras.
984: if ($target eq 'web' || $target eq 'webgrade') {
985: $currentstring .= $token->[4];
986: } elsif ($target eq 'tex') {
987: my $pre;
988: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
989: if ($align eq 'center') {
990: $pre='\begin{center}';
991: } elsif ($align eq 'left') {
992: $pre='\rlap{';
993: } elsif ($align eq 'right') {
994: $pre=' \hfill \llap{';
995: }
996: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
997: if (not defined $TeXsize) {$TeXsize="large";}
998: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
999: }
1000: return $currentstring;
1001: }
1002:
1003: sub end_h5 {
1004: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1005: my $currentstring = '';
1006: if ($target eq 'web' || $target eq 'webgrade') {
1007: $currentstring .= $token->[2];
1008: } elsif ($target eq 'tex') {
1009: my $post='\vskip 0 mm ';
1010: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1011: if ($align eq 'center') {
1012: $post='\end{center}';
1013: } elsif ($align eq 'left') {
1014: $post='} \hfill'.'\vskip 0 mm ';
1015: } elsif ($align eq 'right') {
1016: $post='}'.'\vskip 0 mm ';
1017: }
1018: $currentstring .= '}}'.$post;
1019: }
1020: return $currentstring;
1021: }
1022:
1023: #-- <h6> tag
1024: sub start_h6 {
1025: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1026: my $currentstring = &end_p(); # Close off any prior paras.
1027: if ($target eq 'web' || $target eq 'webgrade') {
1028: $currentstring .= $token->[4];
1029: } elsif ($target eq 'tex') {
1030: my $pre;
1031: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1032: if ($align eq 'center') {
1033: $pre='\begin{center}';
1034: } elsif ($align eq 'left') {
1035: $pre='\rlap{';
1036: } elsif ($align eq 'right') {
1037: $pre=' \hfill \llap{';
1038: }
1039: my $TeXsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval,undef,0);
1040: if (not defined $TeXsize) {$TeXsize="large";}
1041: $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{';
1042: }
1043: return $currentstring;
1044: }
1045:
1046: sub end_h6 {
1047: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1048: my $currentstring = '';
1049: if ($target eq 'web' || $target eq 'webgrade') {
1050: $currentstring .= $token->[2];
1051: } elsif ($target eq 'tex') {
1052: my $post='\vskip 0 mm ';
1053: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1054: if ($align eq 'center') {
1055: $post='\end{center}';
1056: } elsif ($align eq 'left') {
1057: $post='} \hfill'.'\vskip 0 mm ';
1058: } elsif ($align eq 'right') {
1059: $post='}'.'\vskip 0 mm ';
1060: }
1061: $currentstring .= '}}'.$post;
1062: }
1063: return $currentstring;
1064: }
1065:
1066: #--- <cite> tag (end tag required)
1067: sub start_cite {
1068: my ($target,$token) = @_;
1069: my $currentstring = '';
1070: if ($target eq 'web' || $target eq 'webgrade') {
1071: $currentstring .= $token->[4];
1072: } elsif ($target eq 'tex') {
1073: $currentstring .= '\textit{';
1074: }
1075: return $currentstring;
1076: }
1077:
1078: sub end_cite {
1079: my ($target,$token) = @_;
1080: my $currentstring = '';
1081: if ($target eq 'web' || $target eq 'webgrade') {
1082: $currentstring .= $token->[2];
1083: } elsif ($target eq 'tex') {
1084: $currentstring .= '}';
1085: }
1086: return $currentstring;
1087: }
1088:
1089: #-- <i> tag (end tag required)
1090: sub start_i {
1091: my ($target,$token) = @_;
1092: my $currentstring = '';
1093: if ($target eq 'web' || $target eq 'webgrade') {
1094: $currentstring .= $token->[4];
1095: } elsif ($target eq 'tex') {
1096: $currentstring .= '\textit{';
1097: }
1098: return $currentstring;
1099: }
1100:
1101: sub end_i {
1102: my ($target,$token) = @_;
1103: my $currentstring = '';
1104: if ($target eq 'web' || $target eq 'webgrade') {
1105: $currentstring .= $token->[2];
1106: } elsif ($target eq 'tex') {
1107: $currentstring .= '}';
1108: }
1109: return $currentstring;
1110: }
1111:
1112: #-- <address> tag (end tag required)
1113: sub start_address {
1114: my ($target,$token) = @_;
1115: my $currentstring = '';
1116: if ($target eq 'web' || $target eq 'webgrade') {
1117: $currentstring .= $token->[4];
1118: } elsif ($target eq 'tex') {
1119: $currentstring .= '\textit{';
1120: }
1121: return $currentstring;
1122: }
1123:
1124: sub end_address {
1125: my ($target,$token) = @_;
1126: my $currentstring = '';
1127: if ($target eq 'web' || $target eq 'webgrade') {
1128: $currentstring .= $token->[2];
1129: } elsif ($target eq 'tex') {
1130: $currentstring .= '}';
1131: }
1132: return $currentstring;
1133: }
1134:
1135: #-- <dfn> tag (end tag required)
1136: sub start_dfn {
1137: my ($target,$token) = @_;
1138: my $currentstring = '';
1139: if ($target eq 'web' || $target eq 'webgrade') {
1140: $currentstring .= $token->[4];
1141: } elsif ($target eq 'tex') {
1142: $currentstring .= '\textit{';
1143: }
1144: return $currentstring;
1145: }
1146:
1147: sub end_dfn {
1148: my ($target,$token) = @_;
1149: my $currentstring = '';
1150: if ($target eq 'web' || $target eq 'webgrade') {
1151: $currentstring .= $token->[2];
1152: } elsif ($target eq 'tex') {
1153: $currentstring .= '}';
1154: }
1155: return $currentstring;
1156: }
1157:
1158: #-- <tt> tag (end tag required)
1159: sub start_tt {
1160: my ($target,$token) = @_;
1161: my $currentstring = '';
1162: if ($target eq 'web' || $target eq 'webgrade') {
1163: $currentstring .= $token->[4];
1164: } elsif ($target eq 'tex') {
1165: $currentstring .= '\texttt{';
1166: }
1167: return $currentstring;
1168: }
1169:
1170: sub end_tt {
1171: my ($target,$token) = @_;
1172: my $currentstring = '';
1173: if ($target eq 'web' || $target eq 'webgrade') {
1174: $currentstring .= $token->[2];
1175: } elsif ($target eq 'tex') {
1176: $currentstring .= '}';
1177: }
1178: return $currentstring;
1179: }
1180:
1181: #-- <kbd> tag (end tag required)
1182: sub start_kbd {
1183: my ($target,$token) = @_;
1184: my $currentstring = '';
1185: if ($target eq 'web' || $target eq 'webgrade') {
1186: $currentstring .= $token->[4];
1187: } elsif ($target eq 'tex') {
1188: $currentstring .= '\texttt{';
1189: }
1190: return $currentstring;
1191: }
1192:
1193: sub end_kbd {
1194: my ($target,$token) = @_;
1195: my $currentstring = '';
1196: if ($target eq 'web' || $target eq 'webgrade') {
1197: $currentstring .= $token->[2];
1198: } elsif ($target eq 'tex') {
1199: $currentstring .= '}';
1200: }
1201: return $currentstring;
1202: }
1203:
1204: #-- <code> tag (end tag required)
1205: sub start_code {
1206: my ($target,$token) = @_;
1207: my $currentstring = '';
1208: if ($target eq 'web' || $target eq 'webgrade') {
1209: $currentstring .= $token->[4];
1210: } elsif ($target eq 'tex') {
1211: $currentstring .= '\texttt{';
1212: }
1213: return $currentstring;
1214: }
1215:
1216: sub end_code {
1217: my ($target,$token) = @_;
1218: my $currentstring = '';
1219: if ($target eq 'web' || $target eq 'webgrade') {
1220: $currentstring .= $token->[2];
1221: } elsif ($target eq 'tex') {
1222: $currentstring .= '}';
1223: }
1224: return $currentstring;
1225: }
1226:
1227: #-- <em> tag (end tag required)
1228: sub start_em {
1229: my ($target,$token) = @_;
1230: my $currentstring = '';
1231: if ($target eq 'web' || $target eq 'webgrade') {
1232: $currentstring .= $token->[4];
1233: } elsif ($target eq 'tex') {
1234: $currentstring .= '\emph{';
1235: }
1236: return $currentstring;
1237: }
1238:
1239: sub end_em {
1240: my ($target,$token) = @_;
1241: my $currentstring = '';
1242: if ($target eq 'web' || $target eq 'webgrade') {
1243: $currentstring .= $token->[2];
1244: } elsif ($target eq 'tex') {
1245: $currentstring .= '}';
1246: }
1247: return $currentstring;
1248: }
1249:
1250: #-- <q> tag (end tag required)
1251: sub start_q {
1252: my ($target,$token) = @_;
1253: my $currentstring = '';
1254: if ($target eq 'web' || $target eq 'webgrade') {
1255: $currentstring .= $token->[4];
1256: } elsif ($target eq 'tex') {
1257: $currentstring .= '\emph{';
1258: }
1259: return $currentstring;
1260: }
1261:
1262: sub end_q {
1263: my ($target,$token) = @_;
1264: my $currentstring = '';
1265: if ($target eq 'web' || $target eq 'webgrade') {
1266: $currentstring .= $token->[2];
1267: } elsif ($target eq 'tex') {
1268: $currentstring .= '}';
1269: }
1270: return $currentstring;
1271: }
1272:
1273: # <p> is a bit strange since it does not require a closing </p>
1274: # However in latex, we must often output closing stuff to end
1275: # environments and {}'s etc. Therefore we do all the work
1276: # of figuring out the ending strings in the start tag processing,
1277: # and provide a mechanism to output the stop text external
1278: # to tag processing.
1279: #
1280: {
1281:
1282: my $closing_string = ''; # String required to close <p>
1283:
1284: # Some tags are <p> fragile meaning that <p> inside of them
1285: # does not work within TeX mode. This is managed via the
1286: # counter below:
1287: #
1288:
1289: my $para_disabled = 0;
1290:
1291: sub disable_para {
1292: $para_disabled++;
1293: }
1294: sub enable_para {
1295: $para_disabled--;
1296: }
1297:
1298:
1299: #-- <p> tag (end tag optional)
1300: #optional attribute - align="center|left|right"
1301: sub start_p {
1302: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1303: my $currentstring = '';
1304: if ($target eq 'web' || $target eq 'webgrade') {
1305: $currentstring .= &end_p(); # close off prior para if in progress.
1306: $currentstring .= $token->[4];
1307: if (! ($currentstring =~ /\//)) {
1308: $closing_string = '</p>'; # Deal correctly with <p /> e.g.
1309: }
1310: } elsif ($target eq 'tex' && !$para_disabled) {
1311:
1312: $currentstring .= &end_p(); # close off prior para if in progress.
1313: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1314: if ($align eq 'center') {
1315: $currentstring .='\begin{center}\par ';
1316: $closing_string = '\end{center}';
1317: if (&is_inside_of($tagstack, "table")) {
1318: $currentstring = ¢er_correction().$currentstring;
1319: }
1320: } elsif ($align eq 'right') {
1321: $currentstring.="\n".'{\flushright ';
1322: # $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
1323: $closing_string= "}\n";
1324: } elsif ($align eq 'left') {
1325: $currentstring.= "\n".'{\flushleft ';
1326: # $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{{';
1327: $closing_string = "}\n";
1328: } else {
1329: $currentstring.='\par ';
1330: if (&is_inside_of($tagstack, 'table')) {
1331: $closing_string = '\vskip 0pt'; # Seems to be consistent with <p> in tables.
1332: } else {
1333: $closing_string = '\strut\\\\\strut ';
1334: }
1335: }
1336:
1337: }
1338: return $currentstring;
1339: }
1340: #
1341: # End paragraph processing just requires that we output the
1342: # closing string that was saved and blank it.
1343: sub end_p {
1344: # Note only 'tex' mode uses disable_para and enable_para
1345: # so we don't need to know the target in the check below:
1346:
1347: if (!$para_disabled) {
1348: my $current_string = $closing_string;
1349: $closing_string = ''; # Not in a para anymore.
1350: return $current_string;
1351: } else {
1352: return '';
1353: }
1354:
1355: }
1356: }
1357: #-- <br> tag (end tag forbidden)
1358: sub start_br {
1359: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1360: my $currentstring = '';
1361: if ($target eq 'web' || $target eq 'webgrade') {
1362: $currentstring .= $token->[4];
1363: } elsif ($target eq 'tex') {
1364: my @tempo=@$tagstack;
1365: my $signal=0;
1366: # Not going to factor this to is_inside_of since that would require
1367: # multiple stack traversals.
1368: #
1369: for (my $i=$#tempo;$i>=0;$i--) {
1370: if (($tempo[$i] eq 'b') || ($tempo[$i] eq 'strong') ||
1371: ($tempo[$i] eq 'ol') || ($tempo[$i] eq 'ul')) {
1372: $signal=1;
1373: }
1374: if (($tempo[$i] eq 'td') || ($tempo[$i] eq 'th')) {
1375: $signal = 1;
1376: }
1377: }
1378: if ($signal != 1) {
1379: $currentstring .= '\strut \\\\ \strut ';
1380: }
1381:
1382: }
1383: return $currentstring;
1384: }
1385:
1386: sub end_br {
1387: my ($target,$token) = @_;
1388: my $currentstring = '';
1389: if ($target eq 'web' || $target eq 'webgrade') {
1390: $currentstring .= $token->[2];
1391: }
1392: return $currentstring;
1393: }
1394:
1395: #-- <big> tag (end tag required)
1396: sub start_big {
1397: my ($target,$token) = @_;
1398: my $currentstring = '';
1399: if ($target eq 'web' || $target eq 'webgrade') {
1400: $currentstring .= $token->[4];
1401: } elsif ($target eq 'tex') {
1402: $currentstring .= '{\large ';
1403: }
1404: return $currentstring;
1405: }
1406:
1407: sub end_big {
1408: my ($target,$token) = @_;
1409: my $currentstring = '';
1410: if ($target eq 'web' || $target eq 'webgrade') {
1411: $currentstring .= $token->[2];
1412: } elsif ($target eq 'tex') {
1413: $currentstring .= '}';
1414: }
1415: return $currentstring;
1416: }
1417:
1418: #-- <small> tag (end tag required)
1419: sub start_small {
1420: my ($target,$token) = @_;
1421: my $currentstring = '';
1422: if ($target eq 'web' || $target eq 'webgrade') {
1423: $currentstring .= $token->[4];
1424: } elsif ($target eq 'tex') {
1425: $currentstring .= '{\footnotesize ';
1426: }
1427: return $currentstring;
1428: }
1429:
1430: sub end_small {
1431: my ($target,$token) = @_;
1432: my $currentstring = '';
1433: if ($target eq 'web' || $target eq 'webgrade') {
1434: $currentstring .= $token->[2];
1435: } elsif ($target eq 'tex') {
1436: $currentstring .= '}';
1437: }
1438: return $currentstring;
1439: }
1440:
1441: #-- <basefont> tag (end tag forbidden)
1442: sub start_basefont {
1443: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1444: my $currentstring = '';
1445: if ($target eq 'web' || $target eq 'webgrade') {
1446: $currentstring = $token->[4];
1447: } elsif ($target eq 'tex') {
1448: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1449: if (defined $basesize) {
1450: $currentstring = '{\\'.$basesize.' ';
1451: }
1452: }
1453: return $currentstring;
1454: }
1455:
1456: sub end_basefont {
1457: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1458: my $currentstring = '';
1459: if ($target eq 'web' || $target eq 'webgrade') {
1460: $currentstring = $token->[4];
1461: } elsif ($target eq 'tex') {
1462: my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1463: if (defined $basesize) {
1464: $currentstring = '}';
1465: }
1466: }
1467: return $currentstring;
1468: }
1469:
1470: #-- <font> tag (end tag required)
1471: sub start_font {
1472: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1473: my $currentstring = '';
1474: if ($target eq 'web' || $target eq 'webgrade') {
1475: my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
1476: $currentstring = $token->[4];
1477: } elsif ($target eq 'tex') {
1478: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1479: if (defined $fontsize) {
1480: $currentstring = '{\\'.$fontsize.' ';
1481: }
1482: }
1483: return $currentstring;
1484: }
1485:
1486: sub end_font {
1487: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
1488: my $currentstring = '';
1489: if ($target eq 'web' || $target eq 'webgrade') {
1490: $currentstring = $token->[2];
1491: } elsif ($target eq 'tex') {
1492: my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
1493: if (defined $fontsize) {
1494: $currentstring = '}';
1495: }
1496: }
1497: return $currentstring;
1498: }
1499:
1500: #-- <strike> tag (end tag required)
1501: sub start_strike {
1502: my ($target,$token) = @_;
1503: my $currentstring = '';
1504: if ($target eq 'web' || $target eq 'webgrade') {
1505: $currentstring .= $token->[4];
1506: } elsif ($target eq 'tex') {
1507: &Apache::lonxml::startredirection();
1508: }
1509: return $currentstring;
1510: }
1511:
1512: sub end_strike {
1513: my ($target,$token) = @_;
1514: my $currentstring = '';
1515: if ($target eq 'web' || $target eq 'webgrade') {
1516: $currentstring .= $token->[2];
1517: } elsif ($target eq 'tex') {
1518: $currentstring=&Apache::lonxml::endredirection();
1519: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1520: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1521: $currentstring=~s/(\S)\s*$/$1\}/;
1522: }
1523: return $currentstring;
1524: }
1525:
1526: #-- <s> tag (end tag required)
1527: sub start_s {
1528: my ($target,$token) = @_;
1529: my $currentstring = '';
1530: if ($target eq 'web' || $target eq 'webgrade') {
1531: $currentstring .= $token->[4];
1532: } elsif ($target eq 'tex') {
1533: &Apache::lonxml::startredirection();
1534: }
1535: return $currentstring;
1536: }
1537:
1538: sub end_s {
1539: my ($target,$token) = @_;
1540: my $currentstring = '';
1541: if ($target eq 'web' || $target eq 'webgrade') {
1542: $currentstring .= $token->[2];
1543: } elsif ($target eq 'tex') {
1544: $currentstring=&Apache::lonxml::endredirection();
1545: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1546: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1547: $currentstring=~s/(\S)\s*$/$1\}/;
1548: }
1549: return $currentstring;
1550: }
1551:
1552: #-- <sub> tag (end tag required)
1553: sub start_sub {
1554: my ($target,$token) = @_;
1555: my $currentstring = '';
1556: if ($target eq 'web' || $target eq 'webgrade') {
1557: $currentstring .= $token->[4];
1558: } elsif ($target eq 'tex') {
1559: $currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{';
1560: }
1561: return $currentstring;
1562: }
1563:
1564: sub end_sub {
1565: my ($target,$token) = @_;
1566: my $currentstring = '';
1567: if ($target eq 'web' || $target eq 'webgrade') {
1568: $currentstring .= $token->[2];
1569: } elsif ($target eq 'tex') {
1570: $currentstring .= '}}';
1571: }
1572: return $currentstring;
1573: }
1574:
1575: #-- <sup> tag (end tag required)
1576: sub start_sup {
1577: my ($target,$token) = @_;
1578: my $currentstring = '';
1579: if ($target eq 'web' || $target eq 'webgrade') {
1580: $currentstring .= $token->[4];
1581: } elsif ($target eq 'tex') {
1582: $currentstring .= '\raisebox{\smallskipamount}{\scriptsize{';
1583: }
1584: return $currentstring;
1585: }
1586:
1587: sub end_sup {
1588: my ($target,$token) = @_;
1589: my $currentstring = '';
1590: if ($target eq 'web' || $target eq 'webgrade') {
1591: $currentstring .= $token->[2];
1592: } elsif ($target eq 'tex') {
1593: $currentstring .= '}}';
1594: }
1595: return $currentstring;
1596: }
1597:
1598: #-- <hr> tag (end tag forbidden)
1599: sub start_hr {
1600: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1601: my $currentstring = &end_p(); # End enclosing para.
1602: if ($target eq 'web' || $target eq 'webgrade') {
1603: $currentstring .= $token->[4];
1604: } elsif ($target eq 'tex') {
1605:
1606: # <hr /> can't be inside of <sup><sub> thank you LaTeX.
1607: #
1608: my $restart_sub = 0;
1609: my $restart_sup = 0;
1610:
1611: # Since <sub> and <sup> are simple tags it's ok to turn off/on
1612: # using the start_ stop_ functions.. those tags only care about
1613: # $target.
1614:
1615: if (&is_inside_of($tagstack, "sub")) {
1616: $restart_sub = 1;
1617: $currentstring .= &end_sub($target, $token, $tagstack,
1618: $parstack, $parser, $safeeval);
1619: }
1620: if (&is_inside_of($tagstack, "sup")) {
1621: $restart_sup = 1;
1622: $currentstring .= &end_sup($target, $token, $tagstack,
1623: $parstack, $parser, $safeeval);
1624: }
1625:
1626: my $LaTeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
1627: if (defined $LaTeXwidth) {
1628: if ($LaTeXwidth=~/^%/) {
1629: substr($LaTeXwidth,0,1)='';
1630: $LaTeXwidth=($LaTeXwidth/100).'\textwidth';
1631: }
1632: } else {
1633: $LaTeXwidth ='0.9\textwidth';
1634: }
1635: my ($pre,$post);
1636: my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
1637: if (($align eq 'center') || (not defined $align)) {
1638: $pre=''; $post='';
1639: } elsif ($align eq 'left') {
1640: $pre='\rlap{'; $post='} \hfill';
1641: } elsif ($align eq 'right') {
1642: $pre=' \hfill \llap{'; $post='}';
1643: }
1644: $currentstring .= ' \vskip 0 mm \noindent\makebox['.$LaTeXwidth.']{'.$pre.'\makebox['.
1645: $LaTeXwidth.'][b]{\hrulefill}'.$post.'}\vskip 0 mm ';
1646: # Turn stuff back on that we can't be inside of.
1647:
1648: if ($restart_sub) {
1649: $currentstring .= &start_sub($target, $token, $tagstack,
1650: $parstack, $parser, $safeeval);
1651: }
1652: if ($restart_sup) {
1653: $currentstring .= &start_sup($target, $token, $tagstack,
1654: $parstack, $parser, $safeeval);
1655: }
1656: }
1657: return $currentstring;
1658: }
1659:
1660: sub end_hr {
1661: my ($target,$token) = @_;
1662: my $currentstring = '';
1663: if ($target eq 'web' || $target eq 'webgrade') {
1664: $currentstring .= $token->[2];
1665: }
1666: return $currentstring;
1667: }
1668:
1669: #-- <div> tag (end tag required)
1670: {
1671:
1672: # Since div can be nested, the stack below is used
1673: # in 'tex' mode to store the ending strings
1674: # for the div stack.
1675:
1676: my @div_end_stack;
1677:
1678: sub start_div {
1679: my ($target,$token, $tagstack, $parstack, $parser, $safeeval) = @_;
1680: my $currentstring = &end_p(); # Close enclosing para.
1681: if ($target eq 'web' || $target eq 'webgrade') {
1682: $currentstring .= $token->[4];
1683: }
1684: if ($target eq 'tex') {
1685: # 4 possible alignments: left, right, center, and -missing-.
1686: # If inside a table row, we must let the table logic
1687: # do the alignment, however.
1688: #
1689:
1690: my $endstring = '';
1691:
1692: my $align = lc(&Apache::lonxml::get_param('align', $parstack,
1693: $safeeval, undef, 1));
1694: if ($align eq 'center') {
1695: $currentstring .= '\begin{center}';
1696: $endstring = '\end{center}';
1697: if (&is_inside_of($tagstack, "table")) {
1698: $currentstring = ¢er_correction().$currentstring;
1699: $endstring .= ¢er_end_correction();
1700: }
1701: }
1702: elsif ($align eq 'right') {
1703: $currentstring .= '\begin{flushright}';
1704: $endstring .= '\end{flushright}';
1705: } elsif ($align eq 'left') {
1706: $currentstring .= '\begin{flushleft}';
1707: $endstring = '\end{flushleft}';
1708: } else {
1709:
1710: }
1711: $currentstring .= "\n"; # For human readability.
1712: $endstring = "\n$endstring\n"; # For human readability
1713: push(@div_end_stack, $endstring);
1714: }
1715: return $currentstring;
1716: }
1717:
1718: sub end_div {
1719: my ($target,$token) = @_;
1720: my $currentstring = '';
1721: if ($target eq 'web' || $target eq 'webgrade') {
1722: $currentstring .= $token->[2];
1723: }
1724: if ($target eq 'tex') {
1725: my $endstring = pop @div_end_stack;
1726: $currentstring .= $endstring;
1727: }
1728: return $currentstring;
1729: }
1730: }
1731:
1732: #-- <a> tag (end tag required)
1733: sub start_a {
1734: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1735: my $currentstring = '';
1736: if ($target eq 'web' || $target eq 'webgrade') {
1737: my $href=&Apache::lonxml::get_param('href',$parstack,$safeeval,
1738: undef,1);
1739: $currentstring=&Apache::lonenc::encrypt_ref($token,{'href'=>$href});
1740: if ($href =~ /\S/) {
1741: if ($href !~ m{^https?://}) {
1742: my $url=&Apache::lonnet::hreflocation('',$env{'request.filename'});
1743: my $linkurl;
1744: if ($href =~ m{^/uploaded/}) {
1745: $linkurl = $href;
1746: } elsif ($href =~ m{^[^/]}) {
1747: my $path = $url;
1748: $path =~ s{[^/]*$}{};
1749: $linkurl = $path.$href;
1750: }
1751: if ($linkurl =~ m{^/uploaded/}) {
1752: if (!&Apache::lonnet::allowed('bre',$linkurl)) {
1753: if (&Apache::lonnet::is_on_map($url)) {
1754: &Apache::lonxml::extlink($linkurl);
1755: } elsif ($env{'request.course.id'}) {
1756: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
1757: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1758: if ($linkurl =~ m{^([^/]|/uploaded/$cdom/$cnum/(docs|supplemental)/)}) {
1759: my $cleanhref = &clean_docs_httpref($linkurl,$url,$cdom,$cnum);
1760: if ($cleanhref) {
1761: &Apache::lonxml::extlink($cleanhref);
1762: }
1763: }
1764: }
1765: }
1766: }
1767: }
1768: }
1769: }
1770: return $currentstring;
1771: }
1772:
1773: sub end_a {
1774: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1775: my $currentstring = '';
1776: if ($target eq 'web' || $target eq 'webgrade') {
1777: $currentstring .= $token->[2];
1778: }
1779: if ($target eq 'tex') {
1780: my $href =
1781: &Apache::lonxml::get_param('href',$parstack,$safeeval,undef,1);
1782: my $name =
1783: &Apache::lonxml::get_param('name',$parstack,$safeeval,undef,1);
1784: my $uriprint =
1785: &Apache::lonxml::get_param('uriprint',$parstack,$safeeval,undef,1);
1786: my $anchorprint =
1787: &Apache::lonxml::get_param('anchorprint',$parstack,$safeeval,undef,1);
1788: if (($href =~ /\S/) && ($uriprint=~/^on|uriprint|yes|1$/i)) {
1789: $href =~ s/([^\\])%/$1\\\%/g;
1790: # Substitute special symbols... and allow line breaks at each /
1791: #
1792: $href = &Apache::lonxml::latex_special_symbols($href);
1793: $href =~ s/\//\/\\-/g; # Map / to /\- to allow hyphenation.
1794: $currentstring .= ' ({\tt URI:'.$href.'})';
1795: } elsif (($name =~ /\S/) && ($anchorprint=~/^on|anchorprint|yes|1$/i)) {
1796: $currentstring .= ' ({\tt Anchor:'.&Apache::lonxml::latex_special_symbols($name).'})';
1797: } else {
1798: $currentstring.='';
1799: }
1800: }
1801: return $currentstring;
1802: }
1803:
1804: #-- <li> tag (end tag optional)
1805: sub start_li {
1806: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1807: my $currentstring = '';
1808: if ($target eq 'web' || $target eq 'webgrade') {
1809: $currentstring = $token->[4];
1810: } elsif ($target eq 'tex') {
1811: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1812: my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
1813: #FIXME need to support types i and I
1814: if ($type=~/disc/) {
1815: $currentstring .= ' \item[$\bullet$] ';
1816: } elsif ($type=~/circle/) {
1817: $currentstring .= ' \item[$\circ$] ';
1818: } elsif ($type=~/square/) {
1819: $currentstring .= ' \item[$\diamond$] ';
1820: } elsif ($type eq '1') {
1821: $currentstring .= ' \item['.($Apache::londefdef::list_index+1).'.]';
1822: } elsif ($type eq 'A') {
1823: $currentstring .= ' \item['.('A'..'Z')[$Apache::londefdef::list_index].'.]';
1824: } elsif ($type eq 'a') {
1825: $currentstring .= ' \item['.('a'..'z')[$Apache::londefdef::list_index].'.]';
1826: } elsif ($value ne '') {
1827: $currentstring .= ' \item['.$value.'] ';
1828: } else {
1829: $currentstring .= ' \item ';
1830: }
1831: $Apache::londefdef::list_index++;
1832: }
1833: return $currentstring;
1834: }
1835:
1836: sub end_li {
1837: my ($target,$token) = @_;
1838: my $currentstring = &end_p(); # In case there's a <p> in the <li>
1839: if ($target eq 'web' || $target eq 'webgrade') {
1840: $currentstring .= $token->[2];
1841: }
1842: return $currentstring;
1843: }
1844:
1845: #-- <u> tag (end tag required)
1846: sub start_u {
1847: my ($target,$token) = @_;
1848: my $currentstring = '';
1849: if ($target eq 'web' || $target eq 'webgrade') {
1850: $currentstring .= $token->[4];
1851: } elsif ($target eq 'tex') {
1852: &Apache::lonxml::startredirection();
1853: }
1854: return $currentstring;
1855: }
1856:
1857: sub end_u {
1858: my ($target,$token) = @_;
1859: my $currentstring = '';
1860: if ($target eq 'web' || $target eq 'webgrade') {
1861: $currentstring .= $token->[2];
1862: } elsif ($target eq 'tex') {
1863: $currentstring=&Apache::lonxml::endredirection();
1864: $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
1865: $currentstring=~s/^\s*(\S)/\\underline\{$1/;
1866: $currentstring=~s/(\S)\s*$/$1\}/;
1867: }
1868: return $currentstring;
1869: }
1870:
1871: #-- <ul> tag (end tag required)
1872: sub start_ul {
1873: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1874: my $currentstring = &end_p(); # Close off enclosing list.
1875: if ($target eq 'web' || $target eq 'webgrade') {
1876: $currentstring .= $token->[4];
1877: } elsif ($target eq 'tex') {
1878: my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1879: $Apache::londefdef::list_index=0;
1880: if ($TeXtype eq 'disc') {
1881: $currentstring .= '\renewcommand{\labelitemi}{$\bullet$}'.
1882: '\renewcommand{\labelitemii}{$\bullet$}'.
1883: '\renewcommand{\labelitemiii}{$\bullet$}'.
1884: '\renewcommand{\labelitemiv}{$\bullet$}';
1885: } elsif ($TeXtype eq 'circle') {
1886: $currentstring .= '\renewcommand{\labelitemi}{$\circ$}'.
1887: '\renewcommand{\labelitemii}{$\circ$}'.
1888: '\renewcommand{\labelitemiii}{$\circ$}'.
1889: '\renewcommand{\labelitemiv}{$\circ$}';
1890: } elsif ($TeXtype eq 'square') {
1891: $currentstring .= '\renewcommand{\labelitemi}{$\diamond$}'.
1892: '\renewcommand{\labelitemii}{$\diamond$}'.
1893: '\renewcommand{\labelitemiii}{$\diamond$}'.
1894: '\renewcommand{\labelitemiv}{$\diamond$}';
1895: }
1896: $currentstring .= '\strut \begin{itemize}';
1897: }
1898: return $currentstring;
1899: }
1900:
1901: sub end_ul {
1902: my ($target,$token) = @_;
1903: my $currentstring = '';
1904: if ($target eq 'web' || $target eq 'webgrade') {
1905: $currentstring = $token->[2];
1906: } elsif ($target eq 'tex') {
1907: $currentstring = '\end{itemize} \renewcommand{\labelitemi}{$\bullet$}'.
1908: '\renewcommand{\labelitemii}{$\bullet$}'.
1909: '\renewcommand{\labelitemiii}{$\bullet$}'.
1910: '\renewcommand{\labelitemiv}{$\bullet$}\strut ';
1911: }
1912: return $currentstring;
1913: }
1914:
1915: #-- <menu> tag (end tag required)
1916: sub start_menu {
1917: my ($target,$token) = @_;
1918: my $currentstring = '';
1919: if ($target eq 'web' || $target eq 'webgrade') {
1920: $currentstring = $token->[4];
1921: } elsif ($target eq 'tex') {
1922: $currentstring = " \\begin{itemize} ";
1923: }
1924: return $currentstring;
1925: }
1926:
1927: sub end_menu {
1928: my ($target,$token) = @_;
1929: my $currentstring = '';
1930: if ($target eq 'web' || $target eq 'webgrade') {
1931: $currentstring = $token->[2];
1932: } elsif ($target eq 'tex') {
1933: $currentstring = " \\end{itemize}";
1934: }
1935: return $currentstring;
1936: }
1937:
1938: #-- <dir> tag (end tag required)
1939: sub start_dir {
1940: my ($target,$token) = @_;
1941: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1942: if ($target eq 'web' || $target eq 'webgrade') {
1943: $currentstring .= $token->[4];
1944: } elsif ($target eq 'tex') {
1945: $currentstring .= " \\begin{itemize} ";
1946: }
1947: return $currentstring;
1948: }
1949:
1950: sub end_dir {
1951: my ($target,$token) = @_;
1952: my $currentstring = '';
1953: if ($target eq 'web' || $target eq 'webgrade') {
1954: $currentstring = $token->[2];
1955: } elsif ($target eq 'tex') {
1956: $currentstring = " \\end{itemize}";
1957: }
1958: return $currentstring;
1959: }
1960:
1961: #-- <ol> tag (end tag required)
1962: sub start_ol {
1963: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
1964: my $currentstring = &end_p(); # In case there's a <p> prior to the list.
1965: if ($target eq 'web' || $target eq 'webgrade') {
1966: $currentstring .= $token->[4];
1967: } elsif ($target eq 'tex') {
1968: $Apache::londefdef::list_index=0;
1969: my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
1970: if ($type eq '1') {
1971: $currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
1972: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
1973: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
1974: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
1975: } elsif ($type eq 'A') {
1976: $currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
1977: '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
1978: '\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
1979: '\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
1980: } elsif ($type eq 'a') {
1981: $currentstring .= '\renewcommand{\labelenumi}{\alph{enumi}.}'.
1982: '\renewcommand{\labelenumii}{\alph{enumii}.}'.
1983: '\renewcommand{\labelenumiii}{\alph{enumiii}.}'.
1984: '\renewcommand{\labelenumiv}{\alph{enumiv}.}';
1985: } elsif ($type eq 'i') {
1986: $currentstring .= '\renewcommand{\labelenumi}{\roman{enumi}.}'.
1987: '\renewcommand{\labelenumii}{\roman{enumii}.}'.
1988: '\renewcommand{\labelenumiii}{\roman{enumiii}.}'.
1989: '\renewcommand{\labelenumiv}{\roman{enumiv}.}';
1990: } elsif ($type eq 'I') {
1991: $currentstring .= '\renewcommand{\labelenumi}{\Roman{enumi}.}'.
1992: '\renewcommand{\labelenumii}{\Roman{enumii}.}'.
1993: '\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
1994: '\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
1995: }
1996: $currentstring .= '\strut \begin{enumerate}';
1997: }
1998: return $currentstring;
1999: }
2000:
2001: sub end_ol {
2002: my ($target,$token) = @_;
2003: my $currentstring = '';
2004: if ($target eq 'web' || $target eq 'webgrade') {
2005: $currentstring = $token->[2];
2006: } elsif ($target eq 'tex') {
2007: $currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
2008: '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
2009: '\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
2010: '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
2011: }
2012: return $currentstring;
2013: }
2014:
2015: #-- <dl> tag (end tag required)
2016: sub start_dl {
2017: my ($target,$token) = @_;
2018: my $currentstring = &end_p(); # In case there's a <p> unclosed prior to the list.
2019: if ($target eq 'web' || $target eq 'webgrade') {
2020: $currentstring .= $token->[4];
2021: } elsif ($target eq 'tex') {
2022: $currentstring .= '\begin{description}';
2023: $Apache::londefdef::DL++;
2024: push(@Apache::londefdef::description,[]);
2025: $Apache::londefdef::DD[$Apache::londefdef::DL]=0;
2026: $Apache::londefdef::DT[$Apache::londefdef::DL]=0;
2027: $Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
2028: }
2029: return $currentstring;
2030: }
2031:
2032: sub end_dl {
2033: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2034: my $currentstring = '';
2035: if ($target eq 'web' || $target eq 'webgrade') {
2036: $currentstring = $token->[2];
2037: } elsif ($target eq 'tex') {
2038: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2039: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
2040: foreach my $element (@{$Apache::londefdef::description[-1]}) {
2041: $currentstring.=' '.$element.' ';
2042: }
2043: pop(@Apache::londefdef::description);
2044: $currentstring.='\end{description}';
2045: delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
2046: delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
2047: delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
2048: $Apache::londefdef::DL--;
2049: }
2050: return $currentstring;
2051: }
2052:
2053: #-- <dt> tag (end tag optional)
2054: sub start_dt {
2055: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2056: my $currentstring='';
2057: if ($target eq 'web' || $target eq 'webgrade') {
2058: $currentstring = $token->[4];
2059: } elsif ($target eq 'tex') {
2060: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2061: if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
2062: &Apache::lonxml::startredirection();
2063: $Apache::londefdef::DT[-1]++;
2064: $Apache::londefdef::seenDT[-1]=1;
2065: }
2066: return $currentstring;
2067: }
2068:
2069: sub end_dt {
2070: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2071: my $currentstring = '';
2072: if ($target eq 'web' || $target eq 'webgrade') {
2073: $currentstring = $token->[2];
2074: } elsif ($target eq 'tex') {
2075: if ($Apache::londefdef::DT[-1]) {
2076: my $data=&item_cleanup();
2077: push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
2078: $Apache::londefdef::DT[-1]--;
2079: }
2080: }
2081: return $currentstring;
2082: }
2083:
2084: sub item_cleanup {
2085: my $item=&Apache::lonxml::endredirection();
2086: $item=~s/\\begin\{center}//g;
2087: $item=~s/\\end\{center}//g;
2088: return $item;
2089: }
2090:
2091: #-- <dd> tag (end tag optional)
2092: sub start_dd {
2093: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2094: my $currentstring = '';
2095: if ($target eq 'web' || $target eq 'webgrade') {
2096: $currentstring = $token->[4];
2097: } elsif ($target eq 'tex') {
2098: if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
2099: if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
2100: if (!$Apache::londefdef::seenDT[-1]) {
2101: push(@{$Apache::londefdef::description[-1]},'\item[\strut] \strut \vskip 0mm ');
2102: }
2103: push(@{$Apache::londefdef::description[-1]},'');
2104: $Apache::londefdef::description[-1]->[-1].=' \strut ';
2105: $Apache::londefdef::DD[-1]++;
2106: &Apache::lonxml::startredirection();
2107: }
2108: return $currentstring;
2109: }
2110:
2111: sub end_dd {
2112: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2113: my $currentstring = '';
2114: if ($target eq 'web' || $target eq 'webgrade') {
2115: $currentstring = $token->[2];
2116: } elsif ($target eq 'tex') {
2117: $Apache::londefdef::description[-1]->[-1].=
2118: &Apache::lonxml::endredirection().' \vskip 0mm ';
2119: $Apache::londefdef::DD[-1]--;
2120: }
2121: return $currentstring;
2122: }
2123:
2124: #-- <table> tag (end tag required)
2125: # <table> also ends any prior <p> that is not closed.
2126: # but, unless I allow <p>'s to nest, that's the
2127: # only way I could think of to allow <p> in
2128: # <tr> <th> bodies
2129: #
2130: #list of supported attributes: border,width,TeXwidth,TeXtheme
2131: # align
2132: sub start_table {
2133: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2134: my $textwidth = '';
2135: my $currentstring = &end_p();
2136: if ($target eq 'web' || $target eq 'webgrade') {
2137: $currentstring .= $token->[4];
2138: } elsif ($target eq 'tex') {
2139: &disable_para(); # Can't have paras in a table.
2140:
2141: # Get the parameters that we can do something about:
2142:
2143: my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0);
2144: my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0);
2145: my $theme = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0);
2146: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0);
2147: my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0);
2148:
2149: # The only thing that needs any figuring out is the width.. and then only if it is
2150: # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm
2151: #
2152:
2153: my $table = new Apache::lontable();
2154: if ((defined $border) && ($border > 0)) {
2155: # &Apache::lonnet::logthis("Turning on table borders: $border");
2156: $table->table_border(1);
2157: if (!defined $cell_border) {
2158: $table->cell_border(1); # Default for rules is all if rules not defined.
2159: }
2160: }
2161:
2162: if ((defined $cell_border)) {
2163: if ($cell_border eq 'all') {
2164: $table->cell_border(1);
2165: } elsif ($cell_border eq 'rows') {
2166: $table->cell_border(2);
2167: } elsif ($cell_border eq 'cols') {
2168: $table->cell_border(3);
2169: } elsif($cell_border eq 'groups') {
2170: $table->cell_border(4);
2171: } else {
2172: $table->cell_border(0);
2173: }
2174: }
2175: if (defined $theme) {
2176: $table->theme($theme);
2177: }
2178: if (defined $align) {
2179: $table->alignment($align);
2180: }
2181:
2182: # Missing width is most of page width
2183:
2184: if (!(defined $width)) {
2185: $width = '70%';
2186: }
2187:
2188: # If a percentage, need to calculate what this means in terms of
2189: # page width:
2190:
2191: if ($width =~ /%$/) {
2192: my $textwidth = &recalc($env{'form.textwidth'}); # Page width in mm.
2193: $width =~ s/%//;
2194: $width = $width * $textwidth / 100.0;
2195: $width .= " mm";
2196: $table->width($width);
2197: }
2198:
2199: push(@Apache::londefdef::table, $table);
2200: $currentstring.=' \keephidden{NEW TABLE ENTRY}';
2201:
2202: }
2203: return $currentstring;
2204: }
2205:
2206: sub end_table {
2207: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2208: my $currentstring = '';
2209: if ($target eq 'web' || $target eq 'webgrade') {
2210: $currentstring = $token->[2];
2211: } elsif ($target eq 'tex') {
2212:
2213:
2214: my $table = pop(@Apache::londefdef::table);
2215: my $t = $table->generate();
2216: # &Apache::lonnet::logthis("Generating string");
2217: $currentstring = $t->generate_string();
2218: # &Apache::lonnet::logthis("Generated: $currentstring");
2219: &enable_para();
2220:
2221: }
2222: return $currentstring;
2223: }
2224:
2225: #-- <tr> tag (end tag optional)
2226: sub start_tr {
2227: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2228: my $currentstring = '';
2229: if ($target eq 'web' || $target eq 'webgrade') {
2230: $currentstring = $token->[4];
2231: } elsif ($target eq 'tex') {
2232:
2233: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
2234: $Apache::londefdef::table[-1]->start_row();
2235:
2236: if ($align ne '') {
2237: $Apache::londefdef::table[-1]->configure_row({default_halign => $align});
2238: }
2239:
2240: #---------------------------------------------------------------
2241: # Old table code.
2242: #---------------------------------------------------------------
2243:
2244: if (0) {
2245: $Apache::londefdef::table[-1]{'row_number'}++;
2246: my $alignchar=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
2247: if ($alignchar ne '') {
2248: push @ {$Apache::londefdef::table[-1]{'rows'} },substr($alignchar,0,1);
2249: } else {
2250: push @ {$Apache::londefdef::table[-1]{'rows'} }, 'l';
2251: }
2252: push ( @{ $Apache::londefdef::table[-1]{'rowdata'} }, $Apache::londefdef::table[-1]{'hinc'});
2253: #
2254: # Need to save the number of table columns to preserve the max # columns.
2255: #
2256: $Apache::londefdef::table[-1]{'prior_columns'} = $Apache::londefdef::table[-1]{'counter_columns'};
2257: $Apache::londefdef::table[-1]{'counter_columns'} = -1;
2258: push @ {$Apache::londefdef::table[-1]{'TeXlen'}}, [];
2259: push @ {$Apache::londefdef::table[-1]{'objectlen'}}, [];
2260: push @ {$Apache::londefdef::table[-1]{'minlen'}}, [];
2261: push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
2262: push @ {$Apache::londefdef::table[-1]{'content'}}, [];
2263: }
2264: }
2265: return $currentstring;
2266: }
2267:
2268: sub end_tr {
2269: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2270: my $currentstring = &end_p(); # Close any pending <p> in the row.
2271: if ($target eq 'web' || $target eq 'webgrade') {
2272: $currentstring .= $token->[2];
2273: } elsif ($target eq 'tex') {
2274:
2275: # In case the user is missing a </td> or </th> tag:
2276:
2277: if ($Apache::londefdef::TD_redirection) {
2278: &end_td_tex($parstack,$parser,$safeeval);
2279: }
2280: $Apache::londefdef::table[-1]->end_row();
2281:
2282: #-----------------------------------------------
2283: # Old table code
2284: #-----------------------------------------------
2285:
2286: if (0) {
2287: if ($Apache::londefdef::TD_redirection) {
2288: &end_td_tex($parstack,$parser,$safeeval);
2289: }
2290: # Counter columns must be the maximum number of columns seen
2291: # in the table so far so:
2292: if ($Apache::londefdef::table[-1]{'prior_columns'} > $Apache::londefdef::table[-1]{'counter_columns'}) {
2293: $Apache::londefdef::table[-1]{'counter_columns'} = $Apache::londefdef::table[-1]{'prior_columns'};
2294: }
2295: }
2296:
2297:
2298: }
2299: return $currentstring;
2300: }
2301:
2302: #-- <td> tag (end tag optional)
2303: sub start_td {
2304: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2305: my $currentstring = '';
2306: if ($target eq 'web' || $target eq 'webgrade') {
2307: $currentstring = $token->[4];
2308: } elsif ($target eq 'tex') {
2309: $Apache::londefdef::TD_redirection = 1;
2310: &tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
2311: }
2312: return $currentstring;
2313: }
2314:
2315: sub tag_check {
2316: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2317: my @ar=@$parstack;
2318: for (my $i=$#ar-1;$i>=0;$i--) {
2319: if (lc($$tagstack[$i]) eq $good_tag) {
2320: &start_td_tex($parstack,$parser,$safeeval);
2321: last;
2322: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2323: splice @ar, $i+1;
2324: &end_td_tex(\@ar,$parser,$safeeval);
2325: &start_td_tex($parstack,$parser,$safeeval);
2326: last;
2327: }
2328: }
2329: return '';
2330: }
2331:
2332: #
2333: # Factor out cell configuration hash generation:
2334: #
2335:
2336: sub cell_config_hash {
2337: my ($align, $rowspan, $colspan, $width) = @_;
2338: if ($rowspan ne '') {
2339: $rowspan =~ s/^\s+|\s+$//g;
2340: }
2341: if ($colspan ne '') {
2342: $colspan =~ s/^\s+|\s+$//g;
2343: }
2344: my %config;
2345: if ($align ne '') {
2346: $config{'halign'} = $align;
2347: }
2348: if (($colspan =~ /^\d+$/) && ($colspan > 0)) {
2349: $config{'colspan'} = $colspan;
2350: }
2351: if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) {
2352: $config{'rowspan'} = $rowspan;
2353: }
2354: if ($width ne '') {
2355: $config{'width'} = $width;
2356: }
2357: return \%config;
2358: }
2359:
2360: sub start_td_tex {
2361: my ($parstack,$parser,$safeeval) = @_;
2362:
2363: # At this stage, an empty cell is created with the
2364: # appropriate rowspan/colspan and alignment
2365: # attributes, but empty of text. end_td_tex will
2366: # fetch the contents from the recursive parse and
2367: # fill the cell with them:
2368: my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval);
2369: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval);
2370: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval);
2371: my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval);
2372: my $config = &cell_config_hash($align, $rowspan, $colspan, $width);
2373:
2374: my $table = $Apache::londefdef::table[-1];
2375: $table->add_cell('', $config);
2376:
2377:
2378: #------------------------------------------------
2379: # Old table code.
2380: #------------------------------------------------
2381:
2382: if (0) {
2383:
2384: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2385: if ($alignchar eq '') {
2386: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2387: }
2388: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2389: $Apache::londefdef::table[-1]{'counter_columns'}++;
2390: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2391: if (defined $TeXwidth) {
2392: my $current_length=&recalc($TeXwidth);
2393: $current_length=~/(\d+\.?\d*)/;
2394: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2395: }
2396: }
2397: &Apache::lonxml::startredirection();
2398: return '';
2399: }
2400:
2401: sub end_td_tex {
2402:
2403: my $text = &Apache::lonxml::endredirection();
2404: my $table = $Apache::londefdef::table[-1];
2405: $table->append_cell_text($text);
2406:
2407: #-------------------------------------------------
2408: # Old table code
2409: #-------------------------------------------------
2410:
2411: if (0) {
2412: my ($parstack,$parser,$safeeval) = @_;
2413: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2414: my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
2415: my $data = &Apache::lonxml::endredirection();
2416:
2417: # The rowspan array of the table indicates which cells are part of a span.
2418: # n indicates the start of a span set of n rows.
2419: # ^ indicates a cell that continues a span set.
2420: # _ indicates the cell is at the bottom of a span set.
2421: # If this and subsequent cells are part of a rowspan, we must
2422: # push along the row until we find one that is not.
2423:
2424: while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
2425: && ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
2426: # Part of a span.
2427: push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
2428: $current_column++;
2429: }
2430: $Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
2431:
2432:
2433: # Get the column and row spans.
2434: # Colspan can be done via \multicolumn if I can figure out the data structs.
2435:
2436: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 0);
2437: if (!$colspan) {
2438: $colspan = 1;
2439: }
2440:
2441: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 0);
2442: if (!$rowspan) {
2443: $rowspan = 1;
2444: }
2445:
2446:
2447:
2448: for (my $c = 0; $c < $colspan; $c++) {
2449: $Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column+$c] = $rowspan;
2450: for (my $i = 1; $i < $rowspan; $i++) {
2451: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '^';
2452: if ($i == ($rowspan-1)) {
2453: $Apache::londefdef::table[-1]{'rowspan'}[$current_row+$i][$current_column+$c] = '_';
2454: }
2455: }
2456: }
2457:
2458: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2459: if (defined $TeXwidth) {
2460: for (my $c = 0; $c < $colspan; $c++) {
2461: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2462: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2463: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2464: }
2465: } else {
2466: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2467: my $garbage_data=$data;
2468: my $fwidth=0;
2469: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2470: my $current_length=&recalc($1);
2471: $current_length=~/(\d+\.?\d*)/;
2472: if ($fwidth<$1) {$fwidth=$1;}
2473: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2474: }
2475: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2476: my $current_length=$1;
2477: if ($fwidth<$current_length) {$fwidth=$current_length;}
2478: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2479: }
2480: for (my $c = 0; $c < $colspan; $c++) {
2481: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2482: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2483: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2484: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2485: }
2486: } 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)*/) {
2487: my $garbage_data=$data;
2488: my $fwidth=0;
2489: while ($garbage_data=~/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)\s*\}/) {
2490: my $current_length=&recalc($1);
2491: $current_length=~/(\d+\.?\d*)/;
2492: if ($fwidth<$1) {$fwidth=$1;}
2493: $garbage_data=~s/\\parbox\{\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2494: }
2495: while ($garbage_data=~/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2496: my $current_length=&recalc($1);
2497: $current_length=~/(\d+\.?\d*)/;
2498: if ($fwidth<$1) {$fwidth=$1;}
2499: $garbage_data=~s/\\epsfxsize\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2500: }
2501: for (my $c = 0; $c < $colspan; $c++) {
2502: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2503: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2504: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2505: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2506: }
2507: $data=~s/\\\\\s*$//;
2508: } else {
2509: $data=~s/^\s+(\S.*)/$1/;
2510: $data=~s/(.*\S)\s+$/$1/;
2511: $data=~s/(\s)+/$1/;
2512: my ($current_length,$min_length)=(0,0);
2513: if ($data=~/\\vskip/) {
2514: my $newdata=$data;
2515: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2516: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2517: foreach my $elementdata (@newdata) {
2518: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2519: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2520: my @words=split(/ /,$elementdata);
2521: foreach my $word (@words) {
2522: my $lengthword=2.5*&LATEX_length($word);
2523: if ($min_length<$lengthword) {$min_length=$lengthword;}
2524: }
2525: }
2526: } else {
2527: $current_length=2.5*&LATEX_length($data);
2528: my @words=split(/ /,$data);
2529: foreach my $word (@words) {
2530: my $lengthword=2*&LATEX_length($word);
2531: if ($min_length<$lengthword) {$min_length=$lengthword;}
2532: }
2533: }
2534: for (my $c = 0; $c < $colspan; $c++) {
2535: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2536: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2537: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2538: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2539: }
2540: }
2541: }
2542: # Substitute all of the tables nested in this cell in their appropriate places.
2543:
2544:
2545: my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
2546: for (my $in=0; $in<=$nested_count; $in++) {
2547: my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
2548: $nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
2549: # $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2550: $data =~ s/\\keephidden\{NEW TABLE ENTRY\}/$nested/;
2551:
2552: }
2553: # Should be be killing off the 'include' elements as they're used up?
2554:
2555: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2556:
2557:
2558:
2559:
2560: # the colspan array will indicate how many columns will be spanned by this
2561: # cell..this requires that counter_columns also be adjusted accordingly
2562: # so that the next bunch of text goes in the right cell. Note that since
2563: # counter_columns is incremented in the start_td_tex, we adjust by colspan-1.
2564: #
2565:
2566: $Apache::londefdef::table[-1]{'counter_columns'} += $colspan -1;
2567: for (my $i = 0; $i < ($colspan -1); $i++) {
2568: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },'';
2569: }
2570: for (my $r = 0; $r < $rowspan; $r++) {
2571: $Apache::londefdef::table[-1]{'colspan'}[$current_row+$r][$current_column] = $colspan;
2572: # Put empty text in spanned cols.
2573:
2574: }
2575:
2576: }
2577:
2578: return '';
2579: }
2580:
2581: sub end_td {
2582: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2583: my $currentstring = '';
2584: if ($target eq 'web' || $target eq 'webgrade') {
2585: $currentstring = $token->[2];
2586: } elsif ($target eq 'tex') {
2587: $Apache::londefdef::TD_redirection =0;
2588: &end_td_tex($parstack,$parser,$safeeval);
2589: }
2590: return $currentstring;
2591: }
2592:
2593: #-- <th> tag (end tag optional)
2594: sub start_th {
2595: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2596: my $currentstring = '';
2597: if ($target eq 'web' || $target eq 'webgrade') {
2598: $currentstring = $token->[4];
2599: } elsif ($target eq 'tex') {
2600: $Apache::londefdef::TD_redirection = 1;
2601: &tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
2602: }
2603: return $currentstring;
2604: }
2605:
2606: sub tagg_check {
2607: my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
2608: my @ar=@$parstack;
2609: for (my $i=$#ar-1;$i>=0;$i--) {
2610: if (lc($$tagstack[$i]) eq $good_tag) {
2611: &start_th_tex($parstack,$parser,$safeeval);
2612: last;
2613: } elsif (lc($$tagstack[$i]) eq $bad_tag) {
2614: splice @ar, $i+1;
2615: &end_th_tex(\@ar,$parser,$safeeval);
2616: &start_th_tex($parstack,$parser,$safeeval);
2617: last;
2618: }
2619: }
2620: return '';
2621: }
2622:
2623: sub start_th_tex {
2624: my ($parstack,$parser,$safeeval) = @_;
2625:
2626: my $alignment = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef,1);
2627: my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1);
2628: my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1);
2629:
2630: my $config = cell_config_hash($alignment, $rowspan, $colspan);
2631: my $table = $Apache::londefdef::table[-1];
2632: $table->add_cell('\textbf{', $config);
2633:
2634: #-------------------------------------------------------------------------------------
2635: #
2636: # Old table code.
2637: #
2638: #--------------------------------------------------------------------------------------
2639:
2640: if (0) {
2641:
2642:
2643: my $alignchar = substr(&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1),0,1);
2644: if ($alignchar eq '') {
2645: $alignchar = $Apache::londefdef::table[-1]{'rows'}[-1];
2646: }
2647: push @{ $Apache::londefdef::table[-1]{'align'}[$Apache::londefdef::table[-1]{'row_number'}] }, $alignchar;
2648: $Apache::londefdef::table[-1]{'counter_columns'}++;
2649: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2650: if (defined $TeXwidth) {
2651: my $current_length=&recalc($TeXwidth);
2652: $current_length=~/(\d+\.?\d*)/;
2653: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$1;
2654: }
2655: }
2656:
2657: # Accept xml until the </th> tag.
2658:
2659: &Apache::lonxml::startredirection();
2660: return '';
2661: }
2662:
2663: sub end_th_tex {
2664: my ($parstack,$parser,$safeeval) = @_;
2665:
2666: my $table = $Apache::londefdef::table[-1];
2667: my $text = &Apache::lonxml::endredirection();
2668: $table->append_cell_text($text.'}');
2669:
2670: #-----------------------------------------------------------------------------
2671: # Old table code:
2672: #-----------------------------------------------------------------------------
2673:
2674: if (0) {
2675: my $current_row = $Apache::londefdef::table[-1]{'row_number'};
2676: my $data=&Apache::lonxml::endredirection();
2677: my $TeXwidth=&Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0);
2678: if (defined $TeXwidth) {
2679: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2680: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2681: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2682: } else {
2683: if (($data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) or ($data=~m/\[(\d+\.?\d*)\s*mm\]/)) {
2684: my $garbage_data=$data;
2685: my $fwidth=0;
2686: while ($garbage_data=~m/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)/) {
2687: my $current_length=&recalc($1);
2688: $current_length=~/(\d+\.?\d*)/;
2689: if ($fwidth<$1) {$fwidth=$1;}
2690: $garbage_data=~s/width\s*=\s*(\d+\.?\d*\s*(mm|cm|in|pc|pt)*)//;
2691: }
2692: while ($garbage_data=~m/\[(\d+\.?\d*)\s*mm\]/) {
2693: my $current_length=$1;
2694: if ($fwidth<$current_length) {$fwidth=$current_length;}
2695: $garbage_data=~s/\[(\d+\.?\d*)\s*mm\]//;
2696: }
2697: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2698: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
2699: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2700: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2701: } else {
2702: $data=~s/^\s+(\S.*)/$1/;
2703: $data=~s/(.*\S)\s+$/$1/;
2704: $data=~s/(\s)+/$1/;
2705: my ($current_length,$min_length)=(0,0);
2706: if ($data=~/\\vskip/) {
2707: my $newdata=$data;
2708: $newdata=~s/\\vskip \d*\.?\d*\s*mm/THISISJUSTTEMPORARYSEPARATOR/g;
2709: my @newdata=split(/THISISJUSTTEMPORARYSEPARATOR/,$newdata);
2710: foreach my $elementdata (@newdata) {
2711: my $lengthnewdata=2.5*&LATEX_length($elementdata);
2712: if ($lengthnewdata>$current_length) {$current_length=$lengthnewdata;}
2713: my @words=split(/ /,$elementdata);
2714: foreach my $word (@words) {
2715: my $lengthword=2.5*&LATEX_length($word);
2716: if ($min_length<$lengthword) {$min_length=$lengthword;}
2717: }
2718: }
2719: } else {
2720: $current_length=2.5*&LATEX_length($data);
2721: my @words=split(/ /,$data);
2722: foreach my $word (@words) {
2723: my $lengthword=2*&LATEX_length($word);
2724: if ($min_length<$lengthword) {$min_length=$lengthword;}
2725: }
2726: }
2727: push @ {$Apache::londefdef::table[-1]{'TeXlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2728: push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
2729: push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
2730: push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
2731: }
2732: }
2733: for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
2734: $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
2735: }
2736: #make data bold
2737: $data='\textbf{'.$data.'}';
2738: push @ {$Apache::londefdef::table[-1]{'content'}[-1] },$data;
2739: }
2740: return'';
2741: }
2742:
2743: sub end_th {
2744: my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
2745: my $currentstring = &end_p(); # Close any open <p> in the row.
2746: if ($target eq 'web' || $target eq 'webgrade') {
2747: $currentstring .= $token->[2];
2748: } elsif ($target eq 'tex') {
2749: $Apache::londefdef::TD_redirection =0;
2750: &end_th_tex($parstack,$parser,$safeeval);
2751: }
2752: return $currentstring;
2753: }
2754:
2755: #-- <img> tag (end tag forbidden)
2756: #
2757: # Render the <IMG> tag.
2758: # <IMG> has the following attributes (in addition to the
2759: # standard HTML ones:
2760: # TeXwrap - Governs how the tex target will try to wrap text around
2761: # horizontally aligned images.
2762: # TeXwidth - The width of the image when rendered for print (mm).
2763: # TeXheight - The height of the image when rendered for print (mm)
2764: # (Note there seems to also be support for this as a % of page size)
2765: #
2766: sub start_img {
2767: my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
2768: my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
2769: undef,1);
2770: if (! $src &&
2771: ($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
2772: ) {
2773: my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
2774: return '';
2775: }
2776: unless ($src =~ m{^data\:image/gif;base64,}) {
2777: &Apache::lonxml::extlink($src);
2778: }
2779: my $currentstring = '';
2780: my $scaling = .3;
2781:
2782: # Render unto browsers that which are the browser's...
2783:
2784: if ($target eq 'web' || $target eq 'webgrade') {
2785: my $enc = ('yes' eq
2786: lc(&Apache::lonxml::get_param('encrypturl',$parstack,
2787: $safeeval)));
2788: unless ($src =~ m{^data\:image/gif;base64,}) {
2789: $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
2790: $enc);
2791: }
2792:
2793: # and render unto TeX that which is LaTeX
2794: } elsif ($target eq 'tex') {
2795: #
2796: # The alignment will require some superstructure to be put around
2797: # the \includegraphics stuff. At present we can only partially
2798: # simulate the alignments offered by html.
2799: #
2800: #
2801: my $align = lc(&Apache::lonxml::get_param('align',
2802: $parstack,
2803: $safeeval,
2804: undef,1));
2805: if(!$align) {
2806: $align = "bottom"; # This is html's default so it's ours too.
2807: }
2808: #
2809: &Apache::lonxml::debug("Alignemnt = $align");
2810: # LaTeX's image/text wrapping is really bad since it wants to
2811: # make figures float.
2812: # The user has the optional parameter (applicable only to l/r
2813: # alignment to use the picins/parpic directive to get wrapped text
2814: # this is also imperfect.. that's why we give them a choice...
2815: # so they can't yell at us for our choice.
2816: #
2817: my $latex_rendering = &Apache::lonxml::get_param('TeXwrap',
2818: $parstack,
2819: $safeeval,
2820: undef,0);
2821: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering");
2822: if(!$latex_rendering) {
2823: $latex_rendering = "texwrap";
2824: }
2825: # using texwrap inside a table does not work. So, if after all of this,
2826: # texwrap is on, we turn it off if we detect we're in a table:
2827: #
2828: if (($latex_rendering eq 'texwrap') && &is_inside_of($tagstack, "table")) {
2829: $latex_rendering = 'parpic';
2830: }
2831:
2832: # &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
2833:
2834: #if original bmp/gif/jpg/png/svg file exist do following:
2835: my $origsrc=$src;
2836: my ($path,$file) = &get_eps_image($src);
2837: # &Apache::lonnet::logthis("Image source: $src result: $path $file");
2838: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
2839: &Apache::lonxml::debug("path = $path file = $file src = $src");
2840: if (-e $src) {
2841: &Apache::lonxml::debug("$src exists");
2842: my ($height_param,$width_param)=
2843: &image_size($origsrc,0.3,$parstack,$safeeval);
2844: my $size;
2845: if ($width_param) { $size.='width='.$width_param.' mm,'; }
2846: if ($height_param) { $size.='height='.$height_param.' mm]'; }
2847: # Default size if not able to extract that (e.g. eps image).
2848:
2849: # &Apache::lonnet::logthis("Size = $size");
2850:
2851: $size='['.$size;
2852: $size=~s/,$/]/;
2853: $currentstring .= '\graphicspath{{'.$path.'}}'
2854: .'\includegraphics'.$size.'{'.$file.'} ';
2855: my $closure;
2856: ($currentstring, $closure) = &align_latex_image($align,
2857: $latex_rendering,
2858: $currentstring,
2859: $width_param,
2860: $height_param);
2861: $currentstring .= $closure;
2862:
2863: } else {
2864: &Apache::lonxml::debug("$src does not exist");
2865: #original image file doesn't exist so check the alt attribute
2866: my $alt =
2867: &Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
2868: unless ($alt) {
2869: $alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
2870: }
2871:
2872: if ($alt) { $currentstring .= ' '.$alt.' '; }
2873: }
2874:
2875: # And here's where the semi-quote breaks down: allow the user
2876: # to edit the beast as well by rendering the problem for edit:
2877: } elsif ($target eq 'edit') {
2878: my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
2879: $currentstring .=&Apache::edit::tag_start($target,$token);
2880: $currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
2881: &Apache::edit::browse('src',undef,'alt',$only).' '.
2882: &Apache::edit::search('src',undef,'alt').'<br />';
2883: $currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'<br />';
2884: $currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
2885: $currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'<br />';
2886: $currentstring .=&Apache::edit::text_arg('TeXwidth (mm):','TeXwidth',$token,5);
2887: $currentstring .=&Apache::edit::text_arg('TeXheight (mm):','TeXheight',$token,5);
2888: $currentstring .=&Apache::edit::select_arg('Alignment:','align',
2889: ['','bottom','middle','top','left','right'],$token,5);
2890: $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap',
2891: ['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
2892: my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
2893: my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
2894:
2895: $currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
2896: ['no','yes'], $token, 2);
2897: if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
2898: $currentstring.='<br /><span class="LC_warning">'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'</span><br />';
2899: }
2900: $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row();
2901: my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
2902: my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
2903: my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
2904:
2905: if ($token->[2]{'src'}=~/\$/) {
2906: $currentstring.=&mt('Variable image source');
2907: } elsif ($token->[2]{'src'}=~/\S/) {
2908: $currentstring .= '<img src="'.$src.'" alt="'.$alt.'" ';
2909: if ($width) { $currentstring.=' width="'.$width.'" '; }
2910: if ($height) { $currentstring.=' height="'.$height.'" '; }
2911: $currentstring .= ' />';
2912: } else {
2913: $currentstring.=&mt("No image source specified");
2914: }
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 height="">
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('height',$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: #-- <span> tag (end tag required)
4061: sub start_span {
4062: my ($target,$token) = @_;
4063: my $currentstring = '';
4064: if ($target eq 'web' || $target eq 'webgrade') {
4065: $currentstring = $token->[4];
4066: }
4067: return $currentstring;
4068: }
4069:
4070: sub end_span {
4071: my ($target,$token) = @_;
4072: my $currentstring = '';
4073: if ($target eq 'web' || $target eq 'webgrade') {
4074: $currentstring = $token->[2];
4075: }
4076: return $currentstring;
4077: }
4078:
4079: #-- <tbody> tag (end tag optional)
4080: sub start_tbody {
4081: my ($target,$token) = @_;
4082: my $currentstring = '';
4083: if ($target eq 'web' || $target eq 'webgrade') {
4084: $currentstring = $token->[4];
4085: }
4086: if ($target eq 'tex') {
4087: # TODO: Ensure this tag is within a table:
4088:
4089: my $table = $Apache::londefdef::table[-1];
4090: $table->start_body();
4091: }
4092: return $currentstring;
4093: }
4094:
4095: sub end_tbody {
4096: my ($target,$token) = @_;
4097: my $currentstring = '';
4098: if ($target eq 'web' || $target eq 'webgrade') {
4099: $currentstring = $token->[2];
4100: }
4101: if($target eq 'tex') {
4102: # TODO: Ensure this tag is within a table:
4103:
4104: my $table = $Apache::londefdef::table[-1];
4105: $table->end_body();
4106: }
4107: return $currentstring;
4108: }
4109:
4110: #-- <tfoot> tag (end tag optional)
4111: sub start_tfoot {
4112: my ($target,$token) = @_;
4113: my $currentstring = '';
4114: if ($target eq 'web' || $target eq 'webgrade') {
4115: $currentstring = $token->[4];
4116: }
4117: if ($target eq 'tex') {
4118: # TODO: ensure this is within a table tag.
4119: my $table = $Apache::londefdef::table[-1];
4120: $table->start_foot();
4121: }
4122: return $currentstring;
4123: }
4124:
4125: sub end_tfoot {
4126: my ($target,$token) = @_;
4127: my $currentstring = '';
4128: if ($target eq 'web' || $target eq 'webgrade') {
4129: $currentstring = $token->[2];
4130: }
4131: if ($target eq 'tex') {
4132: # TODO: Ensure this is in side a table
4133: my $table = $Apache::londefdef::table[-1];
4134: $table->end_foot();
4135: }
4136: return $currentstring;
4137: }
4138:
4139: #-- <thead> tag (end tag optional)
4140: sub start_thead {
4141: my ($target,$token) = @_;
4142: my $currentstring = '';
4143: if ($target eq 'web' || $target eq 'webgrade') {
4144: $currentstring = $token->[4];
4145: }
4146: if ($target eq 'tex') {
4147: # Assume we're in a table... TODO: Verify that and ignore tag if not.
4148: my $table = $Apache::londefdef::table[-1];
4149: $table->start_head();
4150: }
4151: return $currentstring;
4152: }
4153:
4154: sub end_thead {
4155: my ($target,$token) = @_;
4156: my $currentstring = '';
4157: if ($target eq 'web' || $target eq 'webgrade') {
4158: $currentstring = $token->[2];
4159: }
4160: if ($target eq 'tex') {
4161: # TODO: Verify we are in a table and ignore tag if not.
4162:
4163: my $table = $Apache::londefdef::table[-1];
4164: $table->end_head();
4165: }
4166: return $currentstring;
4167: }
4168:
4169: #-- <var> tag
4170: sub start_var {
4171: my ($target,$token) = @_;
4172: my $currentstring = '';
4173: if ($target eq 'web' || $target eq 'webgrade') {
4174: $currentstring = $token->[4];
4175: } elsif ($target eq 'tex') {
4176: $currentstring = '\textit{';
4177: }
4178: return $currentstring;
4179: }
4180:
4181: sub end_var {
4182: my ($target,$token) = @_;
4183: my $currentstring = '';
4184: if ($target eq 'web' || $target eq 'webgrade') {
4185: $currentstring = $token->[2];
4186: } elsif ($target eq 'tex') {
4187: $currentstring = '}';
4188: }
4189: return $currentstring;
4190: }
4191:
4192: #-- <wbr> tag (end tag forbidden)
4193: sub start_wbr {
4194: my ($target,$token) = @_;
4195: my $currentstring = '';
4196: if ($target eq 'web' || $target eq 'webgrade') {
4197: $currentstring = $token->[4];
4198: }
4199: return $currentstring;
4200: }
4201:
4202: sub end_wbr {
4203: my ($target,$token) = @_;
4204: my $currentstring = '';
4205: if ($target eq 'web' || $target eq 'webgrade') {
4206: $currentstring = $token->[2];
4207: }
4208: return $currentstring;
4209: }
4210:
4211: #-- <hideweboutput> tag
4212: sub start_hideweboutput {
4213: my ($target,$token) = @_;
4214: if ($target eq 'web' || $target eq 'webgrade') {
4215: &Apache::lonxml::startredirection();
4216: }
4217: return '';
4218: }
4219:
4220: sub end_hideweboutput {
4221: my ($target,$token) = @_;
4222: my $currentstring = '';
4223: if ($target eq 'web' || $target eq 'webgrade') {
4224: $currentstring = &Apache::lonxml::endredirection();
4225: }
4226: return '';
4227: }
4228:
4229:
4230: sub image_replication {
4231: my $src = shift;
4232: if (not -e $src) { &Apache::lonnet::repcopy($src); }
4233: #replicates eps or ps
4234: my $epssrc = my $pssrc = $src;
4235: $epssrc =~ s/\.(gif|jpg|jpeg|png)$/.eps/i;
4236: $pssrc =~ s/\.(gif|jpg|jpeg|png)$/.ps/i;
4237: if (not -e $epssrc && not -e $pssrc) {
4238: my $result=&Apache::lonnet::repcopy($epssrc);
4239: if ($result ne 'ok') { &Apache::lonnet::repcopy($pssrc); }
4240: }
4241: return '';
4242: }
4243:
4244:
4245:
4246: sub resize_image {
4247: my ($height_param, $width_param, $scaling,
4248: $parstack, $safeeval, $depth, $cis) = @_;
4249:
4250: # First apply the scaling...
4251:
4252: $height_param = $height_param * $scaling;
4253: $width_param = $width_param * $scaling;
4254:
4255: #do we have any specified LaTeX size of the picture?
4256: my $toget='TeXwidth';
4257: if ($cis) {
4258: $toget=lc($toget);
4259: }
4260: my $TeXwidth = &Apache::lonxml::get_param($toget,$parstack,
4261: $safeeval,$depth,$cis);
4262: $toget='TeXheight'; if ($cis) { $toget=lc($toget); }
4263: my $TeXheight = &Apache::lonxml::get_param($toget,$parstack,
4264: $safeeval,$depth,$cis);
4265: #do we have any specified web size of the picture?
4266: my $width = &Apache::lonxml::get_param('width',$parstack,$safeeval,
4267: $depth,1);
4268: if ($TeXwidth) {
4269: my $old_width_param=$width_param;
4270: if ($TeXwidth=~/(\d+)\s*\%/) {
4271: $width_param = $1*$env{'form.textwidth'}/100;
4272: } else {
4273: $width_param = $TeXwidth;
4274: }
4275: if ($TeXheight) {
4276: $height_param = $TeXheight;
4277: } elsif ($old_width_param) {
4278: $height_param=$TeXwidth/$old_width_param*$height_param;
4279: }
4280: } elsif ($TeXheight) {
4281: if ($height_param) {
4282: $width_param = $TeXheight/$height_param*$width_param;
4283: }
4284: $height_param = $TeXheight;
4285: } elsif ($width) {
4286: my $old_width_param=$width_param;
4287: $width_param = $width*$scaling;
4288: if ($old_width_param) {
4289: $height_param=$width_param/$old_width_param*$height_param;
4290: }
4291: }
4292: if ($width_param > $env{'form.textwidth'}) {
4293: my $old_width_param=$width_param;
4294: $width_param =0.95*$env{'form.textwidth'};
4295: if ($old_width_param) {
4296: $height_param=$width_param/$old_width_param*$height_param;
4297: }
4298: }
4299:
4300: return ($height_param, $width_param);
4301: }
4302:
4303: sub image_size {
4304: my ($src,$scaling,$parstack,$safeeval,$depth,$cis)=@_;
4305:
4306: #size of image from gif/jpg/jpeg/png
4307: my $ressrc=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4308: if (-e $ressrc) {
4309: $src = $ressrc;
4310: }
4311: my $image = Image::Magick->new;
4312: my $current_figure = $image->Read($src);
4313: my $width_param = $image->Get('width');
4314: my $height_param = $image->Get('height');
4315: &Apache::lonxml::debug("Image magick says: $src : Height = $height_param width = $width_param");
4316: undef($image);
4317:
4318: ($height_param, $width_param) = &resize_image($height_param, $width_param,
4319: $scaling, $parstack, $safeeval,
4320: $depth, $cis);
4321:
4322: return ($height_param, $width_param);
4323: }
4324:
4325: sub image_width {
4326: my ($height, $width) = &image_size(@_);
4327: return $width;
4328: }
4329: # Not yet 100% sure this is correct in all circumstances..
4330: # due to my uncertainty about mods to image_size.
4331: #
4332: sub image_height {
4333: my ($height, $width) = &image_size(@_);
4334: return $height;
4335: }
4336:
4337: sub get_eps_image {
4338: my ($src)=@_;
4339: my $orig_src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1], $src);
4340:
4341: # In order to prevent the substitution of the alt text, we need to
4342: # be sure the orig_src file is on system now so:
4343:
4344: if (! -e $orig_src) {
4345: &Apache::lonnet::repcopy($orig_src); # Failure is not completely fatal.
4346: }
4347: &Apache::lonxml::debug("get_eps_image: Original image: $orig_src");
4348: my ($spath, $sname, $sext) = &fileparse($src, qr/\.(bmp|gif|png|jpg|jpeg|svg)/i);
4349: $src=~s/\.(bmp|gif|png|jpg|jpeg|svg)$/\.eps/i;
4350: $src=&Apache::lonnet::filelocation($Apache::lonxml::pwd[-1],$src);
4351: &Apache::lonxml::debug("Filelocation gives: $src");
4352: if (! -e $src) {
4353: &Apache::lonxml::debug("$src does not exist");
4354: if (&Apache::lonnet::repcopy($src) ne 'ok' ) {
4355: &Apache::lonxml::debug("Repcopy of $src failed (1)");
4356: #if replication failed try to find ps file
4357: $src=~s/\.eps$/\.ps/;
4358: &Apache::lonxml::debug("Now looking for $src");
4359: #if no ps file try to replicate it.
4360: my $didrepcopy = &Apache::lonnet::repcopy($src);
4361: &Apache::lonxml::debug("repcopy of $src ... $didrepcopy");
4362: if ( (not -e $src) ||
4363: ($didrepcopy ne 'ok')) {
4364: &Apache::lonxml::debug("Failed to find or replicate $src");
4365:
4366: #if replication failed try to produce eps file dynamically
4367: $src=~s/\.ps$/\.eps/;
4368: if (open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat")) {
4369: my $newsrc=$orig_src;
4370: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4371: &Apache::lonxml::debug("queueing $newsrc for dynamic eps production.");
4372: print FILE ("$newsrc\n");
4373: close(FILE);
4374: }
4375: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4376: $src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
4377: if ($sext ne "") { # Put the ext. back in to uniquify.
4378: $src =~ s/\.eps$/$sext.eps/;
4379: }
4380:
4381: }
4382:
4383: }
4384: } else {
4385: # If the postscript file has spaces in its name,
4386: # LaTeX will gratuitiously vomit. Therefore
4387: # queue such files for copy with " " replaced by "_".
4388: # printout.pm will know them by their .ps or .eps extensions.
4389: my $newsrc = $orig_src;
4390: $newsrc =~ s|(.*)/res/|/home/httpd/html/res/|;
4391: open(FILE,">>/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat");
4392: print FILE "$src\n";
4393: close FILE;
4394: $src=~s|/home/httpd/html/res|/home/httpd/prtspool|;
4395: $src=~s|/home/httpd/html/priv/[^/]+/([^/]*)/|/home/httpd/prtspool/$1/|;
4396: }
4397: my ($path,$file)=($src=~m|(.*)/([^/]*)$|);
4398: $path =~ s/ /\_/g;
4399: $file =~ s/ /\_/g;
4400: &Apache::lonxml::debug("get_eps_image returning: $path / $file<BR />");
4401: return ($path.'/',$file);
4402: }
4403:
4404: sub eps_generation {
4405: my ($src,$file,$width_param) = @_;
4406: my $filename = "/home/httpd/prtspool/$env{'user.name'}_$env{'user.domain'}_printout.dat";
4407: if (open(my $tmpfile,">>$filename")) {
4408: print $tmpfile "$src\n";
4409: close($tmpfile);
4410: }
4411: my $newsrc = $src;
4412: $newsrc =~ s/(\.bmp|\.gif|\.jpg|\.jpeg)$/\.eps/i;
4413: $newsrc=~s{/home/httpd/html/res}{};
4414: $newsrc=~s{/home/httpd/html/priv/[^/]+/($LONCAPA::username_re)/}{/$1/};
4415: $newsrc=~s{/\./}{/};
4416: $newsrc=~s{/([^/]+)\.(ps|eps)}{/};
4417: if ($newsrc=~m{/home/httpd/lonUsers/}) {
4418: $newsrc=~s{/home/httpd/lonUsers}{};
4419: $newsrc=~s{/($LONCAPA::domain_re)/./././}{/$1/};
4420: }
4421: if ($newsrc=~m{/userfiles/}) {
4422: return ' \graphicspath{{'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4423: } else {
4424: return ' \graphicspath{{/home/httpd/prtspool'.$newsrc.'}}\includegraphics[width='.$width_param.' mm]{'.$file.'} ';
4425: }
4426: }
4427:
4428: sub file_path {
4429: my $src=shift;
4430: my ($file,$path);
4431: if ($src =~ m!(.*)/([^/]*)$!) {
4432: $file = $2;
4433: $path = $1.'/';
4434: }
4435: return $file,$path;
4436: }
4437:
4438:
4439: sub recalc {
4440: my $argument = shift;
4441: if (not $argument=~/(mm|cm|in|pc|pt)/) {return $argument.' mm';}
4442: $argument=~/\s*(\d+\.?\d*)\s*(mm|cm|in|pc|pt)/;
4443: my $value=$1;
4444: my $units=$2;
4445: if ($units eq 'cm') {
4446: $value*=10;
4447: } elsif ($units eq 'in') {
4448: $value*=25.4;
4449: } elsif ($units eq 'pc') {
4450: $value*=(25.4*12/72.27);
4451: } elsif ($units eq 'pt') {
4452: $value*=(25.4/72.27);
4453: }
4454: return $value.' mm';
4455: }
4456:
4457: sub LATEX_length {
4458: my $garbage=shift;
4459: $garbage=~s/^\s+$//;
4460: $garbage=~s/^\s+(\S.*)/$1/;#space before
4461: $garbage=~s/(.*\S)\s+$/$1/;#space after
4462: $garbage=~s/(\s)+/$1/;#only one space
4463: $garbage=~s/(\\begin\{([^\}]+)}|\\end\{([^\}]+)})//g;#remove LaTeX \begin{...} and \end{...}
4464: $garbage=~s/(\$\_\{|\$\_|\$\^\{|\$\^|\}\$)//g;#remove $_{,$_,$^{,$^,}$
4465: $garbage=~s/([^\\])\$/$1/g;#$
4466: $garbage=~s/(\\ensuremath\{\_\{|\\ensuremath\{\_|\\ensuremath\{\^\{|\\ensuremath\{\^|\})//g;#remove \ensuremath{...}
4467: $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;
4468: $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;
4469: $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;
4470: $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;
4471: $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;
4472: $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;
4473: $garbage=~s/(\\hat\{([^}]+)}|\\check\{([^}]+)}|\\dot\{([^}]+)}|\\breve\{([^}]+)}|\\acute\{([^}]+)}|\\ddot\{([^}]+)}|\\grave\{([^}]+)}|\\tilde\{([^}]+)}|\\mathring\{([^}]+)}|\\bar\{([^}]+)}|\\vec\{([^}]+)})/$1/g;
4474: #remove some other LaTeX command
4475: $garbage=~s|\\(\w+)\\|\\|g;
4476: $garbage=~s|\\(\w+)(\s*)|$2|g;
4477: $garbage=~s|\+|11|g;
4478: my $value=length($garbage);
4479: return $value;
4480: }
4481:
4482:
4483: sub align_latex_image {
4484: my ($align, $latex_rendering, $image, $width, $height) = @_;
4485: my $currentstring; # The 1/2 wrapped image.
4486: my $closure; # The closure of the wrappage.
4487:
4488: # if it's none just return it back
4489: if ($latex_rendering eq 'none') {
4490: return ($image,'');
4491: }
4492:
4493: # If there's an alignment specification we need to honor it here.
4494: # For the horizontal alignments, we will also honor the
4495: # value of the latex specfication. The default is parbox,
4496: # and that's used for illegal values too.
4497: #
4498: # Even though we set a default alignment value, the user
4499: # could have given us an illegal value. In that case we
4500: # just use the default alignment of bottom..
4501: $currentstring = '';
4502: if ($align eq "top") {
4503: $currentstring .= '\raisebox{-'.$height.'mm}{'.$image;
4504: $closure = '}';
4505: } elsif (($align eq "center") || ($align eq "middle")) { # Being kind
4506: my $offset = $height/2;
4507: $currentstring .= '\raisebox{-'.$offset.'mm}{'.$image;
4508: $closure = '}';
4509: } elsif ($align eq "left") {
4510: if ($latex_rendering eq "parpic") {
4511: $currentstring .= '\parpic[l]{'.$image;
4512: $closure = '}';
4513: } elsif ($latex_rendering eq "parbox") {
4514: $currentstring .= '\begin{minipage}[l]{'.$width.'mm}'
4515: .$image;
4516: $closure = '\end{minipage}';
4517: } elsif ($latex_rendering eq "wrapfigure"
4518: || $latex_rendering ne 'none') { # wrapfig render
4519: $currentstring .=
4520: '\begin{wrapfigure}{l}{'.$width.'mm}'
4521: .'\scalebox{1.0}{'.$image;
4522: $closure = '}\end{wrapfigure}';
4523: }
4524: } elsif ($align eq "right") {
4525: if ($latex_rendering eq "parpic") {
4526: $currentstring .= '\parpic[r]{'.$image;
4527: $closure = '}';
4528: } elsif ($latex_rendering eq "parbox") {
4529: $currentstring .= '\begin{minipage}[r]{'.$width.'mm}'
4530: .$image;
4531: $closure = '\end{minipage}';
4532: } elsif ($latex_rendering eq "wrapfigure"
4533: || $latex_rendering ne 'none') { # wrapfig render
4534: $currentstring .=
4535: '\begin{wrapfigure}{r}{'.$width.'mm}'
4536: .'\scalebox{1.0}{'.$image;
4537: $closure = '}\end{wrapfigure}';
4538: }
4539: } else { # Bottom is also default.
4540: # $currentstring = '\raisebox{'.$height.'mm}{'.$image.'}';
4541: $currentstring .= "{$image";
4542: $closure = '}';
4543: }
4544: return ($currentstring, $closure);
4545: }
4546:
4547:
4548: sub is_inside_of {
4549: my ($tagstack, $tag) = @_;
4550: my @stack = @$tagstack;
4551: for (my $i = ($#stack - 1); $i >= 0; $i--) {
4552: if ($stack[$i] eq $tag) {
4553: return 1;
4554: }
4555: }
4556: return 0;
4557: }
4558:
4559:
4560: #
4561: # This sub provides the typical LaTeX prefix matter for tex output:
4562: #
4563: sub latex_header {
4564: my ($mode) = @_;
4565: my $currentstring = '';
4566:
4567: $currentstring .=
4568: "\n% &Apache::lonxml::londefdef \n" .
4569: '\documentclass[letterpaper,twoside]{article}\raggedbottom';
4570: if (($env{'form.latex_type'}=~'batchmode') ||
4571: (!$env{'request.role.adv'}) ||
4572: ($mode eq 'batchmode')) {$currentstring .='\batchmode';}
4573: $currentstring .= '\newcommand{\keephidden}[1]{}'.
4574: '\renewcommand{\deg}{$^{\circ}$}'.
4575: '\usepackage{multirow}'."\n".
4576: '\usepackage{longtable}'."\n".
4577: '\usepackage{textcomp}'."\n".
4578: '\usepackage{makeidx}'."\n".
4579: '\usepackage[dvips]{graphicx}'."\n".
4580: '\usepackage{wrapfig}'."\n".
4581: '\usepackage{picins}'."\n".
4582: '\usepackage[T1]{fontenc}'."\n".
4583: '\usepackage{lmodern}'."\n".
4584: '\usepackage[postscript]{ucs}'."\n".
4585: '\usepackage[utf8x]{inputenc}'."\n".
4586: '\usepackage{pifont}'."\n".
4587: '\usepackage{latexsym}'."\n".
4588: '\usepackage{epsfig}'."\n".
4589: '\usepackage{xtab}'."\n".
4590: '\usepackage{tabularx}'."\n".
4591: '\usepackage{booktabs}'."\n".
4592: '\usepackage{array}'."\n".
4593: '\usepackage{colortbl}'."\n".
4594: '\usepackage{xcolor}'."\n".
4595: '\usepackage{calc}'."\n".
4596: '\usepackage{amsmath}'."\n".
4597: '\usepackage{soul}'."\n".
4598: '\usepackage{amssymb}'."\n".
4599: '\usepackage{amsfonts}'."\n".
4600: '\usepackage{amsthm}'."\n".
4601: '\usepackage{amscd}'."\n".
4602: '\usepackage{actuarialangle}'."\n";
4603: if($env{'form.pdfFormFields'} eq 'yes') {
4604: $currentstring .= '\usepackage{hyperref}'.
4605: '\usepackage{eforms}'.
4606: '\usepackage{tabularx}';
4607: }
4608:
4609: $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}}'.
4610: '\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}}';
4611: $currentstring .= '\begin{document}';
4612:
4613: return $currentstring;
4614:
4615: }
4616:
4617: sub clean_docs_httpref {
4618: my ($href,$docuri,$cdom,$cnum) = @_;
4619: if ($docuri eq '') {
4620: $docuri = &Apache::lonnet::hreflocation('',$env{'request.filename'});
4621: }
4622: if ($cdom eq '') {
4623: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
4624: }
4625: if ($cnum eq '') {
4626: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
4627: }
4628: my $cleanhref;
4629: if ($docuri =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/)(.+/)[^/]+$}) {
4630: my $prefix = $1;
4631: my $relpath = $2;
4632: my ($hrefpath,$fname);
4633: if ($href =~ m{^/}) {
4634: if ($href =~ m{^\Q$prefix\E(.+/)([^/]+)$}) {
4635: $hrefpath = $1;
4636: $fname = $2;
4637: } else {
4638: return $cleanhref;
4639: }
4640: } else {
4641: if ($href =~ m{/}) {
4642: (my $path,$fname) = ($href =~ m{^(.*)/([^/]*)$});
4643: $hrefpath = $relpath.$path;
4644: if ($path eq '') {
4645: $hrefpath =~ s{/$}{};
4646: }
4647: } else {
4648: $fname = $href;
4649: $hrefpath = $relpath;
4650: $hrefpath =~ s{/$}{};
4651: }
4652: }
4653: if ($fname ne '') {
4654: my $cleanrelpath;
4655: foreach my $dir (split(/\//,$hrefpath)) {
4656: next if ($dir eq '.');
4657: if ($dir eq '..') {
4658: $cleanrelpath =~ s{([^/]+/)$}{};
4659: } else {
4660: $cleanrelpath .= $dir.'/';
4661: }
4662: }
4663: if ($cleanrelpath ne '') {
4664: $cleanhref = $prefix.$cleanrelpath.$fname;
4665: } else {
4666: $cleanhref = $prefix.$fname;
4667: }
4668: }
4669: }
4670: return $cleanhref;
4671: }
4672:
4673: =pod
4674:
4675: =head1 NAME
4676:
4677: Apache::londefdef.pm
4678:
4679: =head1 SYNOPSIS
4680:
4681: Tags Default Definition Module
4682:
4683: This is part of the LearningOnline Network with CAPA project
4684: described at http://www.lon-capa.org.
4685:
4686:
4687: =head1 NOTABLE SUBROUTINES
4688:
4689: =over
4690:
4691: =item start_hideweboutput()
4692:
4693: =item end_hideweboutput()
4694:
4695: =item image_replication()
4696:
4697: =item resize_image()
4698:
4699: Get correct sizing parameter for an image given
4700: it's initial ht. and wid. This allows sizing of
4701: images that are generated on-the-fly (e.g. gnuplot)
4702: as well as serving as a utility for image_size.
4703:
4704: Parameter:
4705: height_param
4706: width_param - Initial picture dimensions.
4707: scaling - A scale factor.
4708: parstack, - the current stack of tag attributes
4709: from the xml parser
4710: safeeval, - pointer to the safespace
4711: depth, - from what level in the stack to look for attributes
4712: (assumes -1 if unspecified)
4713: cis - look for attrubutes case insensitively
4714: (assumes false)
4715:
4716: Returns:
4717: height, width - new dimensions.
4718:
4719: =item image_size()
4720:
4721: =item image_width()
4722:
4723: =item image_height()
4724:
4725: =item get_eps_image()
4726:
4727: =item eps_generation()
4728:
4729: =item file_path()
4730:
4731: =item recalc()
4732:
4733: Converts a measurement in to mm from any of
4734: the other valid LaTeX units of measure.
4735: If the units of measure are missing from the
4736: parameter, it is assumed to be in and returned
4737: with mm units of measure
4738:
4739: =item LATEX_length()
4740:
4741: =item align_latex_image()
4742:
4743: Wrap image 'stuff' inside of the LaTeX required to implement
4744: alignment:
4745: align_tex_image(align, latex_rendering, image)
4746: Where:
4747: align - The HTML alignment specification.
4748: latex_rendering - rendering hint for latex.
4749: image - The LaTeX needed to insert the image itsef.
4750: width,height - dimensions of the image.
4751: Returns:
4752: The 1/2 wrapped image and the stuff required to close the
4753: wrappage. This allows e.g. randomlabel to insert more stuff
4754: into the closure.
4755:
4756:
4757: =item is_inside_of($tagstack, $tag)
4758: This sub returns true if the current state of Xml processing is inside of the tag.
4759: Parameters:
4760: tagstack - The tagstack from the parser.
4761: tag - The tag (without the <>'s.).
4762: Sample usage:
4763: if (is_inside_of($tagstack "table")) {
4764: I'm in a table....
4765: }
4766:
4767: =item clean_docs_httpref($href,$docuri,$cdom,$cnum)
4768: HTML pages uploaded to a course which contain dependencies either from iframes,
4769: javascript files or objects (FlashPlayerSwf, MediaSrc, XMPSrc, ConfigurationSrc,
4770: and PosterImageSrc) for which dependency is another file uploaded to the same
4771: course.
4772:
4773: Required input:
4774: href - dependency (either a relative URL, or an absolute URL)
4775: Optional inputs:
4776: docuri - URL of HTML page containing the dependency
4777: cdom - Course domain
4778: cnum - CourseID
4779:
4780: Output:
4781: returns an absolute URL constructed from the href provided, and the calling context.
4782: (this will be null, if the URL does not begin: /uploaded/$cdom/$cnum/docs/ or
4783: /uploaded/$cdom/$cnum/supplemental/).
4784:
4785: =back
4786:
4787: =cut
4788:
4789:
4790: 1;
4791: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>