commit 0c7c2a7e4984ac072327b52ec90efd2330232d46
parent 93b7ac9391f1fdcd4ffec59f950cf2403d8e0a67
Author: lumidify <nobody@lumidify.org>
Date: Sat, 25 Feb 2023 23:33:17 +0100
Fix markdown parser discarding exclamation marks; change missing linked files to warning instead of error
Diffstat:
8 files changed, 31 insertions(+), 6 deletions(-)
diff --git a/LSG/Config.pm b/LSG/Config.pm
@@ -17,6 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use Exporter qw(import);
our @EXPORT_OK = qw($config);
@@ -28,7 +31,7 @@ sub read_modified_dates {
my $path = shift;
my %dates = (pages => {}, templates => {});
if (!-f $path) {
- print(STDERR "Unable to open \"$path\". Using empty modified_dates.\n");
+ warn "Unable to open \"$path\". Using empty modified_dates.\n";
return \%dates;
}
open (my $fh, "<", $path) or die "Unable to open $path: $!\n";
diff --git a/LSG/Generate.pm b/LSG/Generate.pm
@@ -17,7 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
-binmode(STDOUT, ":utf8");
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use Cwd;
use File::Spec::Functions qw(catfile);
use File::Path qw(make_path);
diff --git a/LSG/Markdown.pm b/LSG/Markdown.pm
@@ -17,6 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use File::Spec::Functions;
use Text::Markdown qw(markdown);
use LSG::Misc;
@@ -71,7 +74,7 @@ sub handle_lnk {
$url = $lnk;
}
if ($lnk_path && !(-f $lnk_path)) {
- die "ERROR: $file: linked file $lnk_path does not exist:\n$line\n";
+ warn "WARNING: $file: linked file $lnk_path does not exist:\n$line\n";
}
# Note: This is a huge hack and will probably break something.
# This should actually return markdown, but it has to return HTML
@@ -103,7 +106,7 @@ sub handle_img {
$src = $img;
}
if ($img_path && !(-f $img_path)) {
- die "ERROR: $file: image file $img_path does not exist:\n$line\n";
+ warn "WARNING: $file: image file $img_path does not exist:\n$line\n";
}
return "![$txt]($src)";
@@ -136,6 +139,8 @@ sub finish_child {
return $parent;
}
+# FIXME: This whole "parser" is extremely primitive and will break on a lot of input.
+# The whole thing should be replaced with something proper sometime.
sub parse_md {
my $lang = shift;
my $pageid = shift;
@@ -193,7 +198,10 @@ sub parse_md {
pop(@states);
$cur_child_ref = finish_child($cur_child_ref, $pageid, $lang, $_, $inpath);
} else {
- if ($states[-1] & $IN_IMG_START) {pop(@states)}
+ if ($states[-1] & $IN_IMG_START) {
+ pop(@states);
+ $char = "!" . $char;
+ }
if ($states[-1] & $IN_TXT) {
$cur_child_ref->{"txt"} .= $char;
} elsif ($states[-1] & $IN_URL) {
diff --git a/LSG/Metadata.pm b/LSG/Metadata.pm
@@ -17,6 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use File::Find;
use File::Spec::Functions qw(catfile catdir splitdir);
use File::Path;
diff --git a/LSG/Misc.pm b/LSG/Misc.pm
@@ -17,6 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
# Generate relative link - both paths must already be relative,
# starting at the same place!
diff --git a/LSG/Template.pm b/LSG/Template.pm
@@ -17,6 +17,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use File::Spec::Functions qw(catfile);
use Storable 'dclone';
use LSG::Config qw($config);
diff --git a/LSG/UserFuncs.pm b/LSG/UserFuncs.pm
@@ -19,6 +19,9 @@ use strict;
use warnings;
use utf8;
use open qw< :encoding(UTF-8) >;
+binmode STDIN, ":encoding(UTF-8)";
+binmode STDOUT, ":encoding(UTF-8)";
+binmode STDERR, ":encoding(UTF-8)";
use LSG::Config qw($config);
use LSG::Misc;
diff --git a/lsg.pl b/lsg.pl
@@ -262,7 +262,7 @@ Text::Markdown
=head1 LICENSE
-Written in 2017-2021 by lumidify <nobody[at]lumidify.org>
+Written in 2017-2023 by lumidify <nobody[at]lumidify.org>
To the extent possible under law, the author has dedicated
all copyright and related and neighboring rights to this