]> Lady’s Gitweb - Gitweb/commitdiff
gitweb: highlight: replace tabs with spaces
authorKevin Cernekee <redacted>
Wed, 16 Mar 2011 22:34:13 +0000 (15:34 -0700)
committerLady <redacted>
Mon, 6 Apr 2026 04:51:30 +0000 (00:51 -0400)
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 <redacted>
Acked-by: John 'Warthog9' Hawley <redacted>
Signed-off-by: Junio C Hamano <redacted>
gitweb.perl

index ccb06cdc140a3d9a6f5e5da41da5a23d95ebf20cd55ca0c51acaf8ec7476e9c1..9781338de7151def013971f6ee2b2ba1c0eaa70205eaf833991720237c8f5cec 100755 (executable)
@@ -3469,7 +3469,7 @@ sub run_highlighter {
        close $fd;
        open $fd, quote_command(git_cmd(), "cat-file", "blob", $hash)." | ".
                  quote_command($highlight_bin).
        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;
 }
                or die_error(500, "Couldn't open file or run syntax highlighter");
        return $fd;
 }
This page took 0.260019 seconds and 4 git commands to generate.