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