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