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