如何将 Gitweb 默认 diff 格式更改为 `--color-words`?

发布于 2024-08-07 06:35:55 字数 122 浏览 3 评论 0原文

我希望 gitweb 输出与 git diff --color-words 相同的 diff 格式。有人知道我该怎么做吗?我查看了 HTML::FromANSI 但无法从命令行使用 git diff --color-words 。

I want gitweb to output the same diff format as git diff --color-words. Does anybody know how I can do this? I looked at HTML::FromANSI but couldn't get it working with git diff --color-words from the command line.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2024-08-14 06:35:56

您如何使用 HTML::FromANSI?因为它对我有用,所以使用以下命令按预期工作

git diff --color-words HEAD^ HEAD |
perl -wle '
use HTML::FromANSI; 
my @lines = <STDIN>; 
foreach my $line (@lines) {
    chomp $line;
    print ansi2html($line); 
}' > tmp.html

尽管如果您想要可用的输出,而不是黑色背景上几乎看不见的白色文本,您可能需要配置 HTML::FromANSI。上面的脚本只是概念验证代码(不是最佳风格)。


顺便说一句,我不确定 HTML::FromANSI 模块的质量;它没有强制为我安装(使用cpan)(但这可能是该模块需要的 Term::VT102::Boundless 的问题)。

ansi2html 子例程在某些行上存在问题(我认为带有嵌入/尾随行尾字符的行和空行/字符串),产生 Use of uninitialized value in concatenation (.) 或字符串位于 .../HTML/FromANSI.pm 第 353 行,NN 行。 警告。这就是为什么我必须chomp(这可能是您在使 HTML::FromANSI 工作时遇到的问题)

此外,该模块生成的 HTML 非常可怕,使用过时且已弃用的 标记以及现代的 < span style='...'> 标签;我也没有看到使用 CSS 代替内联样式的选项。

How did you use HTML::FromANSI? Because it works for me, using the following command worked as intended

git diff --color-words HEAD^ HEAD |
perl -wle '
use HTML::FromANSI; 
my @lines = <STDIN>; 
foreach my $line (@lines) {
    chomp $line;
    print ansi2html($line); 
}' > tmp.html

Although if you want usable output, and not barely visible white text on black background, you would probably need to configure HTML::FromANSI. The above scriptlet is just proof of concept code (ans not in best style).


BTW I am not sure about quality of HTML::FromANSI module; it didn't install (using cpan) for me without force (but it might be problem with Term::VT102::Boundless this module requires).

ansi2html subroutine have problems with some lines (I think lines with embedded / trailing end-of-line character, and empty line / string), producing Use of uninitialized value in concatenation (.) or string at .../HTML/FromANSI.pm line 353, <STDIN> line NN. warning. That's why I had to chomp lines (and that might be the problem you had with making HTML::FromANSI work).

Also the HTML produced by this module is quite horrid, using outdated and deprecated <font face='...' style ='...'> tag together with modern <span style='...'> tag; also I don't see an option to use CSS instead of inline style.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文