Package: po4a
Version: 0.33.3-1
Severity: wishlist
Tags: patch

Attached is a patch for the Text module to support Markdown as used with
Ikiwiki.

Markdown is text-based, but in some situations changes to linebreaks affect
output, so need to be flagged as unwrappable.

Patch seems ok, but has not yet been fully tested extensively due to bug#484023
and #484026.


I suggest including it, even if not yet fully working, as the missing stuff
might be possible to work around outside of po4a.


If interested in my work on internationalizing Ikiwiki, here's a quick'n'dirty
way to see the po4a in action - and see what goes wrong currently:

    git clone git://source.jones.dk/ikiwiki
    cd ikiwiki
    make        # pulls current non-PO-based l10n
    make pot
    make po
    sed -i 's/, fuzzy//' po/*.po
    make translations
    cd basewiki_l10n/da
    git diff    # Shows diff between old and PO-based l10n

You don't need to apply the patch to run the above - a patched Text module is
included with the source.

The example is for danish translation, but you shouldn't need to know the
language to recognize the problematic changes to Markdown.


Kind regards,
 - Jonas


-- System Information:
Debian Release: lenny/sid
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.25-2-amd64 (SMP w/2 CPU cores)
Locale: LANG=da_DK.UTF-8, LC_CTYPE=da_DK.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash

Versions of packages po4a depends on:
ii  gettext                   0.17-2         GNU Internationalization utilities
ii  libsgmls-perl             1.03ii-32      Perl modules for processing SGML p
ii  perl                      5.10.0-10      Larry Wall's Practical Extraction 
ii  perl-modules              5.10.0-10      Core Perl modules
ii  sp                        1.3.4-1.2.1-47 James Clark's SGML parsing tools

Versions of packages po4a recommends:
ii  liblocale-gettext-perl        1.05-4     Using libc functions for internati
ii  libterm-readkey-perl          2.30-4     A perl module for simple terminal 
ii  libtext-wrapi18n-perl         0.06-6     internationalized substitute of Te

-- no debconf information
--- /usr/share/perl5/Locale/Po4a/Text.pm        2008-04-02 23:17:10.000000000 
+0200
+++ Text.pm     2008-06-02 00:50:55.000000000 +0200
@@ -92,6 +92,14 @@
 
 my $fortunes = 0;
 
+=item B<markdown>
+
+Handle some special markup in Markdown-formatted texts.
+
+=cut
+
+my $markdown = 0;
+
 sub initialize {
     my $self = shift;
     my %options = @_;
@@ -109,6 +117,10 @@
     if (defined $options{'fortunes'}) {
         $fortunes=1;
     }
+
+    if (defined $options{'markdown'}) {
+        $markdown=1;
+    }
 }
 
 sub parse {
@@ -162,13 +174,33 @@
             do_paragraph($self,$paragraph,$wrapped_mode);
             $paragraph="";
             $wrapped_mode = 1;
+        } elsif ($markdown and
+                 (   $line =~ /^#/            # headline
+                  or $line =~ /^\s*\[\[\!\S[^\]]*\]\]\s*$/)) { # sole macro
+            # Found Markdown markup that should be preserved as a single line
+            do_paragraph($self,$paragraph,$wrapped_mode);
+            $paragraph="$line\n";
+            $wrapped_mode = 0;
+            do_paragraph($self,$paragraph,$wrapped_mode);
+            $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;
             }
-            $line =~ s/%%(.*)$//;
+            if ($fortunes) {
+                $line =~ s/%%(.*)$//;
+            }
 # TODO: comments
             $paragraph .= $line."\n";
         }

Reply via email to