summaryrefslogtreecommitdiff
path: root/perl/Locale
diff options
context:
space:
mode:
Diffstat (limited to 'perl/Locale')
-rw-r--r--perl/Locale/Po4a/Text.pm86
1 files changed, 68 insertions, 18 deletions
diff --git a/perl/Locale/Po4a/Text.pm b/perl/Locale/Po4a/Text.pm
index eecd333..0cc2cc8 100644
--- a/perl/Locale/Po4a/Text.pm
+++ b/perl/Locale/Po4a/Text.pm
@@ -129,8 +129,21 @@ sub parse {
my $paragraph="";
my $wrapped_mode = 1;
my $expect_header = 1;
+ my $end_of_paragraph = 0;
($line,$ref)=$self->shiftline();
+ my $file = $ref;
+ $file =~ s/:[0-9]+$//;
while (defined($line)) {
+ $ref =~ m/^(.*):[0-9]+$/;
+ if ($1 ne $file) {
+ $file = $1;
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph="";
+ $wrapped_mode = 1;
+ $expect_header = 1;
+ }
+
+ # TODO: preserve original line ends throughout the code instead
chomp($line);
$self->{ref}="$ref";
if ($debianchangelog and
@@ -153,6 +166,8 @@ sub parse {
$line =~ m/^%%?\s*$/) {
# Found end of fortune
do_paragraph($self,$paragraph,$wrapped_mode);
+ # FIXME: test if this is still needed when always adding
+ # newline in do_paragraph()
$self->pushline("\n") unless ( $wrapped_mode == 0
or $paragraph eq "");
$paragraph="";
@@ -161,42 +176,55 @@ sub parse {
} elsif ($line =~ /^\s*$/) {
# Break paragraphs on lines containing only spaces
do_paragraph($self,$paragraph,$wrapped_mode);
- $self->pushline("\n") unless ( $wrapped_mode == 0
- or $paragraph eq "");
$paragraph="";
$wrapped_mode = 1;
$self->pushline($line."\n");
- } elsif ( $line =~ /^=*$/
- or $line =~ /^_*$/
- or $line =~ /^-*$/) {
+ } elsif ($line =~ /^-- $/) {
+ # Break paragraphs on email signature hint
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph="";
+ $wrapped_mode = 1;
+ $self->pushline($line."\n");
+ } elsif ( $line =~ /^=+$/
+ or $line =~ /^_+$/
+ or $line =~ /^-+$/) {
$wrapped_mode = 0;
$paragraph .= $line."\n";
do_paragraph($self,$paragraph,$wrapped_mode);
$paragraph="";
$wrapped_mode = 1;
} elsif ($markdown and
+ ( $line =~ /^\s*\[\[\!\S+\s*$/ # macro begin
+ or $line =~ /^\s*"""\s*\]\]\s*$/)) { # """ textblock inside macro end
+ # Avoid translating Markdown lines containing only markup
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph="";
+ $wrapped_mode = 1;
+ $self->pushline("$line\n");
+ } elsif ($markdown and
( $line =~ /^#/ # headline
or $line =~ /^\s*\[\[\!\S[^\]]*\]\]\s*$/)) { # sole macro
- # Found Markdown markup that should be preserved as a single line
+ # Preserve some Markdown markup as a single line
do_paragraph($self,$paragraph,$wrapped_mode);
$paragraph="$line\n";
$wrapped_mode = 0;
+ $end_of_paragraph = 1;
+ } elsif ($markdown and
+ ( $line =~ /^"""/)) { # """ textblock inside macro end
+ # Markdown markup needing separation _before_ this line
do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph="$line\n";
$wrapped_mode = 1;
- $paragraph="";
- } elsif ($markdown and
- ( $paragraph =~ m/^>/ # blockquote
- or $paragraph =~ m/[<>]/ # maybe html
- or $paragraph =~ m/^"""/ # textblock inside macro end
- or $paragraph =~ m/"""$/)) { # textblock inside macro begin
- # Found Markdown markup that might not survive wrapping
- $wrapped_mode = 0;
- $paragraph .= $line."\n";
} else {
if ($line =~ /^\s/) {
# A line starting by a space indicates a non-wrap
# paragraph
$wrapped_mode = 0;
+ } elsif ($markdown and
+ ( $line =~ /\S $/ # explicit newline
+ or $line =~ /"""$/)) { # """ textblock inside macro begin
+ # Markdown markup needing separation _after_ this line
+ $end_of_paragraph = 1;
}
if ($fortunes) {
$line =~ s/%%(.*)$//;
@@ -209,7 +237,23 @@ sub parse {
# (more than 3)
# are considered as verbatim paragraphs
$wrapped_mode = 0 if ( $paragraph =~ m/^(\*|[0-9]+[.)] )/s
- or $paragraph =~ m/[ \t][ \t][ \t]/s);
+ or $paragraph =~ m/[ \t][ \t][ \t]/s);
+ if ($markdown) {
+ # Some Markdown markup can (or might) not survive wrapping
+ $wrapped_mode = 0 if (
+ $paragraph =~ /^>/ms # blockquote
+ or $paragraph =~ /^( {8}|\t)/ms # monospaced
+ or $paragraph =~ /^\$(\S+[{}]\S*\s*)+/ms # Xapian macro
+ or $paragraph =~ /[<>]/ms # maybe html
+ or $paragraph =~ /^\s*\[\[\!\S[^\]]+$/ms # macro begin
+ );
+ }
+ if ($end_of_paragraph) {
+ do_paragraph($self,$paragraph,$wrapped_mode);
+ $paragraph="";
+ $wrapped_mode = 1;
+ $end_of_paragraph = 0;
+ }
($line,$ref)=$self->shiftline();
}
if (length $paragraph) {
@@ -268,10 +312,16 @@ TEST_BULLET:
}
# TODO: detect indented paragraphs
- $self->pushline( $self->translate($paragraph,
+ my $transfinal = $self->translate($paragraph,
$self->{ref},
"Plain text",
- "wrap" => $wrap) );
+ "wrap" => $wrap);
+
+ # TODO: preserve original line ends throughout the code instead
+ chomp $transfinal;
+ $transfinal .= "\n";
+
+ $self->pushline( $transfinal );
}
1;