feat: add explicit UTF-8 handling
This commit is contained in:
6
m2h.pl
6
m2h.pl
@@ -2,6 +2,7 @@
|
||||
use strict;
|
||||
use Getopt::Long;
|
||||
use MarkdownParser;
|
||||
use open qw(:std :encoding(UTF-8));
|
||||
|
||||
sub show_help {
|
||||
print <<"EOF";
|
||||
@@ -30,6 +31,7 @@ sub read_input {
|
||||
if ($file) {
|
||||
open my $fh, '<', $file
|
||||
or die "Error: Cannot open file: $file\n";
|
||||
binmode $fh, ':encoding(UTF-8)';
|
||||
my $content = <$fh>;
|
||||
close $fh;
|
||||
return $content;
|
||||
@@ -52,12 +54,16 @@ show_version() if $version;
|
||||
|
||||
my $input_file = shift @ARGV;
|
||||
|
||||
binmode STDIN, ':encoding(UTF-8)';
|
||||
binmode STDOUT, ':encoding(UTF-8)';
|
||||
|
||||
my $input = read_input($input_file);
|
||||
|
||||
my $output;
|
||||
if ($output_file) {
|
||||
open $output, '>', $output_file
|
||||
or die "Error: Cannot write to file: $output_file\n";
|
||||
binmode $output, ':encoding(UTF-8)';
|
||||
}
|
||||
else {
|
||||
$output = \*STDOUT;
|
||||
|
||||
Reference in New Issue
Block a user