--- loncom/xml/londefdef.pm 2005/07/05 18:59:03 1.276 +++ loncom/xml/londefdef.pm 2005/07/07 10:09:50 1.277 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Tags Default Definition Module # -# $Id: londefdef.pm,v 1.276 2005/07/05 18:59:03 albertel Exp $ +# $Id: londefdef.pm,v 1.277 2005/07/07 10:09:50 foxr Exp $ # # # Copyright Michigan State University Board of Trustees @@ -565,11 +565,11 @@ EDITBUTTON sub end_body { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off unclosed

if ($target eq 'web') { - $currentstring = &Apache::lonxml::xmlend($target,$parser); + $currentstring .= &Apache::lonxml::xmlend($target,$parser); } elsif ($target eq 'tex') { - $currentstring = '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; + $currentstring .= '\strut\newline\noindent\makebox[\textwidth/$number_of_columns][b]{\hrulefill}\newline\noindent \end{document}'; } return $currentstring; } @@ -577,11 +577,11 @@ sub end_body { #--

tag (end tag required) sub start_center { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior para. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\begin{center}'; + $currentstring .= '\begin{center}'; } return $currentstring; } @@ -646,7 +646,7 @@ sub end_strong { #--

tag (end tag required) sub start_h1 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -663,7 +663,7 @@ sub start_h1 { if (not defined $TeXsize) {$TeXsize="large";} $currentstring .= '\strut\newline '.$pre.'{\\'.$TeXsize.' \textbf{'; } elsif ($target eq 'meta') { - $currentstring=''; + $currentstring.=''; &start_output($target); } return $currentstring; @@ -695,7 +695,7 @@ sub end_h1 { #--

tag sub start_h2 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -738,7 +738,7 @@ sub end_h2 { #--

tag sub start_h3 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -781,7 +781,7 @@ sub end_h3 { #--

tag sub start_h4 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -824,7 +824,7 @@ sub end_h4 { #--

tag sub start_h5 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior paras. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -867,7 +867,7 @@ sub end_h5 { #--
tag sub start_h6 { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any prior paras. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1114,52 +1114,64 @@ sub end_q { return $currentstring; } +#

is a bit strange since it does not require a closing

+# However in latex, we must often output closing stuff to end +# environments and {}'s etc. Therefore we do all the work +# of figuring out the ending strings in the start tag processing, +# and provide a mechanism to output the stop text external +# to tag processing. +# +{ + + my $closing_string = ''; # String required to close

+ #--

tag (end tag optional) #optional attribute - align="center|left|right" sub start_p { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # close off prior para if in progress. if ($target eq 'web') { $currentstring .= $token->[4]; + $closing_string = '

'; # Not sure this is correct. } elsif ($target eq 'tex') { my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); if ($align eq 'center') { - $currentstring='\begin{center}\par'; + $currentstring .='\begin{center}\par'; + $closing_string = '\end{center}'; } elsif ($align eq 'right') { - $currentstring='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{'; + $currentstring.='\makebox['.$env{'form.textwidth'}.']{\hfill\llap{'; + $closing_string= '}}'; } elsif ($align eq 'left') { - $currentstring='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{'; + $currentstring.='\noindent\makebox['.$env{'form.textwidth'}.']{\rlap{'; + $closing_string = '}\hfill}'; } else { - $currentstring='\par '; + $currentstring.='\par '; + $closing_string = '\strut\\\\\strut'; } my $signal=1;#

does not work inside ... - foreach my $tag (@$tagstack) {if (lc($tag) eq 'b') {$signal=0;} - if (!$signal) {$currentstring = '';} + foreach my $tag (@$tagstack) { + if (lc($tag) eq 'b') { + $signal=0; + } + } + if (!$signal) { + $currentstring = &end_p; # Just close the prior? Not sure this is correct + $closing_string = ''; # Probably correct? } - } - return $currentstring; -} -sub end_p { - my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; - if ($target eq 'web') { - $currentstring .= $token->[2]; - } elsif ($target eq 'tex') { - my $align=&Apache::lonxml::get_param('align',$parstack,$safeeval,undef,1); - if (not defined $align) { - $currentstring.='\strut\\\\\strut '; - } elsif ($align eq 'center') { - $currentstring .= '\end{center}'; - } elsif ($align eq 'right') { - $currentstring .= '}}'; - } elsif ($align eq 'left') { - $currentstring .= '}\hfill}'; - } } return $currentstring; } +# +# End paragraph processing just requires that we output the +# closing string that was saved and blank it. +sub end_p { + my $current_string = $closing_string; + $closing_string = ''; # Not in a para anymore. + return $current_string; +} +} #--
tag (end tag forbidden) sub start_br { my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_; @@ -1405,7 +1417,7 @@ sub end_sup { #--


tag (end tag forbidden) sub start_hr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # End enclosing para. if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -1445,7 +1457,7 @@ sub end_hr { #--
tag (end tag required) sub start_div { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close enclosing para. if ($target eq 'web') { $currentstring .= $token->[4]; } @@ -1527,9 +1539,9 @@ sub start_li { sub end_li { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # In case there's a

in the

  • if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring .= $token->[2]; } return $currentstring; } @@ -1563,9 +1575,9 @@ sub end_u { #--
      tag (end tag required) sub start_ul { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off enclosing list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { my $TeXtype=&Apache::lonxml::get_param('type',$parstack,$safeeval,undef,0); $Apache::londefdef::list_index=0; @@ -1630,11 +1642,11 @@ sub end_menu { #-- tag (end tag required) sub start_dir { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # In case there's a

      prior to the list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring = " \\begin{itemize} "; + $currentstring .= " \\begin{itemize} "; } return $currentstring; } @@ -1653,9 +1665,9 @@ sub end_dir { #--

        tag (end tag required) sub start_ol { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # In case there's a

        prior to the list. if ($target eq 'web') { - $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); @@ -1707,11 +1719,11 @@ sub end_ol { #--

        tag (end tag required) sub start_dl { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # In case there's a

        unclosed prior to the list. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { - $currentstring = '\begin{description}'; + $currentstring .= '\begin{description}'; $Apache::londefdef::DL++; push(@Apache::londefdef::description,[]); $Apache::londefdef::DD[$Apache::londefdef::DL]=0; @@ -1814,12 +1826,18 @@ sub end_dd { } #-- tag (end tag required) +#
        also ends any prior

        that is not closed. +# but, unless I allow

        's to nest, that's the +# only way I could think of to allow

        in +#

        bodies +# #list of supported attributes: border,width,TeXwidth sub start_table { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my ($textwidth,$currentstring)=('',''); + my $textwidth = ''; + my $currentstring = &end_p; if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } elsif ($target eq 'tex') { my $aa = {}; push @Apache::londefdef::table, $aa; @@ -1883,7 +1901,7 @@ sub start_table { $Apache::londefdef::table[-1]{'minlen'}=[]; $Apache::londefdef::table[-1]{'content'}=[]; $Apache::londefdef::table[-1]{'align'}=[]; - $currentstring='\keephidden{NEW TABLE ENTRY}'; + $currentstring.='\keephidden{NEW TABLE ENTRY}'; } return $currentstring; } @@ -2137,9 +2155,9 @@ sub start_tr { sub end_tr { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close any pending

        in the row. if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring .= $token->[2]; } elsif ($target eq 'tex') { if ($Apache::londefdef::TD_redirection) { &end_td_tex($parstack,$parser,$safeeval); @@ -2414,9 +2432,9 @@ sub end_th_tex { sub end_th { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close any open

        in the row. if ($target eq 'web') { - $currentstring = $token->[2]; + $currentstring .= $token->[2]; } elsif ($target eq 'tex') { $Apache::londefdef::TD_redirection =0; &end_th_tex($parstack,$parser,$safeeval); @@ -2795,7 +2813,7 @@ sub end_allow { #-- sub start_frameset { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = ''; # Close any pending para. if ($target eq 'web') { if (!$Apache::lonxml::registered && $env{'request.state'} eq 'published') { @@ -2864,7 +2882,7 @@ sub end_xmp { #--

         (end tag required)
         sub start_pre {
             my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_;
        -    my $currentstring = '';
        +    my $currentstring = &end_p;	# close off pending 

        if ($target eq 'web') { $currentstring .= $token->[4]; } elsif ($target eq 'tex') { @@ -2927,7 +2945,7 @@ sub end_externallink { #-- sub start_blankspace { my ($target,$token,$tagstack,$parstack,$parser,$safeeval) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # closes off any unclosed

        if ($target eq 'tex') { my $howmuch = &Apache::lonxml::get_param('heigth',$parstack,$safeeval,undef,1); $currentstring .= '\vskip '.$howmuch.' '; @@ -3080,9 +3098,9 @@ sub end_blink { #--

        tag (end tag required) sub start_blockquote { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close any unclosed

        if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } return $currentstring; } @@ -3403,9 +3421,9 @@ sub end_marquee { #-- tag (end tag required) sub start_multicol { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close any pending

        if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } return $currentstring; } @@ -3601,9 +3619,9 @@ sub end_server { #-- tag (end tag forbidden) sub start_spacer { my ($target,$token) = @_; - my $currentstring = ''; + my $currentstring = &end_p; # Close off any open

        tag. if ($target eq 'web') { - $currentstring = $token->[4]; + $currentstring .= $token->[4]; } return $currentstring; }