9130b2f18c42137557400d69d11a1f2f5f894da9
commit 9130b2f18c42137557400d69d11a1f2f5f894da9
Author: spesk1 <spesk@pm.me>
Date: Mon Jun 24 01:44:47 2019 +0000

Added link parsing to md parser

diff --git a/README.md b/README.md
index 674b5b9..64e2b8c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,5 @@
# git-site-gen #
+### AKA gsg
* Tool used to generate a bare bones, pure HTML static website from information availble in a git project dir. See: https://spwbk.site/git.
* Inspired by the much better/full-featured cgit.
* Not sure if this will be widely useful, mostly written for learning purposes.
diff --git a/lib/Gsg/MdParse.pm b/lib/Gsg/MdParse.pm
index 9a2333c..bedcca7 100644
--- a/lib/Gsg/MdParse.pm
+++ b/lib/Gsg/MdParse.pm
@@ -5,6 +5,20 @@ use Log::Log4perl qw(:easy);
use Exporter qw(import);
our @EXPORT_OK = qw(render_readme);

+sub link_line($) {
+
+ my $line = shift;
+ if ( $line =~ m/(http.*)/ ) {
+ my $link = $1;
+ my $link_replace = "<a href=\"$link\">$link</a>";
+ $line =~ s/\Q$1\E/$link_replace/g;
+ return $line;
+ }
+
+ return $line;
+
+}
+
# README content is passed in as a var, sub returned an HTML version of the parsed markdown
sub render_readme($$) {

@@ -63,7 +77,8 @@ sub render_readme($$) {
}
print $fh "$parsed_line";
} elsif ( $line =~ m/^\*(.*)/ && $inside_code == 0) {
- my $parsed_line = "<ul><li>$1</li></ul>";
+ $line = link_line($1);
+ my $parsed_line = "<ul><li>$line</li></ul>";
print $fh "$parsed_line";
} elsif ( $line =~ m/^```$/ ) {
if ( $inside_code == 0 ) {
@@ -74,13 +89,16 @@ sub render_readme($$) {
}
} elsif ( $inside_code == 1 ) {
print $fh "<code>$line</code><br>";
+ } elsif ( $line =~ m/(http.*)/ ) {
+ $line = link_line($line);
+ print $fh "$line<br>";
}
-
else {
print $fh "$line<br>";
}
}

+ print $fh "<br>";
close $fh;
$logger->info("Parsed README");
return $html_readme;