feat: add explicit UTF-8 handling
This commit is contained in:
10
m2h.pl
10
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;
|
||||||
@@ -38,7 +40,7 @@ sub read_input {
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $output_file;
|
my $output_file;
|
||||||
my $help = 0;
|
my $help = 0;
|
||||||
my $version = 0;
|
my $version = 0;
|
||||||
|
|
||||||
GetOptions(
|
GetOptions(
|
||||||
@@ -47,17 +49,21 @@ GetOptions(
|
|||||||
'output|o=s' => \$output_file,
|
'output|o=s' => \$output_file,
|
||||||
) or show_help();
|
) or show_help();
|
||||||
|
|
||||||
show_help() if $help;
|
show_help() if $help;
|
||||||
show_version() if $version;
|
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