--- loncom/xml/londefdef.pm 2009/10/15 22:39:58 1.412 +++ loncom/xml/londefdef.pm 2012/03/05 14:41:15 1.415.4.6.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.412 2009/10/15 22:39:58 raeburn Exp $ +# $Id: londefdef.pm,v 1.415.4.6.2.1 2012/03/05 14:41:15 raeburn Exp $ # # # Copyright Michigan State University Board of Trustees @@ -48,6 +48,7 @@ use Image::Magick; use Apache::lonmenu(); use Apache::lonmeta(); use Apache::lonlocal; +use Apache::loncommon(); use Apache::Constants qw(:common); use File::Basename; use LONCAPA(); @@ -55,7 +56,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')); } @@ -455,6 +456,31 @@ sub insert_meta { '; } +#-- tag +sub start_style { + my ($target, $token, $tagstack, $parstack, $parser, $safeeval, $style) = @_; + my $currentstring = ''; + + if ($target eq 'tex') { + Apache::lonxml::startredirection(); + } else { + $currentstring = $token->[4]; + } + return $currentstring; +} + +sub end_style { + my ($target, $token, $tagstack, $parstack, $parser, $safeeval) = @_; + my $currentstring = ''; + + if ($target eq 'tex') { + Apache::lonxml::endredirection(); + } else { + $currentstring = $token->[2]; + } + return $currentstring; +} + # accessrule sub start_accessrule { my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; @@ -549,6 +575,8 @@ sub start_body { 'text' => 'HTML Editor', 'href' => '', }); + # breadcrumbs (and tools) will be created + # in start_page->bodytag->innerregister } else { # FIXME Where are we? } @@ -561,10 +589,6 @@ sub start_body { # 'no_title' => 1, 'force_register' => 1}); - if ($env{'request.state'} eq 'construct') { - $currentstring .= &Apache::lonhtmlcommon::breadcrumbs(); - } - my $header = ''; if ($env{'request.state'} ne 'published' && $env{'request.state'} ne 'construct') { @@ -591,7 +615,7 @@ sub start_body { sub edit_controls { my ($nochgview) = @_; my $result .= ' -
+
'; unless ($nochgview) { $result .= ' @@ -603,7 +627,12 @@ sub edit_controls { $result .= '
'; if (($env{'request.course.id'}) && ($env{'form.forceedit'})) { - $result .= (' ' x 3).''; + my $viewtext = &mt('Course View'); + if (&Apache::loncommon::course_type() eq 'Community') { + $viewtext = &mt('Community View'); + } + $result .= (' ' x 3).''; } $result .= '
@@ -2041,35 +2070,50 @@ sub start_table { } elsif ($target eq 'tex') { &disable_para(); # Can't have paras in a table. - - # New table code: - # Get the parameters that we can do something about: my $border = &Apache::lonxml::get_param('border', $parstack, $safeeval, undef, 0); my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval, undef, 0); my $theme = &Apache::lonxml::get_param('TeXtheme', $parstack, $safeeval, undef, 0); my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 0); + my $cell_border = &Apache::lonxml::get_param('rules', $parstack, $safeeval, undef, 0); # The only thing that needs any figuring out is the width.. and then only if it is # a percent. If not it's assumed to be some valid TeX measurement unit e.g. 3.0cm # my $table = new Apache::lontable(); - if ($border ne '') { - $table->table_border(1); - $table->cell_border(1); - } - if ($theme ne '') { + if ((defined $border) && ($border > 0)) { + # &Apache::lonnet::logthis("Turning on table borders: $border"); + $table->table_border(1); + if (!defined $cell_border) { + $table->cell_border(1); # Default for rules is all if rules not defined. + } + } + + if ((defined $cell_border)) { + if ($cell_border eq 'all') { + $table->cell_border(1); + } elsif ($cell_border eq 'rows') { + $table->cell_border(2); + } elsif ($cell_border eq 'cols') { + $table->cell_border(3); + } elsif($cell_border eq 'groups') { + $table->cell_border(4); + } else { + $table->cell_border(0); + } + } + if (defined $theme) { $table->theme($theme); } - if ($align ne '') { + if (defined $align) { $table->alignment($align); } # Missing width is most of page width - if ($width eq "") { + if (!(defined $width)) { $width = '70%'; } @@ -2087,88 +2131,6 @@ sub start_table { push(@Apache::londefdef::table, $table); $currentstring.=' \keephidden{NEW TABLE ENTRY}'; - #-------------------------------------------------------- - # Old table code here. - #-------------------------------------------------------- - - - if (0) { - push(@Apache::londefdef::table, {}); - $Apache::londefdef::table[-1]{'row_number'} = -1; - #maximum table's width (default coincides with text line length) - if ($#Apache::londefdef::table==0) { - $textwidth=&recalc($env{'form.textwidth'}); #result is always in mm - $textwidth=~/(\d+\.?\d*)/; - $textwidth=0.85*$1; #accounts "internal" LaTeX space for table frame - } else { - if ($Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]=~/\d/) { - #the maximum width of nested table is determined by LATeX width of parent cell - $textwidth=$Apache::londefdef::table[-2]{'TeXlen'}[$Apache::londefdef::table[-2]{'row_number'}][$Apache::londefdef::table[-2]{'counter_columns'}]; - } else { - #try to use all space not used before (minus 5% for LaTeX table internal) - rather silly - $textwidth=$Apache::londefdef::table[-2]{'width'}; - for (my $i=0;$i<$Apache::londefdef::table[-2]{'counter_columns'};$i++) { - $textwidth=$textwidth-$Apache::londefdef::table[-2]{'TeXlen'}[0][$i]; - } - } - } - - # width either comes forced from the TeXwidth or the width parameters. - # in either case it can be a percentage or absolute width. - # in the width case we ignore absolute width - my $TeXwidth = &Apache::lonxml::get_param('TeXwidth',$parstack,$safeeval,undef,0); - if (!defined($TeXwidth)) { - my $htmlwidth = &Apache::lonxml::get_param('width',$parstack, - $safeeval,undef,1); - if ($htmlwidth =~ /%/) { - $TeXwidth = $htmlwidth; - } else { - $TeXwidth = $textwidth; - } - } - # if the width is specified as a % it is converted to an absolute width. - # otherwise.. just plugged right in the hash - - if ($TeXwidth=~/%/) { - $TeXwidth=~/(\d+)/; - $Apache::londefdef::table[-1]{'width'}=$1*$textwidth/100; - } else { - $Apache::londefdef::table[-1]{'width'}=$TeXwidth; - } - # In the end, however the table width cannot be wider than $textwidth... - - if ($Apache::londefdef::table[-1]{'width'} > $textwidth) { - $Apache::londefdef::table[-1]{'width'} = $textwidth; - } - #table's border - my $border = &Apache::lonxml::get_param('border',$parstack,$safeeval); - my $permission=&Apache::lonxml::get_param('TeXDropEmptyColumns',$parstack,$safeeval,undef,0); - unless (defined $border) { $border = 0; } - if ($border) { - $Apache::londefdef::table[-1]{'hinc'} = '\hline '; - $Apache::londefdef::table[-1]{'vinc'} = '&'; - $Apache::londefdef::table[-1]{'vvinc'} = '|'; - } else { - $Apache::londefdef::table[-1]{'hinc'} = ''; - $Apache::londefdef::table[-1]{'vinc'} = '&'; - $Apache::londefdef::table[-1]{'vvinc'} = ''; - } - if ($#Apache::londefdef::table==0) { - # Note that \newline seems to destroy the alignment envs. - # $Apache::londefdef::table[-1]{'output'}='\strut\newline\strut\setlength{\tabcolsep}{1 mm}'; - $Apache::londefdef::table[-1]{'output'}='\strut'.'\\\\'."\n".'\strut\setlength{\tabcolsep}{1 mm}'; - } - $Apache::londefdef::table[-1]{'output'}.=' \noindent \begin{tabular} '; - $Apache::londefdef::table[-1]{'TeXlen'}=[]; - $Apache::londefdef::table[-1]{'objectlen'}=[]; - $Apache::londefdef::table[-1]{'objectsignal'}=[]; - $Apache::londefdef::table[-1]{'maxlen'}=[]; - $Apache::londefdef::table[-1]{'minlen'}=[]; - $Apache::londefdef::table[-1]{'content'}=[]; - $Apache::londefdef::table[-1]{'align'}=[]; - $currentstring.=' \keephidden{NEW TABLE ENTRY}'; - } - } return $currentstring; } @@ -2181,8 +2143,6 @@ sub end_table { } elsif ($target eq 'tex') { - # New table code: - my $table = pop(@Apache::londefdef::table); my $t = $table->generate(); $currentstring = $t->generate_string(); @@ -2724,17 +2684,26 @@ sub tag_check { # sub cell_config_hash { - my ($align, $rowspan, $colspan) = @_; + my ($align, $rowspan, $colspan, $width) = @_; + if ($rowspan ne '') { + $rowspan =~ s/^\s+|\s+$//g; + } + if ($colspan ne '') { + $colspan =~ s/^\s+|\s+$//g; + } my %config; if ($align ne '') { $config{'halign'} = $align; } - if ($colspan ne "") { + if (($colspan =~ /^\d+$/) && ($colspan > 0)) { $config{'colspan'} = $colspan; } - if ($rowspan ne '') { + if (($rowspan =~ /^\d+$/) && ($rowspan > 0)) { $config{'rowspan'} = $rowspan; } + if ($width ne '') { + $config{'width'} = $width; + } return \%config; } @@ -2746,11 +2715,11 @@ sub start_td_tex { # attributes, but empty of text. end_td_tex will # fetch the contents from the recursive parse and # fill the cell with them: - my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval, undef, 1); - my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval, undef, 1); - my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval, undef, 1); - - my $config = &cell_config_hash($align, $rowspan, $colspan); + my $align = &Apache::lonxml::get_param('align', $parstack, $safeeval); + my $rowspan = &Apache::lonxml::get_param('rowspan', $parstack, $safeeval); + my $colspan = &Apache::lonxml::get_param('colspan', $parstack, $safeeval); + my $width = &Apache::lonxml::get_param('TeXwidth', $parstack, $safeeval); + my $config = &cell_config_hash($align, $rowspan, $colspan, $width); my $table = $Apache::londefdef::table[-1]; $table->add_cell('', $config); @@ -3277,21 +3246,28 @@ sub start_img { ['','bottom','middle','top','left','right'],$token,5); $currentstring .=&Apache::edit::select_arg('TeXwrap:', 'TeXwrap', ['', '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')) { + $currentstring.='
'.&mt('Warning: the description "[_1]" will be available, even for encrypted URL',$alt).'
'; + } $currentstring .=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); my $src= &Apache::lonxml::get_param('src',$parstack,$safeeval); - my $alt= &Apache::lonxml::get_param('alt',$parstack,$safeeval); my $width= &Apache::lonxml::get_param('width',$parstack,$safeeval); my $height= &Apache::lonxml::get_param('height',$parstack,$safeeval); if ($token->[2]{'src'}=~/\$/) { - $currentstring.='Variable image source'; + $currentstring.=&mt('Variable image source'); + } elsif ($token->[2]{'src'}=~/\S/) { + $currentstring .= ''.$alt.'$code, - 'archive'=>$archive} - ); + $currentstring = $token->[4]; } else { my $alttag= &Apache::lonxml::get_param('alt',$parstack, $safeeval,undef,1); @@ -3882,11 +3855,32 @@ sub end_col { #-- tag (end tag optional) sub start_colgroup { - my ($target,$token) = @_; + my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style) = @_; my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; - } + } + if ($target eq 'tex') { + # TODO: Ensure this tag is in a table: + + # Fetch the attributes and build the hash for the + # call to define_colgroup. + + my $span = &Apache::lonxml::get_param('span', $parstack, $safeeval); + my $halign = &Apache::lonxml::get_param('halign', $parstack, $safeeval); + + my %colgroup_params; + if ($span ne '') { + $colgroup_params{'span'} = $span; + } + if ($halign ne '') { + $colgroup_params{'halign'} = $halign; + } + + my $table = $Apache::londefdef::table[-1]; + $table->define_colgroup(\%colgroup_params); + + } return $currentstring; } @@ -4372,6 +4366,12 @@ sub start_tbody { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; + } + if ($target eq 'tex') { + # TODO: Ensure this tag is within a table: + + my $table = $Apache::londefdef::table[-1]; + $table->start_body(); } return $currentstring; } @@ -4381,6 +4381,12 @@ sub end_tbody { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; + } + if($target eq 'tex') { + # TODO: Ensure this tag is within a table: + + my $table = $Apache::londefdef::table[-1]; + $table->end_body(); } return $currentstring; } @@ -4391,6 +4397,11 @@ sub start_tfoot { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; + } + if ($target eq 'tex') { + # TODO: ensure this is within a table tag. + my $table = $Apache::londefdef::table[-1]; + $table->start_foot(); } return $currentstring; } @@ -4400,6 +4411,11 @@ sub end_tfoot { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; + } + if ($target eq 'tex') { + # TODO: Ensure this is in side a table + my $table = $Apache::londefdef::table[-1]; + $table->end_foot(); } return $currentstring; } @@ -4410,6 +4426,11 @@ sub start_thead { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[4]; + } + if ($target eq 'tex') { + # Assume we're in a table... TODO: Verify that and ignore tag if not. + my $table = $Apache::londefdef::table[-1]; + $table->start_head(); } return $currentstring; } @@ -4419,6 +4440,12 @@ sub end_thead { my $currentstring = ''; if ($target eq 'web' || $target eq 'webgrade') { $currentstring = $token->[2]; + } + if ($target eq 'tex') { + # TODO: Verify we are in a table and ignore tag if not. + + my $table = $Apache::londefdef::table[-1]; + $table->end_head(); } return $currentstring; } @@ -4753,7 +4780,7 @@ sub align_latex_image { # Even though we set a default alignment value, the user # could have given us an illegal value. In that case we # just use the default alignment of bottom.. - $currentstring = "\n% figurewrapping \n"; + $currentstring = ''; if ($align eq "top") { $currentstring .= '\raisebox{-'.$height.'mm}{'.$image; $closure = '}'; @@ -4796,8 +4823,6 @@ sub align_latex_image { $currentstring .= "{$image"; $closure = '}'; } - $currentstring .= "\n% end wrappage\n"; - $closure = "\n% Begin closure\n".$closure."\n% End closure\n"; return ($currentstring, $closure); } @@ -4817,8 +4842,7 @@ sub is_inside_of { # # This sub provides the typical LaTeX prefix matter for tex output: # -sub latex_header -{ +sub latex_header { my ($mode) = @_; my $currentstring = '';