0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PukiWikiをMoinMoinに

Last updated at Posted at 2015-12-10

以前 PukiWiki から MoinMoin に切り替えたときに、データを変換するために書いたスクリプトです。

割り切って、変換できなかったところは手で修正することにしたため、かなり adHoc なスクリプトになっており汎用性は低いですが、もしかしたら役に立つことがあるかも知れないので掲載しておきます。

puki2moin.pl
# !/usr/bin/perl
while (<>) {
  if (/^\S/ && $text_block) {
      undef $text_block;
    print "}}}\n";
  }
  if (m!^//!) {
    s/^/##/; print; next;
  }
  if (/^#contents/) {
    print "<<TableOfContents>>\n"; next;
  }
  if (/^#comment/) {
    print "<<Comments>>\n";
    print "<<AddComment>>\n";
    next;
  }
  if (/^#setlinebreak(\((on|off|default)\))?/) {
    if ($1 == 'on') {
      $linebreak = 1;
    } elsif ($1 == 'off') {
      $linebreak = 0;
    } elsif ($1 == 'default') {
      $linebreak = 1;
    } else {
      $linebreak = 1;
    }
    s/^#(setlinebreak)/##$1/;
  }
  if (/^#lsx/) {
    print '##<<Include(^@PAGE@/[^/]*$, , 2, sort=ascending, titlesonly)>>', "\n";
    print '<<ListPages(search_term=^@PAGE@/[^/]*$, list_type=number_list, link=subpage)>>', "\n";
    next;
  }
  if (/#fold/) {
    s/^/SeeSaw/;
  }
  s/#br/<<BR>>/g;
  s/\&br;/<<BR>>/g;
  if (/^\~$/) {
    print "\n";
    next;
  }
  s/\~$/<<BR>>/;
  if (/^\&size\(\d+\){"?(.*?)"?};/i) {
    print "= $1 =\n"; next;
  }
  s/^(\*+.*?)\s*\[#g5c2de5c.*\]$/$1/;
  s/^(\*+)\&size\(\d+\){"?(.*?)"?};/$1$2/i;
  s/^\&color\((\w+)\){(.*)};?/<<Color2("$2",$1)>>/i;
  s/\&size\(\d+\){(.*)};?/~+$1+~/i;
  s/\%{2}(.*)\%{2}/--($1)--/g;
  s/^(--(.+)--)/\`\`$1/; # mark to avoid itemize
  s/''/'''/g;
  if (/^\|/) {
    if (/\|h$/) {
      s/\|h$/|/;
      s/^\|/|<rowstyle="background-color:  #E0E0FF;">/;
    }
    if (/\|c$/) {
      # row style
      s/\|c$/|/;
    }
    s/\|LEFT:/|<style="text-align: left;">/g;
    s/\|RIGHT:/|<style="text-align: right;">/g;
    s/\|BGCOLOR\((.*)\):/|<bgcolor="$1">/g;
    s/\|/||/g;
  }
  s/\[\[(.*)>(.*)\]\]/[[$2|$1]]/;
  s/#ref\((\S+\.(png|gif|jpg))\)/{{attachment:$1}}/;
  s/\&ref\((\S+\.(png|gif|jpg)),,(\S+)\);?/{{attachment:$1|$3}}/;
  s/#ref\((\S+\.(png|gif|jpg)),(\S+)\);?/{{attachment:$1}}/;
  if (/^:/) {
    s/^:(.*)\|(.*)/ $1:: $2/;
    print; next;
  }
  if (/^[*]/ && $depth) {
    undef $depth;
  }
  if (/^(\*+)/) {
    $tag = $1;
    $tag =~ s/\*/=/g;
    $_ =~ s/^(\*+)\s*(.*?)(\s*\[#[a-z0-9]*\])?$/=$tag $2 $tag=/;
    print; next;
  }
  if (/^----+$/) {
    print; next;
  }
  if (/^(-{1,3})/) {
    # itemize
    $depth = length($1);
    print ' ' x $depth;
    print '* ', $';
    next;
  }
  if (/^(\+{1,3})/) {
    # enumerate
    $depth = length($1);
    print ' ' x $depth;
    print '1. ', $';
    next;
  }
  if (/^\s+/) {
    # text block
    unless ($text_block) {
      if (/^$/) { print; next; }
      $text_block = 1;
      print ' ' x $depth if ($depth);
      print "{{{\n";
    }
    print $';
    next;
  }
  if ($depth > 0) {
    print ' ' x $depth;
    if ($linebreak) { s/$/<<BR>>/; }
    print $_;
    next;
  }
  if (/^$/) {
    print; next;
  }
  s/\&lastmod;/<<lastmodified()>>/;
  if (/^RIGHT:(更新日時.*)$/) {
    print "<<span(style=\"float: right; vertical-align: bottom\")>>$1<<span>><<BR>>\n";
    next;
  }
  s/\`\`(--(.+)--)/$1/; # drop mark
  print;
  #if ($linebreak && $last !~ /^$/) { print "\n"; }
  #$last = $_;
}
if ($text_block) {
  undef $text_block;
  print "}}}\n";
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?