git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] gitweb: highlight: replace tabs with spaces

From
Kevin Cernekee <cernekee@gmail.com>
Date
Mar 16, 2011, 22:34 UTC
Message-ID
<6ac7d48cfdf4192c3240c1ecbd4e5522@localhost>
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>
---
 gitweb/gitweb.perl |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index d171ad5..649e10a 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -3485,7 +3485,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;
 }
-- 
1.7.4.1
Next: J.H.
Message 1 of 3 in “gitweb: highlight: replace tabs with spaces”
  1. gitweb: highlight: replace tabs with spacesKevin Cernekee, Mar 16, 2011
  2. J.H.Mar 16, 2011
  3. Jakub NarebskiMar 17, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.