summaryrefslogtreecommitdiff
path: root/perl/Locale/Po4a
AgeCommit message (Collapse)Author
2010-07-16Sync with (CVS snapshot of) po4a 0.39.1.Jonas Smedegaard
2009-05-25Sync with po4a 0.36.1.Jonas Smedegaard
2008-10-23Revert "Drop superfluous /ms regex extensions."Jonas Smedegaard
It is indeed needed for templates. This reverts commit e35add35a02e84a99b83a4090870ac634e344ca6.
2008-10-23Drop superfluous /ms regex extensions.Jonas Smedegaard
2008-10-23Disable wrap on macro begin at middle of a line.Jonas Smedegaard
2008-10-14Ignore <URL> from html detection in po4a plugin.Jonas Smedegaard
2008-10-01Separate markdown and wrap rules in po4a plugin.Jonas Smedegaard
2008-08-04Extend make and po4a to support templates.Jonas Smedegaard
2008-08-04Much improved Markdown support.Jonas Smedegaard
2008-08-03Fix Locale::Po4a::Text reset flags on new file.Jonas Smedegaard
2008-08-03Fix not stripping final newline of some filesJonas Smedegaard
Text parser is broken: It assumes it is parsing only a single file. po4a 0.34 partly fixed this by checking at beginning of each iteration of the loop if filename changed - but only then - not at the several places do_paragraph() is done multiple times in same iteration. This patch makes does the opposite: it ensures that all files contain a final newline. This breaks files that has no final newline (but those shouold be rare).
2008-08-02Sync Locale::Po4a::Text with po4a 0.34.Jonas Smedegaard
2008-05-31Mark oneliners as non-wrap again (it was needed after all).Jonas Smedegaard
2008-05-31Don't mark oneliners as non-wrap (and polish coding style).Jonas Smedegaard
2008-05-31Fix po4a: Really treat line-based Markdown markup as such.Jonas Smedegaard
2008-05-31Fix po4a: Treat paragraph-based Markdown markup as such.Jonas Smedegaard
2008-05-31Fix po4a: Only strip fortune comment in fortunes mode.Jonas Smedegaard
2008-05-31Sync with po4a 0.33.3.Jonas Smedegaard
2007-11-06Disable markdown tweaks by default in po4a perl module, and instead enable ↵Jonas Smedegaard
them explicitly in Makefile.
2007-11-06Use local Locale::Po4a::Text tweaked to not wrap paragraphs containing ↵Jonas Smedegaard
headlines, blockquotes, triple-quotes or html tags.
ss="hl">
  • By default, tabulations are considered as spaces.
  • =cut
  • my $tabs = "";
  • =item B<breaks>=I<regex>
  • A regular expression matching lines which introduce breaks.
  • The regular expression will be anchored so that the whole line must match.
  • =cut
  • my $breaks;
  • =item B<debianchangelog>
  • Handle the header and footer of
  • released versions, which only contain non translatable informations.
  • =cut
  • my $debianchangelog = 0;
  • =item B<fortunes>
  • Handle the fortunes format, which separate fortunes with a line which
  • consists in '%' or '%%', and use '%%' as the beginning of a comment.
  • =cut
  • my $fortunes = 0;
  • =item B<markdown>
  • Handle some special markup in Markdown-formatted texts.
  • =cut
  • my $markdown = 0;
  • =item B<asciidoc>
  • Handle documents in the asciidoc format.
  • =cut
  • my $asciidoc = 0;
  • =back
  • =cut
  • sub initialize {
  • my $self = shift;
  • my %options = @_;
  • $self->{options}{'asciidoc'} = 1;
  • $self->{options}{'breaks'} = 1;
  • $self->{options}{'debianchangelog'} = 1;
  • $self->{options}{'debug'} = 1;
  • $self->{options}{'fortunes'} = 1;
  • $self->{options}{'markdown'} = 1;
  • $self->{options}{'nobullets'} = 1;
  • $self->{options}{'tabs'} = 1;
  • $self->{options}{'verbose'} = 1;
  • foreach my $opt (keys %options) {
  • die wrap_mod("po4a::text",
  • dgettext("po4a", "Unknown option: %s"), $opt)
  • unless exists $self->{options}{$opt};
  • $self->{options}{$opt} = $options{$opt};
  • }
  • if (defined $options{'nobullets'}) {
  • $bullets = 0;
  • }
  • if (defined $options{'tabs'}) {
  • $tabs = $options{'tabs'};
  • }
  • if (defined $options{'breaks'}) {
  • $breaks = $options{'breaks'};
  • }
  • if (defined $options{'debianchangelog'}) {
  • $debianchangelog=1;
  • }
  • if (defined $options{'fortunes'}) {
  • $fortunes=1;
  • }
  • if (defined $options{'markdown'}) {
  • $markdown=1;
  • }
  • $asciidoc=1 if (defined $options{'asciidoc'});
  • }
  • sub parse {
  • my $self = shift;
  • my ($line,$ref);
  • 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;
  • }
  • chomp($line);
  • $self->{ref}="$ref";
  • if ($debianchangelog and
  • $expect_header and
  • $line =~ /^(\w[-+0-9a-z.]*)\ \(([^\(\) \t]+)\) # src, version
  • \s+([-+0-9a-z.]+); # distribution
  • \s*urgency\s*\=\s*(.*\S)\s*$/ix) { #
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $self->pushline("$line\n");
  • $expect_header=0;
  • } elsif ($debianchangelog and
  • $line =~ m/^ \-\- (.*) <(.*)> ((\w+\,\s*)?\d{1,2}\s+\w+\s+\d{4}\s+\d{1,2}:\d\d:\d\d\s+[-+]\d{4}(\s+\([^\\\(\)]\))?)$/) {
  • # Found trailer
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $self->pushline("$line\n");
  • $expect_header=1;
  • } elsif ($fortunes and
  • $line =~ m/^%%?\s*$/) {
  • # Found end of fortune
  • 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 ( (defined $self->{verbatim})
  • and ($self->{verbatim} == 2)) {
  • # Untranslated blocks
  • $self->pushline($line."\n");
  • if ($asciidoc and
  • ($line =~ m/^(\/{4,}|~{4,})$/)) {
  • undef $self->{verbatim};
  • undef $self->{type};
  • $wrapped_mode = 1;
  • }
  • } elsif ( ($line =~ /^\s*$/)
  • or ( defined $breaks
  • and $line =~ m/^$breaks$/)) {
  • # Break paragraphs on lines containing only spaces
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $wrapped_mode = 1 unless defined($self->{verbatim});
  • $self->pushline($line."\n");
  • } elsif ($asciidoc and (not defined($self->{verbatim})) and
  • ($line =~ m/^(\+|--)$/)) {
  • # List Item Continuation or List Block
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $self->pushline($line."\n");
  • } elsif ($asciidoc and (not defined($self->{verbatim})) and
  • ($line =~ m/^(={4,}|-{4,}|~{4,}|\^{4,}|\+{4,})$/) and
  • (defined($paragraph) )and
  • ($paragraph =~ m/^[^\n]*\n$/s) and
  • (length($paragraph) == (length($line)+1))) {
  • # Found title
  • $wrapped_mode = 0;
  • my $level = $line;
  • $level =~ s/^(.).*$/$1/;
  • my $t = $self->translate($paragraph,
  • $self->{ref},
  • "Title $level",
  • "wrap" => 0);
  • $self->pushline($t);
  • $paragraph="";
  • $wrapped_mode = 1;
  • $self->pushline(($level x (length($t)-1))."\n");
  • } elsif ($asciidoc and
  • ($line =~ m/^(={1,5})( +)(.*?)( +\1)?$/)) {
  • my $titlelevel1 = $1;
  • my $titlespaces = $2;
  • my $title = $3;
  • my $titlelevel2 = $4||"";
  • # Found one line title
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $wrapped_mode = 0;
  • $paragraph="";
  • my $t = $self->translate($title,
  • $self->{ref},
  • "Title $titlelevel1",
  • "wrap" => 0);
  • $self->pushline($titlelevel1.$titlespaces.$t.$titlelevel2."\n");
  • $wrapped_mode = 1;
  • } elsif ($asciidoc and
  • ($line =~ m/^(\/{4,}|\+{4,}|-{4,}|\.{4,}|\*{4,}|_{4,}|={4,}|~{4,})$/)) {
  • # Found one delimited block
  • my $t = $line;
  • $t =~ s/^(.).*$/$1/;
  • my $type = "delimited block $t";
  • if (defined $self->{verbatim} and ($self->{type} ne $type)) {
  • $paragraph .= "$line\n";
  • } else {
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • if ( (defined $self->{type})
  • and ($self->{type} eq $type)) {
  • undef $self->{type};
  • undef $self->{verbatim};
  • $wrapped_mode = 1;
  • } else {
  • if ($t eq "\/") {
  • # CommentBlock, should not be treated
  • $self->{verbatim} = 2;
  • } elsif ($t eq "+") {
  • # PassthroughBlock
  • $wrapped_mode = 0;
  • $self->{verbatim} = 1;
  • } elsif ($t eq "-") {
  • # ListingBlock
  • $wrapped_mode = 0;
  • $self->{verbatim} = 1;
  • } elsif ($t eq ".") {
  • # LiteralBlock
  • $wrapped_mode = 0;
  • $self->{verbatim} = 1;
  • } elsif ($t eq "*") {
  • # SidebarBlock
  • $wrapped_mode = 1;
  • } elsif ($t eq "_") {
  • # QuoteBlock
  • if ( (defined $self->{type})
  • and ($self->{type} eq "verse")) {
  • $wrapped_mode = 0;
  • $self->{verbatim} = 1;
  • } else {
  • $wrapped_mode = 1;
  • }
  • } elsif ($t eq "=") {
  • # ExampleBlock
  • $wrapped_mode = 1;
  • } elsif ($t eq "~") {
  • # Filter blocks, TBC: not translated
  • $wrapped_mode = 0;
  • $self->{verbatim} = 2;
  • }
  • $self->{type} = $type;
  • }
  • $paragraph="";
  • $self->pushline($line."\n");
  • }
  • } elsif ($asciidoc and not defined $self->{verbatim} and
  • ($line =~ m/^\[\[([^\]]*)\]\]$/)) {
  • # Found BlockId
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $wrapped_mode = 1;
  • $self->pushline($line."\n");
  • undef $self->{bullet};
  • undef $self->{indent};
  • } elsif ($asciidoc and not defined $self->{verbatim} and
  • ($paragraph eq "") and
  • ($line =~ m/^((?:NOTE|TIP|IMPORTANT|WARNING|CAUTION):\s+)(.*)$/)) {
  • my $type = $1;
  • my $text = $2;
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph=$text."\n";
  • $wrapped_mode = 1;
  • $self->pushline($type);
  • undef $self->{bullet};
  • undef $self->{indent};
  • } elsif ($asciidoc and not defined $self->{verbatim} and
  • ($line =~ m/^\[(NOTE|TIP|IMPORTANT|WARNING|CAUTION|verse|quote)\]$/)) {
  • my $type = $1;
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • $wrapped_mode = 1;
  • $self->pushline($line."\n");
  • if ($type eq "verse") {
  • $wrapped_mode = 0;
  • }
  • undef $self->{bullet};
  • undef $self->{indent};
  • } elsif ($asciidoc and not defined $self->{verbatim} and
  • ($line =~ m/^\[(verse|quote), +(.*)\]$/)) {
  • my $type = $1;
  • my $arg = $2;
  • do_paragraph($self,$paragraph,$wrapped_mode);
  • $paragraph="";
  • my $t = $self->translate($arg,
  • $self->{ref},
  • "$type",
  • "wrap" => 0);
  • $self->pushline("[$type, $t]\n");
  • $wrapped_mode = 1;