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