Gitweb:如何像github一样自动以html格式显示markdown文件

Lar*_*Cai 7 perl markdown gitweb

Markdown对于文档很重要,很高兴看到README.md可以在github中以html格式自动显示,如https://github.com/twitter/bootstrap/blob/master/README.md

gitweb是用perl脚本编写的,perl中有markdown插件.

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

小智 11

我在我的远程存储库中使用以下post-receive hook,它可以使用gitweb进行浏览.

#!/bin/sh
#
# Post-receive hook script which generates README.html to git-dir from
# README.md 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 HEAD:README.md | markdown > $GIT_DIR/README.html
Run Code Online (Sandbox Code Playgroud)

当我将提交从我的本地工作存储库推送到远程裸存储库时,该脚本就会运行.根据您的工作流程/设置,您可以使用它或类似的东西.

有关git hooks的更多信息:http://book.git-scm.com/5_git_hooks.html


eri*_*sei 7

这是你可以sub git_summary在你gitweb.perl或你的某个地方坚持的东西gitweb.cgi.请注意,它取决于外部markdown可执行文件.

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>";
    }
}
Run Code Online (Sandbox Code Playgroud)

我真的不知道Perl,所以这是一个肮脏的黑客,但它确实有效.