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