gitweb: highlight: replace tabs with spaces
authorKevin Cernekee <cernekee@gmail.com>
Wed, 16 Mar 2011 22:34:13 +0000 (15:34 -0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 16 Mar 2011 23:18:58 +0000 (16:18 -0700)
Consider the following code fragment:

        /*
         * test
         */

vim ":set list" mode shows that the first character on each line is a
tab:

^I/*$
^I * test$
^I */$

By default, the "highlight" program will retain the tabs in the HTML
output:

$ highlight --fragment --syntax c test.c
        <span class="hl com">/*</span>
<span class="hl com">    * test</span>
<span class="hl com">    */</span>

vim list mode:

^I<span class="hl com">/*</span>$
<span class="hl com">^I * test</span>$
<span class="hl com">^I */</span>$

In gitweb, this winds up looking something like:

   1         /*
   2     * test
   3     */

I tried both Firefox and Opera and saw the same behavior.

The desired output is:

   1         /*
   2          * test
   3          */

This can be accomplished by specifying "--replace-tabs=8" on the
highlight command line.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
Acked-by: John 'Warthog9' Hawley <warthog9@eaglescrag.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gitweb/gitweb.perl

index 1b9369d1a72f625bcb66e021bdab8559930cb0eb..b04ab8c9bba5098e6fd1ebdf2a5d278be503fa41 100755 (executable)
@@ -3468,7 +3468,7 @@ sub run_highlighter {
        close $fd;
        open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
                  quote_command($highlight_bin).
-                 " --fragment --syntax $syntax |"
+                 " --replace-tabs=8 --fragment --syntax $syntax |"
                or die_error(500, "Couldn't open file or run syntax highlighter");
        return $fd;
 }