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