|
@@ -18,9 +18,11 @@ sub render_readme($$) {
|
|
|
# Main parsing logic, doing it line by line
|
|
|
# I have some ideas on how to make this more robust/efficient,
|
|
|
# but starting with below for POC
|
|
|
- foreach my $line ( split("\n", $readme_content) ) {
|
|
|
+ my @readme_lines = split("\n", $readme_content);
|
|
|
+ my $inside_code = 0;
|
|
|
+ foreach my $line ( @readme_lines ) {
|
|
|
# HEADERS
|
|
|
- if ( $line =~ m/^#{1}(?!#)(.*)#$|^#{1}(?!#)(.*)$/ ) {
|
|
|
+ if ( $line =~ m/^#{1}(?!#)(.*)#$|^#{1}(?!#)(.*)$/ && $inside_code == 0 ) {
|
|
|
my $parsed_line;
|
|
|
if ( ! defined $1 || $1 eq "" ) {
|
|
|
$parsed_line = "<h1>$2</h1>";
|
|
@@ -28,7 +30,7 @@ sub render_readme($$) {
|
|
|
$parsed_line = "<h1>$1</h1>";
|
|
|
}
|
|
|
print $fh "$parsed_line";
|
|
|
- } elsif ( $line =~ m/^#{2}(?!#)(.*)#{2}$|^#{2}(?!#)(.*)$/ ) {
|
|
|
+ } elsif ( $line =~ m/^#{2}(?!#)(.*)#{2}$|^#{2}(?!#)(.*)$/ && $inside_code == 0) {
|
|
|
my $parsed_line;
|
|
|
if ( ! defined $1 || $1 eq "" ) {
|
|
|
$parsed_line = "<h2>$2</h2>";
|
|
@@ -36,7 +38,7 @@ sub render_readme($$) {
|
|
|
$parsed_line = "<h2>$1</h2>";
|
|
|
}
|
|
|
print $fh "$parsed_line";
|
|
|
- } elsif ( $line =~ m/^#{3}(?!#)(.*)#{3}$|^#{3}(?!#)(.*)$/ ) {
|
|
|
+ } elsif ( $line =~ m/^#{3}(?!#)(.*)#{3}$|^#{3}(?!#)(.*)$/ && $inside_code == 0) {
|
|
|
my $parsed_line;
|
|
|
if ( ! defined $1 || $1 eq "" ) {
|
|
|
$parsed_line = "<h3>$2</h3>";
|
|
@@ -44,7 +46,7 @@ sub render_readme($$) {
|
|
|
$parsed_line = "<h3>$1</h3>";
|
|
|
}
|
|
|
print $fh "$parsed_line";
|
|
|
- } elsif ( $line =~ m/^#{4}(?!#)(.*)#{4}$|^#{4}(?!#)(.*)$/ ) {
|
|
|
+ } elsif ( $line =~ m/^#{4}(?!#)(.*)#{4}$|^#{4}(?!#)(.*)$/ && $inside_code == 0) {
|
|
|
my $parsed_line;
|
|
|
if ( ! defined $1 || $1 eq "" ) {
|
|
|
$parsed_line = "<h4>$2</h4>";
|
|
@@ -52,7 +54,7 @@ sub render_readme($$) {
|
|
|
$parsed_line = "<h4>$1</h4>";
|
|
|
}
|
|
|
print $fh "$parsed_line";
|
|
|
- } elsif ( $line =~ m/^#{5}(?!#)(.*)#{5}$|^#{5}(?!#)(.*)$/ ) {
|
|
|
+ } elsif ( $line =~ m/^#{5}(?!#)(.*)#{5}$|^#{5}(?!#)(.*)$/ && $inside_code == 0) {
|
|
|
my $parsed_line;
|
|
|
if ( ! defined $1 || $1 eq "" ) {
|
|
|
$parsed_line = "<h5>$2</h5>";
|
|
@@ -60,16 +62,25 @@ sub render_readme($$) {
|
|
|
$parsed_line = "<h5>$1</h5>";
|
|
|
}
|
|
|
print $fh "$parsed_line";
|
|
|
- } elsif ( $line =~ m/^\*(.*)/ ) {
|
|
|
+ } elsif ( $line =~ m/^\*(.*)/ && $inside_code == 0) {
|
|
|
my $parsed_line = "<ul><li>$1</li></ul>";
|
|
|
print $fh "$parsed_line";
|
|
|
+ } elsif ( $line =~ m/^```$/ ) {
|
|
|
+ if ( $inside_code == 0 ) {
|
|
|
+ $inside_code = 1;
|
|
|
+ print $fh "<br>";
|
|
|
+ } elsif ( $inside_code == 1 ) {
|
|
|
+ $inside_code = 0;
|
|
|
+ }
|
|
|
+ } elsif ( $inside_code == 1 ) {
|
|
|
+ print $fh "<code>$line</code><br>";
|
|
|
}
|
|
|
+
|
|
|
else {
|
|
|
- print $fh "$line</br>";
|
|
|
+ print $fh "$line<br>";
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- print $fh "</br><hr\>";
|
|
|
close $fh;
|
|
|
$logger->info("Parsed README");
|
|
|
return $html_readme;
|