Last active
December 10, 2015 06:59
-
-
Save komeda-shinji/c2c42831741e53309cda to your computer and use it in GitHub Desktop.
PukiWikiをMoinMoinに ref: http://qiita.com/komeda-shinji/items/fc1377dff7360eea8067
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment