summaryrefslogtreecommitdiff
path: root/localworddiff
diff options
context:
space:
mode:
authorJonas Smedegaard <dr@jones.dk>2013-05-08 16:00:34 +0200
committerJonas Smedegaard <dr@jones.dk>2013-05-08 16:00:34 +0200
commit86c82db6780593c4a7a9f52d1afbce29c5e37e8b (patch)
tree976208fe571d95b337aa84434a76225e4101dfd8 /localworddiff
parentda3dd87e3bae0e7d618c49d5deccfea75a54ea1b (diff)
Fix handle UTF-8 chars.
Diffstat (limited to 'localworddiff')
-rwxr-xr-xlocalworddiff10
1 files changed, 7 insertions, 3 deletions
diff --git a/localworddiff b/localworddiff
index 1561684..af29599 100755
--- a/localworddiff
+++ b/localworddiff
@@ -33,14 +33,18 @@ my ( $infile1, $infile2, $outfile ) = @ARGV;
die 'Missing input file arguments'
unless ( $infile1 and $infile2 );
+# read infiles using File::Slurp (Text::WordDiff don't handle UTF-8)
+my $text1 = read_file( $infile1, binmode => ':utf8' );
+my $text2 = read_file( $infile2, binmode => ':utf8' );
+
# use console if no output file provided as third argument
unless ($outfile) {
- print word_diff $infile1, $infile2, { STYLE => 'ANSIColor' };
+ print word_diff $text1, $text2, { STYLE => 'ANSIColor' };
exit 0;
}
# resolve diff
-my $diff = word_diff $infile1, $infile2, { STYLE => 'HTMLTwoLines' };
+my $diff = word_diff $text1, $text2, { STYLE => 'HTMLTwoLines' };
# apply markup to each file div of resolved diff
my $d = "<div class=\"file\">";
@@ -87,6 +91,6 @@ my $page = html(
CHUNK( $diffchunk[1] ),
),
);
-write_file( $outfile, $page );
+write_file( $outfile, { binmode => ':utf8' }, $page );
1;