Gitweb: how to display markdown file in html format automatically like github

Markdown is important for documentation, it is very nice to see can be automatically show in html format in github like

gitweb is written in perl script, and there is plugin for markdown in perl already.

I want to check whether there is plugin/solution to let gitweb automatically show html files for markdown format.


Here's something you can stick somewhere under sub git_summary in your gitweb.perl or gitweb.cgi. Note that it depends on an external markdown executable.

if (!$prevent_xss) {
    $file_name = "";
    my $proj_head_hash = git_get_head_hash($project);
    my $readme_blob_hash = git_get_hash_by_path($proj_head_hash, "", "blob");

    if ($readme_blob_hash) { # if exists                                                                                                                                                      
        print "<div class=\"header\">readme</div>\n";
        print "<div class=\"readme page_body\">"; # TODO find/create a better CSS class than page_body                                                                                                  

        my $cmd_markdownify = $GIT . " " . git_cmd() . " cat-file blob " . $readme_blob_hash . " | markdown |";
        open FOO, $cmd_markdownify or die_error(500, "Open git-cat-file blob '$hash' failed");
        while (<FOO>) {
            print $_;

        print "</div>";

I don't really know Perl, so this is a dirty hack more than anything else, but it works.

I use following post-receive hook in my remote repositories which are made browsable with gitweb.

# Post-receive hook script which generates README.html to git-dir from
# found at the head of master branch in repository.
# Gitweb can read the README.html and embed it to the project summary page.

git cat-file blob | markdown > $GIT_DIR/README.html

That script is run when I push commits from my local work repositories to the remote bare ones. You could use that or something similar depending on your workflow/setup.

More information about git hooks:

Need Your Help

gitignore globbing or RE?

git version-control project-management gitignore

I have a little trouble with some auto generated binary files in my project.

Could i increase speed of executing statements?

sql-server performance visual-studio-2010 sql-update

My function: Removes the unit in a specific row of a given Table

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.