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