[Koha-cvs] CVS: koha/misc/translator TmplTokenizer.pm,1.25,1.26

Ambrose C. LI acli at users.sourceforge.net
Wed Feb 25 07:08:46 CET 2004


Update of /cvsroot/koha/koha/misc/translator
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1842

Modified Files:
	TmplTokenizer.pm 
Log Message:
This should make it handle commenting out of whole blocks of HTML better.
It seems to be still correct, and it is no longer complaining about syntax
errors when seeing commented-out HTML (esp. with TMPL_* directives).

Don't try to translate stuff between <title>...</title> too, the stuff in
the middle is supposed to be PCDATA.


Index: TmplTokenizer.pm
===================================================================
RCS file: /cvsroot/koha/koha/misc/translator/TmplTokenizer.pm,v
retrieving revision 1.25
retrieving revision 1.26
diff -C2 -r1.25 -r1.26
*** TmplTokenizer.pm	23 Feb 2004 18:49:56 -0000	1.25
--- TmplTokenizer.pm	25 Feb 2004 06:08:41 -0000	1.26
***************
*** 34,37 ****
--- 34,38 ----
  use vars qw( $pedantic_attribute_error_in_nonpedantic_mode_p );
  use vars qw( $pedantic_tmpl_var_use_in_nonpedantic_mode_p );
+ use vars qw( $pedantic_error_markup_in_pcdata_p );
  
  ###############################################################################
***************
*** 63,67 ****
     # This is no longer similar to the original regexp in subst.pl :-(
     # Note that we don't want <> in compat mode; Mozilla knows about <
!    q{(<\/?(?:|(?:"(?:} . $re_directive . q{|[^"])*"|'(?:} . $re_directive . q{|[^'])*'|--(?:[^-]|-[^-])*--|(?:}
     . $re_directive
     . q{|(?!--)[^"'<>} . $etag . q{]))+))([} . $etag . q{]|(?=<))(.*)};
--- 64,68 ----
     # This is no longer similar to the original regexp in subst.pl :-(
     # Note that we don't want <> in compat mode; Mozilla knows about <
!    q{(<\/?(?:|(?:"(?:} . $re_directive . q{|[^"])*"|'(?:} . $re_directive . q{|[^'])*'|--(?:(?!--)(?:$re_directive)*.)*--|(?:}
     . $re_directive
     . q{|(?!--)[^"'<>} . $etag . q{]))+))([} . $etag . q{]|(?=<))(.*)};
***************
*** 92,95 ****
--- 93,97 ----
  sub CDATA_MODE_P	() {'cdata-mode-p'}
  sub CDATA_CLOSE		() {'cdata-close'}
+ sub PCDATA_MODE_P	() {'pcdata-mode-p'}	# additional submode for CDATA
  
  sub ALLOW_CFORMAT_P	() {'allow-cformat-p'}
***************
*** 163,166 ****
--- 165,173 ----
  }
  
+ sub pcdata_mode_p {
+     my $this = shift;
+     return $this->{+PCDATA_MODE_P};
+ }
+ 
  sub cdata_close {
      my $this = shift;
***************
*** 228,231 ****
--- 235,244 ----
  }
  
+ sub _set_pcdata_mode {
+     my $this = shift;
+     $this->{+PCDATA_MODE_P} = $_[0];
+     return $this;
+ }
+ 
  sub _set_cdata_close {
      my $this = shift;
***************
*** 321,324 ****
--- 334,338 ----
      } else {				# tag/declaration/processing instruction
  	my $ok_p = 0;
+ 	my $bad_comment_p = 0;
  	for (my $cdata_close = $this->cdata_close;;) {
  	    if ($this->cdata_mode_p) {
***************
*** 350,359 ****
  		    warn_normal "SGML \"closed start tag\" notation: $head<\n", $this->line_number if $tail eq '';
  		}
! 	    } elsif ($this->_peek_readahead =~ /^<!--(?:(?!-->).)*-->/s) {
  		($kind, $it) = (TmplTokenType::COMMENT, $&);
  		$this->_set_readahead( $' );
  		$ok_p = 1;
! 		warn_normal "Syntax error in comment: $&\n", $this->line_number_start;
! 		$this->_set_syntaxerror( 1 );
  	    }
  	last if $ok_p;
--- 364,372 ----
  		    warn_normal "SGML \"closed start tag\" notation: $head<\n", $this->line_number if $tail eq '';
  		}
! 	    } elsif ($this->_peek_readahead =~ /^<!--(?:(?!-->)$re_directive*.)*-->/os) {
  		($kind, $it) = (TmplTokenType::COMMENT, $&);
  		$this->_set_readahead( $' );
  		$ok_p = 1;
! 		$bad_comment_p = 1;
  	    }
  	last if $ok_p;
***************
*** 377,380 ****
--- 390,397 ----
  	if ($it =~ /^$re_directive/ios && !$this->cdata_mode_p) {
  	    $kind = TmplTokenType::DIRECTIVE;
+ 	} elsif ($bad_comment_p) {
+ 	    warn_normal sprintf("Syntax error in comment: %s\n", $it),
+ 		    $this->line_number_start;
+ 	    $this->_set_syntaxerror( 1 );
  	}
  	if (!$ok_p && $eof_p) {
***************
*** 401,404 ****
--- 418,426 ----
  		$this->_set_cdata_mode( 1 );
  		$this->_set_cdata_close( "</$1\\s*>" );
+ 		$this->_set_pcdata_mode( 0 );
+ 	    } elsif ($it->string =~ /^<(title)\b/is) {
+ 		$this->_set_cdata_mode( 1 );
+ 		$this->_set_cdata_close( "</$1\\s*>" );
+ 		$this->_set_pcdata_mode( 1 );
  	    }
  	    $it->set_attributes( $this->_extract_attributes($it->string, $it->line_number) );
***************
*** 415,419 ****
--- 437,449 ----
  	    $it .= $next->string;
  	}
+ 	if ($this->pcdata_mode_p) {
+ 	    my $check = $it;
+ 	    $check =~ s/$re_directive//gos;
+ 	    warn_pedantic "Markup found in PCDATA\n", $this->line_number,
+ 			    \$pedantic_error_markup_in_pcdata_p
+ 		    if $check =~ /$re_tag_compat/s;
+ 	}
  	$it = TmplToken->new( $it, TmplTokenType::CDATA, $this->line_number );
+ 	$this->_set_pcdata_mode, 0;
  	$this->_set_cdata_close, undef;
      }





More information about the Koha-cvs mailing list