https://stackoverflow.com/a/36593115/2995591
--- gitweb.cgi-orig 2018-11-19 17:16:36.000000000 +0100
+++ gitweb.cgi 2019-08-03 16:50:41.404605436 +0200
@@ -16,8 +16,9 @@ use CGI::Carp qw(fatalsToBrowser set_mes
use Encode;
use Fcntl ':mode';
use File::Find qw();
-use File::Basename qw(basename);
+use File::Basename qw(basename dirname);
use Time::HiRes qw(gettimeofday tv_interval);
+use File::Spec; # hack
binmode STDOUT, ':utf8';
our $t0 = [ gettimeofday() ];
@@ -6507,6 +6508,20 @@ sub git_summary {
print "\n\n"; # class="readme"
}
+ # hack
+ if (!$prevent_xss) {
+ $file_name = "README.md";
+ my $proj_head_hash = git_get_head_hash($project);
+ my $readme_blob_hash = git_get_hash_by_path($proj_head_hash, "README.md", "blob");
+
+ if ($readme_blob_hash) { # if README.md exists
+ print "
\n";
+ print ""; # TODO find/create a better CSS class than page_body
+ print get_markdown($file_name, $readme_blob_hash);
+ print "
";
+ }
+ }
+
# we need to request one more than 16 (0..15) to check if
# those 16 are all
my @commitlist = $head ? parse_commits($head, 17) : ();
@@ -6980,6 +6995,9 @@ sub git_blob {
$fd = run_highlighter($fd, $highlight, $syntax)
if $syntax;
+ # hack
+ my $ismarkdown = ($file_name =~ /md$/);
+
git_header_html(undef, $expires);
my $formats_nav = '';
if (defined $hash_base && (my %co = parse_commit($hash_base))) {
@@ -7023,6 +7041,10 @@ sub git_blob {
href(action=>"blob_plain", hash=>$hash,
hash_base=>$hash_base, file_name=>$file_name) .
qq!" />\n!;
+ } elsif ($ismarkdown) {
+ print qq!\n!;
+ print get_markdown($file_name, $hash);
+ print qq!
\n!; # $cmd_markdownify
} else {
my $nr;
while (my $line = <$fd>) {
@@ -7040,6 +7062,79 @@ sub git_blob {
git_footer_html();
}
+# hack
+sub get_norm_rel_path { # http://www.perlmonks.org/bare/?node_id=11907
+ my $unnormpath = shift;
+ while ($unnormpath =~ m!/\.!) {
+ $unnormpath =~ s!/[^\/]+/\.\.!!;
+ # print "Path is now -+$unnormpath+-\n";
+ }
+ return $unnormpath;
+}
+sub get_markdown {
+ my $tfilename = shift;
+ my $thash = shift;
+ my $rethtmlstr = "";
+ use open ":encoding(utf8)"; # needed to have utf8 survive through the shell pipe
+ my $cmd_markdownify = $GIT . " " . git_cmd() . " cat-file blob " . $thash . " | perl -e 'my \$str = do { local \$/; }; \$str =~ s/