gitweb: Refactor syntax highlighting support
This refactoring (adding guess_file_syntax and run_highlighter subroutines) is meant to make it easier in the future to add support for other syntax highlighing solutions, or make it smarter by not re-running `git cat-file` second time. Instead of looping over list of regexps (keys of %highlight_type hash), make use of the fact that choosing syntax is based either on full basename (%highlight_basename), or on file extension (%highlight_ext). Add some basic test of syntax highlighting (with 'highlight' as prerequisite) to t/t9500-gitweb-standalone-no-errors.sh test. While at it make git_blob Perl style prettier. Signed-off-by: Jakub Narebski <jnareb@gmail.com> Acked-by: Petr Baudis <pasky@suse.cz> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b331fe5476
commit
592ea4173a
@ -647,4 +647,33 @@ test_expect_success \
|
||||
gitweb_run "p=.git;a=summary"'
|
||||
test_debug 'cat gitweb.log'
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# syntax highlighting
|
||||
|
||||
cat >>gitweb_config.perl <<\EOF
|
||||
$feature{'highlight'}{'override'} = 1;
|
||||
EOF
|
||||
|
||||
highlight --version >/dev/null 2>&1
|
||||
if [ $? -eq 127 ]; then
|
||||
say "Skipping syntax highlighting test, because 'highlight' was not found"
|
||||
else
|
||||
test_set_prereq HIGHLIGHT
|
||||
fi
|
||||
|
||||
test_expect_success HIGHLIGHT \
|
||||
'syntax highlighting (no highlight)' \
|
||||
'git config gitweb.highlight yes &&
|
||||
gitweb_run "p=.git;a=blob;f=file"'
|
||||
test_debug 'cat gitweb.log'
|
||||
|
||||
test_expect_success HIGHLIGHT \
|
||||
'syntax highlighting (highlighted)' \
|
||||
'git config gitweb.highlight yes &&
|
||||
echo "#!/usr/bin/sh" > test.sh &&
|
||||
git add test.sh &&
|
||||
git commit -m "Add test.sh" &&
|
||||
gitweb_run "p=.git;a=blob;f=test.sh"'
|
||||
test_debug 'cat gitweb.log'
|
||||
|
||||
test_done
|
||||
|
Reference in New Issue
Block a user