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