--- loncom/xml/londefdef.pm 2011/10/01 03:19:06 1.434 +++ loncom/xml/londefdef.pm 2023/03/25 22:11:11 1.471 @@ -1,9 +1,8 @@ - # The LearningOnline Network with CAPA -# Tags Default Definition Module +# Tags Default Definition Module +# +# $Id: londefdef.pm,v 1.471 2023/03/25 22:11:11 raeburn Exp $ # -# $Id: londefdef.pm,v 1.434 2011/10/01 03:19:06 raeburn Exp $ -# # # Copyright Michigan State University Board of Trustees # @@ -26,19 +25,19 @@ # /home/httpd/html/adm/gpl.txt # # http://www.lon-capa.org/ -## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. -# TtHfunc and TtMfunc (the "Code") may be compiled and linked into -# binary executable programs or libraries distributed by the -# Michigan State University (the "Licensee"), but any binaries so +## Copyright for TtHfunc and TtMfunc by Ian Hutchinson. +# TtHfunc and TtMfunc (the "Code") may be compiled and linked into +# binary executable programs or libraries distributed by the +# Michigan State University (the "Licensee"), but any binaries so # distributed are hereby licensed only for use in the context -# of a program or computational system for which the Licensee is the -# primary author or distributor, and which performs substantial +# of a program or computational system for which the Licensee is the +# primary author or distributor, and which performs substantial # additional tasks beyond the translation of (La)TeX into HTML. # The C source of the Code may not be distributed by the Licensee # to any other parties under any circumstances. # -package Apache::londefdef; +package Apache::londefdef; use Apache::lonnet; use strict; @@ -56,7 +55,7 @@ use LONCAPA(); BEGIN { - &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','sub','sup','table','tbody','td','textarea','tfoot','th','thead','title','tr','tt','tthoption','u','ul','var','wbr','hideweboutput')); + &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')); } @@ -93,6 +92,26 @@ sub start_m { my $inside = &Apache::lonxml::get_all_text_unbalanced("/m",$parser); if ($target eq 'web' || $target eq 'analyze') { &Apache::lonxml::debug("M is starting with:$inside:"); + if (!($inside =~ /^\s*\$.*\$\s*$/ || $inside =~ /^\s*\\[([].*\\[)\]]\s*$/)) { + # Non-math LaTeX will not be rendered correctly with MathJax + # and it should be avoided anyway. + # On top of that, MathJax will render math without $, but + # it will fail with tth. This is worth a warning. + # (even though some people might just use latex for printing) + &Apache::lonxml::warning(&mt('Missing $ in [_1].','<m>')); + } elsif (($env{'browser.type'} eq 'safari') && ($env{'form.editxmltext'}) && + (($env{'form.problemmode'} eq 'view') || ($env{'form.problemmode'} eq 'discard'))) { + my $delimiter; + if ($inside =~ /\$$/) { + $delimiter = '$'; + } elsif ($inside =~ /\\([)\]])$/) { + $delimiter = $1; + } + if ($delimiter) { + &Apache::lonxml::warning(&mt('Insert a space between [_1] and [_2].', + $delimiter,'</m>')); + } + } my $eval=&Apache::lonxml::get_param('eval',$parstack,$safeeval); if ($eval eq 'on') { $inside=&Apache::run::evaluate($inside,$safeeval,$$parstack[-1]); @@ -175,7 +194,7 @@ sub start_html { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'edit' || $target eq 'webgrade' ) { - # start_body() takes care of emitting the + # start_body() takes care of emitting the } elsif ($target eq 'tex') { $currentstring .= &latex_header(); @@ -198,7 +217,7 @@ sub start_head { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { &Apache::lonxml::startredirection(); - } + } return $currentstring; } @@ -211,7 +230,7 @@ sub end_head { if ($Apache::lonxml::redirection) { $Apache::londefdef::head = &Apache::lonxml::endredirection(); } - } + } return $currentstring; } @@ -220,8 +239,8 @@ sub start_map { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; - } + $currentstring = $token->[4]; + } return $currentstring; } @@ -229,8 +248,8 @@ sub end_map { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } + $currentstring = $token->[2]; + } return $currentstring; } @@ -239,7 +258,7 @@ sub start_select { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; + $currentstring = $token->[4]; } elsif ($target eq 'tex') { $Apache::londefdef::select=0; } @@ -250,8 +269,8 @@ sub end_select { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } + $currentstring = $token->[2]; + } return $currentstring; } @@ -260,7 +279,7 @@ sub start_option { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; + $currentstring = $token->[4]; } elsif ($target eq 'tex') { $Apache::londefdef::select++; if ($Apache::londefdef::select == 1) { @@ -276,7 +295,7 @@ sub end_option { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; + $currentstring = $token->[2]; } elsif ($target eq 'tex') { $currentstring='}'; } @@ -288,8 +307,8 @@ sub start_input { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; - } + $currentstring = $token->[4]; + } return $currentstring; } @@ -297,8 +316,8 @@ sub end_input { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } + $currentstring = $token->[2]; + } return $currentstring; } @@ -307,8 +326,8 @@ sub start_textarea { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; - } + $currentstring = $token->[4]; + } return $currentstring; } @@ -316,8 +335,8 @@ sub end_textarea { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } + $currentstring = $token->[2]; + } return $currentstring; } @@ -326,8 +345,8 @@ sub start_form { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[4]; - } + $currentstring = $token->[4]; + } return $currentstring; } @@ -335,8 +354,8 @@ sub end_form { my ($target,$token) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $currentstring = $token->[2]; - } + $currentstring = $token->[2]; + } return $currentstring; } @@ -345,10 +364,10 @@ sub start_title { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { - $Apache::londefdef::title = + $Apache::londefdef::title = &Apache::lonxml::get_all_text('/title',$parser,$style); } elsif ($target eq 'tex') { - $currentstring .= '\keephidden{Title of the document: ' + $currentstring .= '\keephidden{Title of the document: '; } if ($target eq 'meta') { $currentstring='
# Some tags are
fragile meaning that
inside of them
-# does not work within TeX mode. This is managed via the
+# does not work within TeX mode. This is managed via the
# counter below:
#
@@ -1230,6 +1317,10 @@ sub start_p {
$currentstring .= &end_p(); # close off prior para if in progress.
my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1);
+ if (!defined $align) {
+ # check inline CSS
+ $align = &get_css_property('text-align',$parstack,$safeeval);
+ }
if ($align eq 'center') {
$currentstring .='\begin{center}\par ';
$closing_string = '\end{center}';
@@ -1237,13 +1328,13 @@ sub start_p {
$currentstring = ¢er_correction().$currentstring;
}
} elsif ($align eq 'right') {
- $currentstring.="\n".'{\flushright ';
+ $currentstring.="\n".'\begin{flushright}';
# $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{';
- $closing_string= "}\n";
+ $closing_string= '\end{flushright}'."\n";
} elsif ($align eq 'left') {
- $currentstring.= "\n".'{\flushleft ';
+ $currentstring.= "\n".'\begin{flushleft}';
# $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{{';
- $closing_string = "}\n";
+ $closing_string = '\end{flushleft}'."\n";
} else {
$currentstring.='\par ';
if (&is_inside_of($tagstack, 'table')) {
@@ -1297,7 +1388,7 @@ sub start_br {
if ($signal != 1) {
$currentstring .= '\strut \\\\ \strut ';
}
-
+
}
return $currentstring;
}
@@ -1319,7 +1410,7 @@ sub start_big {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '{\large ';
- }
+ }
return $currentstring;
}
@@ -1362,7 +1453,7 @@ sub start_basefont {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
if (defined $basesize) {
@@ -1376,7 +1467,7 @@ sub end_basefont {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $basesize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
if (defined $basesize) {
@@ -1392,7 +1483,7 @@ sub start_font {
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
my $face=&Apache::lonxml::get_param('face',$parstack,$safeeval);
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
if (defined $fontsize) {
@@ -1406,7 +1497,7 @@ sub end_font {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
my $fontsize=&Apache::lonxml::get_param('TeXsize',$parstack,$safeeval);
if (defined $fontsize) {
@@ -1415,7 +1506,7 @@ sub end_font {
}
return $currentstring;
}
-
+
#-- in the prior to the list.
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
- $currentstring .= " \\begin{itemize} ";
- }
+ $currentstring .= " \\begin{itemize} ";
+ }
return $currentstring;
}
@@ -1861,10 +1961,10 @@ sub end_dir {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
- $currentstring = " \\end{itemize}";
- }
+ $currentstring = " \\end{itemize}";
+ }
return $currentstring;
}
@@ -1873,18 +1973,18 @@ sub start_ol {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = &end_p(); # In case there's a prior to the list.
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$Apache::londefdef::list_index=0;
my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
if ($type eq '1') {
$currentstring .= '\renewcommand{\labelenumi}{\arabic{enumi}.}'.
- '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
+ '\renewcommand{\labelenumii}{\arabic{enumii}.}'.
'\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
'\renewcommand{\labelenumiv}{\arabic{enumiv}.}';
} elsif ($type eq 'A') {
$currentstring .= '\renewcommand{\labelenumi}{\Alph{enumi}.}'.
- '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
+ '\renewcommand{\labelenumii}{\Alph{enumii}.}'.
'\renewcommand{\labelenumiii}{\Alph{enumiii}.}'.
'\renewcommand{\labelenumiv}{\Alph{enumiv}.}';
} elsif ($type eq 'a') {
@@ -1903,8 +2003,8 @@ sub start_ol {
'\renewcommand{\labelenumiii}{\Roman{enumiii}.}'.
'\renewcommand{\labelenumiv}{\Roman{enumiv}.}';
}
- $currentstring .= '\strut \begin{enumerate}';
- }
+ $currentstring .= '\strut \begin{enumerate}';
+ }
return $currentstring;
}
@@ -1912,13 +2012,13 @@ sub end_ol {
my ($target,$token) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
$currentstring = '\end{enumerate}\renewcommand{\labelenumi}{\arabic{enumi}.}'.
'\renewcommand{\labelenumii}{\arabic{enumii}.}'.
'\renewcommand{\labelenumiii}{\arabic{enumiii}.}'.
- '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
- }
+ '\renewcommand{\labelenumiv}{\arabic{enumiv}.}\strut ';
+ }
return $currentstring;
}
@@ -1927,7 +2027,7 @@ sub start_dl {
my ($target,$token) = @_;
my $currentstring = &end_p(); # In case there's a unclosed prior to the list.
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\begin{description}';
$Apache::londefdef::DL++;
@@ -1935,7 +2035,7 @@ sub start_dl {
$Apache::londefdef::DD[$Apache::londefdef::DL]=0;
$Apache::londefdef::DT[$Apache::londefdef::DL]=0;
$Apache::londefdef::seenDT[$Apache::londefdef::DL]=0;
- }
+ }
return $currentstring;
}
@@ -1943,7 +2043,7 @@ sub end_dl {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
@@ -1951,12 +2051,12 @@ sub end_dl {
$currentstring.=' '.$element.' ';
}
pop(@Apache::londefdef::description);
- $currentstring.='\end{description}';
+ $currentstring.='\end{description}';
delete($Apache::londefdef::DD[$Apache::londefdef::DL]);
delete($Apache::londefdef::DT[$Apache::londefdef::DL]);
delete($Apache::londefdef::seenDT[$Apache::londefdef::DL]);
$Apache::londefdef::DL--;
- }
+ }
return $currentstring;
}
@@ -1965,14 +2065,14 @@ sub start_dt {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring='';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
if ($Apache::londefdef::DD[-1]) { &end_dd(@_); }
&Apache::lonxml::startredirection();
$Apache::londefdef::DT[-1]++;
$Apache::londefdef::seenDT[-1]=1;
- }
+ }
return $currentstring;
}
@@ -1980,21 +2080,21 @@ sub end_dt {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
if ($Apache::londefdef::DT[-1]) {
my $data=&item_cleanup();
push(@{$Apache::londefdef::description[-1]},'\item['.$data.'] \strut \vskip 0mm');
$Apache::londefdef::DT[-1]--;
}
- }
+ }
return $currentstring;
}
sub item_cleanup {
my $item=&Apache::lonxml::endredirection();
- $item=~s/\\begin{center}//g;
- $item=~s/\\end{center}//g;
+ $item=~s/\\begin\{center}//g;
+ $item=~s/\\end\{center}//g;
return $item;
}
@@ -2003,7 +2103,7 @@ sub start_dd {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
if ($Apache::londefdef::DT[-1]) { &end_dt(@_); }
if ($Apache::londefdef::DD[-1]) { &end_dd(@_);}
@@ -2014,7 +2114,7 @@ sub start_dd {
$Apache::londefdef::description[-1]->[-1].=' \strut ';
$Apache::londefdef::DD[-1]++;
&Apache::lonxml::startredirection();
- }
+ }
return $currentstring;
}
@@ -2022,7 +2122,7 @@ sub end_dd {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
$Apache::londefdef::description[-1]->[-1].=
&Apache::lonxml::endredirection().' \vskip 0mm ';
@@ -2034,7 +2134,7 @@ sub end_dd {
#-- that is not closed.
# but, unless I allow 's to nest, that's the
-# only way I could think of to allow in
+# only way I could think of to allow in
# in the row.
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[2];
+ $currentstring .= $token->[2];
} elsif ($target eq 'tex') {
# In case the user is missing a or in the row.
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[2];
+ $currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$Apache::londefdef::TD_redirection =0;
&end_th_tex($parstack,$parser,$safeeval);
}
return $currentstring;
}
-
+
#-- tag (end tag forbidden)
#
# Render the tag.
-# has the following attributes (in addition to the
+# has the following attributes (in addition to the
# standard HTML ones:
# TeXwrap - Governs how the tex target will try to wrap text around
# horizontally aligned images.
# TeXwidth - The width of the image when rendered for print (mm).
# TeXheight - The height of the image when rendered for print (mm)
# (Note there seems to also be support for this as a % of page size)
-#
+#
sub start_img {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_;
my $src = &Apache::lonxml::get_param('src',$parstack,$safeeval,
undef,1);
- if (! $src &&
+ if (! $src &&
($target eq 'web' || $target eq 'webgrade' || $target eq 'tex')
- ) {
+ ) {
my $inside = &Apache::lonxml::get_all_text("/img",$parser,$style);
return '';
}
- &Apache::lonxml::extlink($src);
+ unless ($src =~ m{^data\:image/gif;base64,}) {
+ &Apache::lonxml::extlink($src);
+ }
my $currentstring = '';
my $scaling = .3;
# Render unto browsers that which are the browser's...
if ($target eq 'web' || $target eq 'webgrade') {
- my $enc = ('yes' eq
+ my $enc = ('yes' eq
lc(&Apache::lonxml::get_param('encrypturl',$parstack,
$safeeval)));
- $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
- $enc);
+ unless ($src =~ m{^data\:image/gif;base64,}) {
+ $currentstring.=&Apache::lonenc::encrypt_ref($token,{'src'=>$src},
+ $enc);
+ }
# and render unto TeX that which is LaTeX
} elsif ($target eq 'tex') {
@@ -2704,7 +2808,7 @@ sub start_img {
# simulate the alignments offered by html.
#
#
- my $align = lc(&Apache::lonxml::get_param('align',
+ my $align = lc(&Apache::lonxml::get_param('align',
$parstack,
$safeeval,
undef,1));
@@ -2714,7 +2818,7 @@ sub start_img {
#
&Apache::lonxml::debug("Alignemnt = $align");
# LaTeX's image/text wrapping is really bad since it wants to
- # make figures float.
+ # make figures float.
# The user has the optional parameter (applicable only to l/r
# alignment to use the picins/parpic directive to get wrapped text
# this is also imperfect.. that's why we give them a choice...
@@ -2737,7 +2841,7 @@ sub start_img {
# &Apache::lonxml::debug("LaTeX rendering = $latex_rendering image file: $src");
- #if original bmp/gif/jpg/png file exist do following:
+ #if original bmp/gif/jpg/png/svg file exist do following:
my $origsrc=$src;
my ($path,$file) = &get_eps_image($src);
# &Apache::lonnet::logthis("Image source: $src result: $path $file");
@@ -2751,25 +2855,25 @@ sub start_img {
if ($width_param) { $size.='width='.$width_param.' mm,'; }
if ($height_param) { $size.='height='.$height_param.' mm]'; }
# Default size if not able to extract that (e.g. eps image).
-
+
# &Apache::lonnet::logthis("Size = $size");
-
+
$size='['.$size;
- $size=~s/,$/]/;
+ $size=~s/,$/]/;
$currentstring .= '\graphicspath{{'.$path.'}}'
.'\includegraphics'.$size.'{'.$file.'} ';
my $closure;
- ($currentstring, $closure) = &align_latex_image($align,
- $latex_rendering,
- $currentstring,
- $width_param,
+ ($currentstring, $closure) = &align_latex_image($align,
+ $latex_rendering,
+ $currentstring,
+ $width_param,
$height_param);
$currentstring .= $closure;
-
+
} else {
&Apache::lonxml::debug("$src does not exist");
#original image file doesn't exist so check the alt attribute
- my $alt =
+ my $alt =
&Apache::lonxml::get_param('alt',$parstack,$safeeval,undef,1);
unless ($alt) {
$alt=&Apache::lonmeta::alttag($Apache::lonxml::pwd[-1],$src);
@@ -2784,8 +2888,8 @@ sub start_img {
my $only = join(',',&Apache::loncommon::filecategorytypes('Pictures'));
$currentstring .=&Apache::edit::tag_start($target,$token);
$currentstring .=&Apache::edit::text_arg('Image Url:','src',$token,70).
- &Apache::edit::browse('src',undef,'alt',$only).' '.
- &Apache::edit::search('src',undef,'alt').' tag (end tag required)
sub start_strike {
my ($target,$token) = @_;
@@ -1424,7 +1515,7 @@ sub start_strike {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
&Apache::lonxml::startredirection();
- }
+ }
return $currentstring;
}
@@ -1435,8 +1526,8 @@ sub end_strike {
$currentstring .= $token->[2];
} elsif ($target eq 'tex') {
$currentstring=&Apache::lonxml::endredirection();
- $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
- $currentstring=~s/^\s*(\S)/\\underline\{$1/;
+ $currentstring=~s/(\S)(\s+)(\S)/$1\}$2\\underline\{$3/g;
+ $currentstring=~s/^\s*(\S)/\\underline\{$1/;
$currentstring=~s/(\S)\s*$/$1\}/;
}
return $currentstring;
@@ -1450,7 +1541,7 @@ sub start_s {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
&Apache::lonxml::startredirection();
- }
+ }
return $currentstring;
}
@@ -1476,7 +1567,7 @@ sub start_sub {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\raisebox{-\smallskipamount}{\scriptsize{';
- }
+ }
return $currentstring;
}
@@ -1499,7 +1590,7 @@ sub start_sup {
$currentstring .= $token->[4];
} elsif ($target eq 'tex') {
$currentstring .= '\raisebox{\smallskipamount}{\scriptsize{';
- }
+ }
return $currentstring;
}
@@ -1523,7 +1614,7 @@ sub start_hr {
} elsif ($target eq 'tex') {
#
can't be inside of thank you LaTeX.
- #
+ #
my $restart_sub = 0;
my $restart_sup = 0;
@@ -1533,7 +1624,7 @@ sub start_hr {
if (&is_inside_of($tagstack, "sub")) {
$restart_sub = 1;
- $currentstring .= &end_sub($target, $token, $tagstack,
+ $currentstring .= &end_sub($target, $token, $tagstack,
$parstack, $parser, $safeeval);
}
if (&is_inside_of($tagstack, "sup")) {
@@ -1572,7 +1663,7 @@ sub start_hr {
$currentstring .= &start_sup($target, $token, $tagstack,
$parstack, $parser, $safeeval);
}
- }
+ }
return $currentstring;
}
@@ -1599,12 +1690,12 @@ sub start_div {
my $currentstring = &end_p(); # Close enclosing para.
if ($target eq 'web' || $target eq 'webgrade') {
$currentstring .= $token->[4];
- }
+ }
if ($target eq 'tex') {
# 4 possible alignments: left, right, center, and -missing-.
# If inside a table row, we must let the table logic
# do the alignment, however.
- #
+ #
my $endstring = '';
@@ -1615,7 +1706,7 @@ sub start_div {
$endstring = '\end{center}';
if (&is_inside_of($tagstack, "table")) {
$currentstring = ¢er_correction().$currentstring;
- $endstring .= ¢er_end_correction();
+ $endstring .= ¢er_end_correction();
}
}
elsif ($align eq 'right') {
@@ -1671,6 +1762,15 @@ sub start_a {
if (!&Apache::lonnet::allowed('bre',$linkurl)) {
if (&Apache::lonnet::is_on_map($url)) {
&Apache::lonxml::extlink($linkurl);
+ } elsif ($env{'request.course.id'}) {
+ my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+ my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+ if ($linkurl =~ m{^([^/]|/uploaded/$cdom/$cnum/(docs|supplemental)/)}) {
+ my $cleanhref = &clean_docs_httpref($linkurl,$url,$cdom,$cnum);
+ if ($cleanhref) {
+ &Apache::lonxml::extlink($cleanhref);
+ }
+ }
}
}
}
@@ -1716,11 +1816,11 @@ sub start_li {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $type=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0);
my $value=&Apache::lonxml::get_param('value',$parstack,$safeeval,undef,0);
- #FIXME need to support types i and I
+ #FIXME need to support types i and I
if ($type=~/disc/) {
$currentstring .= ' \item[$\bullet$] ';
} elsif ($type=~/circle/) {
@@ -1737,7 +1837,7 @@ sub start_li {
$currentstring .= ' \item['.$value.'] ';
} else {
$currentstring .= ' \item ';
- }
+ }
$Apache::londefdef::list_index++;
}
return $currentstring;
@@ -1747,8 +1847,8 @@ sub end_li {
my ($target,$token) = @_;
my $currentstring = &end_p(); # In case there's a tag (end tag required)
#
also ends any prior
bodies
#
#list of supported attributes: border,width,TeXwidth,TeXtheme
@@ -2044,7 +2144,7 @@ sub start_table {
my $textwidth = '';
my $currentstring = &end_p();
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring .= $token->[4];
+ $currentstring .= $token->[4];
} elsif ($target eq 'tex') {
&disable_para(); # Can't have paras in a table.
@@ -2112,12 +2212,12 @@ sub start_table {
}
return $currentstring;
}
-
+
sub end_table {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
@@ -2137,7 +2237,7 @@ sub start_tr {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1);
@@ -2171,21 +2271,21 @@ sub start_tr {
push @ {$Apache::londefdef::table[-1]{'maxlen'}}, [];
push @ {$Apache::londefdef::table[-1]{'content'}}, [];
}
- }
+ }
return $currentstring;
}
-
+
sub end_tr {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = &end_p(); # Close any pending tag:
if ($Apache::londefdef::TD_redirection) {
- &end_td_tex($parstack,$parser,$safeeval);
+ &end_td_tex($parstack,$parser,$safeeval);
}
$Apache::londefdef::table[-1]->end_row();
@@ -2195,7 +2295,7 @@ sub end_tr {
if (0) {
if ($Apache::londefdef::TD_redirection) {
- &end_td_tex($parstack,$parser,$safeeval);
+ &end_td_tex($parstack,$parser,$safeeval);
}
# Counter columns must be the maximum number of columns seen
# in the table so far so:
@@ -2214,17 +2314,17 @@ sub start_td {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
$Apache::londefdef::TD_redirection = 1;
&tag_check('tr','td',$tagstack,$parstack,$parser,$safeeval);
- }
+ }
return $currentstring;
-}
-
+}
+
sub tag_check {
my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
- my @ar=@$parstack;
+ my @ar=@$parstack;
for (my $i=$#ar-1;$i>=0;$i--) {
if (lc($$tagstack[$i]) eq $good_tag) {
&start_td_tex($parstack,$parser,$safeeval);
@@ -2246,7 +2346,7 @@ sub tag_check {
sub cell_config_hash {
my ($align, $rowspan, $colspan, $width) = @_;
if ($rowspan ne '') {
- $rowspan =~ s/^\s+|\s+$//g;
+ $rowspan =~ s/^\s+|\s+$//g;
}
if ($colspan ne '') {
$colspan =~ s/^\s+|\s+$//g;
@@ -2266,7 +2366,7 @@ sub cell_config_hash {
}
return \%config;
}
-
+
sub start_td_tex {
my ($parstack,$parser,$safeeval) = @_;
@@ -2283,7 +2383,7 @@ sub start_td_tex {
my $table = $Apache::londefdef::table[-1];
$table->add_cell('', $config);
-
+
#------------------------------------------------
# Old table code.
@@ -2321,7 +2421,7 @@ sub end_td_tex {
if (0) {
my ($parstack,$parser,$safeeval) = @_;
my $current_row = $Apache::londefdef::table[-1]{'row_number'};
- my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
+ my $current_column = $Apache::londefdef::table[-1]{'counter_columns'};
my $data = &Apache::lonxml::endredirection();
# The rowspan array of the table indicates which cells are part of a span.
@@ -2331,14 +2431,14 @@ sub end_td_tex {
# If this and subsequent cells are part of a rowspan, we must
# push along the row until we find one that is not.
- while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
+ while ((defined $Apache::londefdef::table[-1]{'rowspan'}[$current_row] [$current_column])
&& ($Apache::londefdef::table[-1]{'rowspan'}[$current_row][$current_column] =~ /[\^\_]/)) {
# Part of a span.
push @ {$Apache::londefdef::table[-1]{'content'}[-1]}, '';
$current_column++;
}
$Apache::londefdef::table[-1]{'counter_columns'} = $current_column;
-
+
# Get the column and row spans.
# Colspan can be done via \multicolumn if I can figure out the data structs.
@@ -2414,9 +2514,9 @@ sub end_td_tex {
push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
}
- $data=~s/\\\\\s*$//;
- } else {
- $data=~s/^\s+(\S.*)/$1/;
+ $data=~s/\\\\\s*$//;
+ } else {
+ $data=~s/^\s+(\S.*)/$1/;
$data=~s/(.*\S)\s+$/$1/;
$data=~s/(\s)+/$1/;
my ($current_length,$min_length)=(0,0);
@@ -2447,13 +2547,13 @@ sub end_td_tex {
push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
}
- }
+ }
}
# Substitute all of the tables nested in this cell in their appropriate places.
my $nested_count = $#{$Apache::londefdef::table[-1]{'include'}}; # This one is constant...
- for (my $in=0; $in<=$nested_count; $in++) {
+ for (my $in=0; $in<=$nested_count; $in++) {
my $nested = shift @{$Apache::londefdef::table[-1]{'include'}};
$nested =~ s/\\end\{tabular\}\\strut\\\\/\\end\{tabular\}/;
# $data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
@@ -2492,7 +2592,7 @@ sub end_td {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[2];
+ $currentstring = $token->[2];
} elsif ($target eq 'tex') {
$Apache::londefdef::TD_redirection =0;
&end_td_tex($parstack,$parser,$safeeval);
@@ -2505,17 +2605,17 @@ sub start_th {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = '';
if ($target eq 'web' || $target eq 'webgrade') {
- $currentstring = $token->[4];
+ $currentstring = $token->[4];
} elsif ($target eq 'tex') {
$Apache::londefdef::TD_redirection = 1;
&tagg_check('tr','th',$tagstack,$parstack,$parser,$safeeval);
- }
+ }
return $currentstring;
-}
-
+}
+
sub tagg_check {
my ($good_tag,$bad_tag,$tagstack,$parstack,$parser,$safeeval) = @_;
- my @ar=@$parstack;
+ my @ar=@$parstack;
for (my $i=$#ar-1;$i>=0;$i--) {
if (lc($$tagstack[$i]) eq $good_tag) {
&start_th_tex($parstack,$parser,$safeeval);
@@ -2529,7 +2629,7 @@ sub tagg_check {
}
return '';
}
-
+
sub start_th_tex {
my ($parstack,$parser,$safeeval) = @_;
@@ -2608,8 +2708,8 @@ sub end_th_tex {
push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$fwidth;
push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
- } else {
- $data=~s/^\s+(\S.*)/$1/;
+ } else {
+ $data=~s/^\s+(\S.*)/$1/;
$data=~s/(.*\S)\s+$/$1/;
$data=~s/(\s)+/$1/;
my ($current_length,$min_length)=(0,0);
@@ -2638,9 +2738,9 @@ sub end_th_tex {
push @ {$Apache::londefdef::table[-1]{'objectlen'}[$Apache::londefdef::table[-1]{'row_number'}] },'0';
push @ {$Apache::londefdef::table[-1]{'maxlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$current_length;
push @ {$Apache::londefdef::table[-1]{'minlen'}[$Apache::londefdef::table[-1]{'row_number'}] },$min_length;
- }
+ }
}
- for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
+ for (my $in=0; $in<=$#{$Apache::londefdef::table[-1]{'include'}};$in++) {
$data=~s/\\keephidden\{NEW TABLE ENTRY\}/$Apache::londefdef::table[-1]{'include'}[$in]/;
}
#make data bold
@@ -2654,47 +2754,51 @@ sub end_th {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
my $currentstring = &end_p(); # Close any open
';
+ &Apache::edit::browse_or_search('src',undef,'alt',$only,undef,1).
+ '
';
$currentstring .=&Apache::edit::text_arg('Description:','alt',$token,70).'
';
$currentstring .=&Apache::edit::text_arg('width (pixel):','width',$token,5);
$currentstring .=&Apache::edit::text_arg('height (pixel):','height',$token,5).'
';
@@ -2797,7 +2901,7 @@ sub start_img {
['', 'none','parbox', 'parpic', 'wrapfigure'], $token, 2);
my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval);
my $enc= &Apache::lonxml::get_param('encrypturl',$parstack,$safeeval);
-
+
$currentstring .=&Apache::edit::select_arg('Encrypt URL:','encrypturl',
['no','yes'], $token, 2);
if (($alt=~/\S/) && (lc($enc) eq 'yes')) {
@@ -2807,17 +2911,19 @@ sub start_img {
my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval);
my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval);
my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval);
-
+ my $element = &Apache::edit::get_element('src');
+ my $text;
if ($token->[2]{'src'}=~/\$/) {
- $currentstring.=&mt('Variable image source');
+ $text = &mt('Variable image source');
} elsif ($token->[2]{'src'}=~/\S/) {
$currentstring .= '';
} else {
- $currentstring.=&mt("No image source specified");
+ $text = &mt("No image source specified");
}
+ $currentstring .= ' '.$text.'';
} elsif ($target eq 'modified') {
my ($osrc,$owidth,$oheight)=
($token->[2]{'src'},$token->[2]{'width'},$token->[2]{'height'});
@@ -2838,7 +2944,7 @@ sub start_img {
}
if ($osrc ne $nsrc || (!$nwidth && !$nheight)) {
# changed image or no size specified,
- # if they didn't explicitly change the
+ # if they didn't explicitly change the
# width or height use the ones from the image
if ($iwidth && $iheight) {
if ($owidth == $nwidth || (!$nwidth && !$nheight)) {
@@ -2877,7 +2983,7 @@ sub end_img {
#--