#!/usr/bin/perl
use warnings;
use strict;
use utf8;
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
sub unponc {
my $word = shift;
$word = lc($word);
$word =~ s/ḃ/bh/g;
$word =~ s/ċ/ch/g;
$word =~ s/ḋ/dh/g;
$word =~ s/ḟ/fh/g;
$word =~ s/ġ/gh/g;
$word =~ s/ṁ/mh/g;
$word =~ s/ṗ/ph/g;
$word =~ s/ṡ/sh/g;
$word =~ s/ṫ/th/g;
$word;
}
while(<>) {
chomp;
s/ +$//;
if (/^$/) {
print "\n";
} else {
my $line = $_;
my $word = '';
if (/^\{\{insular\|([^}]*)\}\}/) {
$word = $1;
my $unponcw = unponc($word);
my $lword = lc($word);
if($lword eq $unponcw) {
print "{{anchor|$lword}}\n";
} else {
print "{{anchor|$lword|$unponcw}}\n";
}
print "{{outdent|$line}}\n";
}
}
}