[Po4a-devel] comments in XML

Nicolas François nicolas.francois at centraliens.net
Tue Nov 21 01:37:40 CET 2006


Hello Azamat,

On Fri, Nov 17, 2006 at 10:22:01PM +0500, Azamat H. Hackimov wrote:
> Begin of discussion:
> http://alioth.debian.org/forum/forum.php?thread_id=3014&forum_id=694
> 
> I have Guide-file with header like this:

[...]

> And I need preserve commented cvs "$Header: $" and warnings about license.
> I know, it's possible make with addenda, but this is not Perl-way :).
> I found temporary fix for this, like a commenting out this string in Xml.pm:
> 
> f_extract       => \&tag_extract_comment,
> 
> but this made other bug - program crashes when try parse commented tags.

I could not reproduce this crash. On what guide file was it? (I tried
xml-guide.xml)


Here is a first patch that implements a kind of comments extraction.
It is not a final version (there are probably a lot of comments that are
still just dropped), but it should give an idea of how it works.

Can you check whether that would be OK for the Gentoo documentation?
(I'm mostly worried about the place where the comments appear (which can
be different from the place the comment was extracted))

Kind Regards,
-- 
Nekral
-------------- next part --------------
Index: lib/Locale/Po4a/Xml.pm
===================================================================
RCS file: /cvsroot/po4a/po4a/lib/Locale/Po4a/Xml.pm,v
retrieving revision 1.48
diff -u -r1.48 Xml.pm
--- lib/Locale/Po4a/Xml.pm	13 Jun 2006 23:23:34 -0000	1.48
+++ lib/Locale/Po4a/Xml.pm	21 Nov 2006 00:28:33 -0000
@@ -59,6 +59,8 @@
 #It will mantain the path from the root tag to the current one
 my @path;
 
+my @comments;
+
 sub read {
 	my ($self,$filename)=@_;
 	push @{$self->{DOCPOD}{infile}}, $filename;
@@ -343,8 +345,7 @@
 	} else {
 		die wrap_ref_mod($ref, "po4a::xml", dgettext("po4a", "Internal error: unknown type identifier '%s'."), $options->{'type'});
 	}
-
-	$text = $self->translate($text,$ref,$comment,'wrap'=>$wrap);
+	$text = $self->translate($text,$ref,$comment,'wrap'=>$wrap, comment => $options->{'comments'});
 	return $text;
 }
 
@@ -959,6 +960,7 @@
 		    and $f_extract eq \&tag_extract_comment) {
 			# Remove the content of the comments
 			($eof, @text) = $self->extract_tag($type,1);
+			push @comments, @text;
 		} else {
 			my ($tmpeof, @tag) = $self->extract_tag($type,0);
 			# Append the found inline tag
@@ -1201,6 +1203,15 @@
 	my ($self, $translate) = (shift, shift);
 	my @paragraph = @_;
 
+	my $comments;
+	while (@comments) {
+		my ($t,$l) = (shift @comments, shift @comments);
+		$comments .= "\n" if defined $comments;
+		$comments .= $t;
+	}
+	$self->pushline("<!--".$comments."-->\n") if defined $comments;
+	@comments = ();
+
 	if ( length($self->join_lines(@paragraph)) > 0 ) {
 		my $struc = $self->get_path;
 		my $options = $self->tag_in_list($struc,@{$self->{tags}});
@@ -1211,7 +1222,8 @@
 				$self->join_lines(@paragraph),
 				$paragraph[1], {
 					type=>"tag",
-					tag_options=>$options
+					tag_options=>$options,
+					comments=>$comments
 				}));
 		} else {
 			# Inform that this tag isn't translated in debug mode


More information about the Po4a-devel mailing list