#!/usr/bin/perl
use strict;
use HTML::Parser;
# set up a hash containing the umlauted characters and their replacements:
my %replace = (
"\xC4" => 'Ae', "\xCF" => 'Ie', "\xD6" => 'Oe', "\xDC" => 'Ue',
"\xE4" => 'ae', "\xEF" => 'ie', "\xF6" => 'oe', "\xFC" => 'ue',
);
my $um = join '', keys %replace;
binmode STDIN, ':utf8';
binmode STDOUT, ':utf8';
$/ = undef;
my $input = <>;
my $output = '';
my $p = HTML::Parser->new( api_version => 3,
start_h => [ \&fix_umlaut, 'tagname, attr, text' ],
default_h => [ \©, 'text' ],
);
$p->empty_element_tags( 1 );
$p->parse( $input );
print $output;
sub fix_umlaut
{
my ( $tagname, $attr, $text ) = @_;
$output .= $text;
if ( $tagname eq 'idx:orth' and $$attr{value} =~ /[$um]/ ) {
$text =~ s/([$um])/$replace{$1}/g;
$output .= $text; # repeat the tag with modified umlauts
}
}
sub copy
{
$output .= $_[0];
}