URI: 
       tFix markdown parser discarding exclamation marks; change missing linked files to warning instead of error - lsg - Lumidify Site Generator
  HTML git clone git://lumidify.org/lsg.git (fast, but not encrypted)
  HTML git clone https://lumidify.org/git/lsg.git (encrypted, but very slow)
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 0c7c2a7e4984ac072327b52ec90efd2330232d46
   DIR parent 93b7ac9391f1fdcd4ffec59f950cf2403d8e0a67
  HTML 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:
         M LSG/Config.pm                       |       5 ++++-
         M LSG/Generate.pm                     |       4 +++-
         M LSG/Markdown.pm                     |      14 +++++++++++---
         M LSG/Metadata.pm                     |       3 +++
         M LSG/Misc.pm                         |       3 +++
         M LSG/Template.pm                     |       3 +++
         M LSG/UserFuncs.pm                    |       3 +++
         M lsg.pl                              |       2 +-
       
       8 files changed, 31 insertions(+), 6 deletions(-)
       ---
   DIR diff --git a/LSG/Config.pm b/LSG/Config.pm
       t@@ -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);
       t@@ -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";
   DIR diff --git a/LSG/Generate.pm b/LSG/Generate.pm
       t@@ -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);
   DIR diff --git a/LSG/Markdown.pm b/LSG/Markdown.pm
       t@@ -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;
       t@@ -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
       t@@ -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)";
       t@@ -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;
       t@@ -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) {
   DIR diff --git a/LSG/Metadata.pm b/LSG/Metadata.pm
       t@@ -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;
   DIR diff --git a/LSG/Misc.pm b/LSG/Misc.pm
       t@@ -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!
   DIR diff --git a/LSG/Template.pm b/LSG/Template.pm
       t@@ -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);
   DIR diff --git a/LSG/UserFuncs.pm b/LSG/UserFuncs.pm
       t@@ -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;
        
   DIR diff --git a/lsg.pl b/lsg.pl
       t@@ -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