Gitweb:如何像github一样自动以html格式显示markdown文件 [英] Gitweb: how to display markdown file in html format automatically like github

查看:282
本文介绍了Gitweb:如何像github一样自动以html格式显示markdown文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Markdown对于文档很重要,很高兴看到README.md可以自动以html格式显示在github中,例如

Markdown is important for documentation, it is very nice to see README.md can be automatically show in html format in github like https://github.com/twitter/bootstrap/blob/master/README.md

gitweb是用perl脚本编写的,并且perl中已经有用于markdown的插件.

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

我想检查是否有插件/解决方案让gitweb自动显示markdown格式的html文件.

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

推荐答案

在这里,您可以在gitweb.perlgitweb.cgi中的sub git_summary下粘贴一些内容.请注意,它取决于外部markdown可执行文件.

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 = "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 "<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 $_;
        }
        close(FOO);

        print "</div>";
    }
}

我不太了解Perl,所以这比其他任何东西都更肮脏,但它确实有效.

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

这篇关于Gitweb:如何像github一样自动以html格式显示markdown文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆