[Po4a-devel] [SGML] Missing end of line in verbatim blocks

Nicolas François nicolas.francois at centraliens.net
Thu Sep 15 21:06:20 UTC 2005


Hello,

An issue was mentionned on IRC regarding such code in an SGML document:
   <example>
 foo
 bar
</example>

Which was converted to:
   <example>foo
 bar</example>

The attached patch tries to fix this.

Can anybody have a look at it ?
Is it too nsgmls specific (Martin has the not so secret which to get rid
of nsgmls) ?
Is there other places where an end of line should be added ?


I intend to commit it this week-end if there is no issue.

TIA,
-- 
Nekral
-------------- next part --------------
Index: lib/Locale/Po4a/Sgml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Sgml.pm,v
retrieving revision 1.77
diff -u -r1.77 Sgml.pm
--- lib/Locale/Po4a/Sgml.pm	15 Sep 2005 17:28:43 -0000	1.77
+++ lib/Locale/Po4a/Sgml.pm	15 Sep 2005 19:22:42 -0000
@@ -763,6 +763,7 @@
     # Some values for the parsing
     my @open=(); # opened translation container tags
     my $verb=0;  # can we wrap or not
+    my $verb_last_ref;
     my $seenfootnote=0;
     my $indent=0; # indent level
     my $lastchar = ''; # 
@@ -868,7 +869,13 @@
 		    if (scalar @open);
 	    }
 
-	    $verb++ if $verbatim{$event->data->name()};
+	    if ($verbatim{$event->data->name()}) {
+		$verb++;
+		# Keep a reference to the line that openned the verbatim
+		# section. This is needed to check if its data starts on
+		# the same line.
+		$verb_last_ref = $ref;
+	    }
 	    if ($indent{$event->data->name()}) {
 		# push the indenting space only if not in verb before that tag
 		# push trailing "\n" only if not in verbose afterward
@@ -886,6 +893,17 @@
 		           : 
 		       '</'.lc($event->data->name()).'>');
 
+	    if ($verb) {
+		# Tag in a verbatim section. Check if it appeared at
+		# the same line than the previous data. If not, it
+		# means that an end of line must be added to the
+		# buffer.
+		if ($ref ne $verb_last_ref) {
+		    # FIXME: Does it work if $verb > 1
+		    $buffer .= "\n";
+		    $verb_last_ref = $ref;
+		}
+	    }
 	    print STDERR "Seen $tag, level=".(scalar @open).", verb=$verb\n"
 		if ($debug{'tag'});
 
@@ -934,7 +952,15 @@
 	    $cdata =~ s/{PO4A-amp}/&/g;
             $cdata =~ s/{PO4A-end}/\]\]>/g;
             $cdata =~ s/{PO4A-beg-([^\}]+)}/<!\[$1\[/g;
-            unless ($verb) {
+	    if ($verb) {
+		# Check if this line of data appear on the same line
+		# than the previous tag. If not, append an end of line
+		# to the buffer.
+		if ($ref ne $verb_last_ref) {
+		    $buffer .= "\n";
+		    $verb_last_ref = $ref;
+		}
+	    } else {
               $cdata =~ s/\\t/ /g;
               $cdata =~ s/\s+/ /g;
 	      $cdata =~ s/^\s//s if $lastchar eq ' ';
@@ -953,6 +979,13 @@
 
 	elsif ($event->type eq 're') {
 	    if ($verb) {
+		# Check if this line of data appear on the same line
+		# than the previous tag. If not, append an end of line
+		# to the buffer.
+		if ($ref ne $verb_last_ref) {
+		    $buffer .= "\n";
+		    $verb_last_ref = $ref;
+		}
 		$buffer .= "\n";
 	    } elsif ($lastchar ne ' ') {
 		$buffer .= " ";
@@ -999,8 +1032,8 @@
     $para = $self->translate($para,$ref,$type,
 			     'wrap' => ! $verb,
 			     'wrapcol' => (75 - $indent));
-    $para =~ s/^\n//s;
     unless ($verb) {
+	$para =~ s/^\n//s;
 	my $toadd=" " x ($indent+1);
 	$para =~ s/^/$toadd/mg;
     }


More information about the Po4a-devel mailing list