Browse Source

Worked around diff html issue via xmp HTML tags. Probably a better way to do this

spesk1 4 years ago
parent
commit
4678ce1b68
2 changed files with 10 additions and 6 deletions
  1. 0 1
      README.md
  2. 10 5
      lib/Gsg/Html.pm

+ 0 - 1
README.md

@@ -20,7 +20,6 @@ TODO:
 * Show git:// address for cloning (configurable via config file)
 * Code needs to be more robust / handle failure cases
 * Need to recurse git home, right now will only pull dirs in root of git home
-* Fix issue with diff highlight where if the diff contains HTML it gets rendered in the browser (isolate/sanitize it somehow)
 * README.md markdown renderer/parser / display in project index
 * (Stretch Goal) HTML based syntax highlighting for files
 * Support detection of misconfig of config file

+ 10 - 5
lib/Gsg/Html.pm

@@ -86,17 +86,22 @@ sub gen_diff_colors($$) {
 	my $html_diff;
 	open my $fh, '>>', \$html_diff or die "Can't open variable: $!";
 
-	print $fh "<!DOCTYPE html><html><div id=\"content\"><pre id=\"blob\">";
+	#print $fh "<!DOCTYPE html><html><div id=\"content\"><pre id=\"blob\">";
+	print $fh "<!DOCTYPE html><html><div id=\"content\"><pre>";
 	my $line_counter = 1;
 	foreach my $line ( split("\n", $raw_diff) ) {
 		if ( $line =~ m/^\+/ ) {
-			print $fh "<a href=\"\#l$line_counter\" class=\"line\" id=\"l$line_counter\">$line_counter</a><font color=\"green\">\t$line</font></br>";
+			print $fh "<font color=\"green\"><xmp>$line</xmp></font>";
 		} elsif ( $line =~ m/^\-/ ) {
-			print $fh "<a href=\"\#l$line_counter\" class=\"line\" id=\"l$line_counter\">$line_counter</a><font color=\"red\">\t$line</font></br>";
+			print $fh "<font color=\"red\"><xmp>$line</xmp></font>";
 		} elsif ( $line =~ m/^@@/ ) {
-			print $fh "<a href=\"\#l$line_counter\" class=\"line\" id=\"l$line_counter\">$line_counter</a><font color=\"blue\">\t$line</font></br>";
+			print $fh "<font color=\"blue\"><xmp>$line</xmp></font>";
+		} elsif ( $line =~ m/^diff/ ) {
+			print $fh "<font color=\"purple\"><xmp>$line</xmp></font>";
+		} elsif ( $line =~ m/^commit/ ) {
+			print $fh "<font color=\"purple\"><b><xmp>$line</xmp></b></font>";
 		} else {
-			print $fh "<a href=\"\#l$line_counter\" class=\"line\" id=\"l$line_counter\">$line_counter</a>\t$line</br>";
+			print $fh "<xmp>$line</xmp>";
 		}
 		$line_counter++;
 	}