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