#!/usr/bin/perl

use strict;
use utf8;
use Encode;

my $file = $ARGV[0] || die;

open(IF, $file) || die;
$/ = undef;
my $text = <IF>;
close(IF);

$text = decode('utf8', $text);
$text =~ s/^\*/= /mg;
$text =~ s/^\*\*/== /mg;
$text =~ s/^\- /  * /mg;
$text =~ s/^\-- /    * /mg;
$text =~ s/^\--- /      * /mg;
$text =~ s/\[\[/[/g;
$text =~ s/\|/||/g;
$text =~ s/]]/]/g;
$text =~ s/~%/\n/g;
$text = encode('utf8', $text);

my $outd = 'converted';
mkdir $outd;
open(OF, "> $outd/$file") || die;
print OF $text;
close(OF);

1;

