@@ -25,6 +25,20 @@ def get_detection_line(scan_type: str, detection: 'Detection') -> int:
2525 )
2626
2727
28+ def _get_syntax_highlighted_code (code : str , lexer : str , start_line : int , detection_line : int ) -> Syntax :
29+ return Syntax (
30+ theme = _SYNTAX_HIGHLIGHT_THEME ,
31+ code = code ,
32+ lexer = lexer ,
33+ line_numbers = True ,
34+ word_wrap = True ,
35+ dedent = True ,
36+ tab_size = 2 ,
37+ start_line = start_line + 1 ,
38+ highlight_lines = {detection_line + 1 },
39+ )
40+
41+
2842def _get_code_snippet_syntax_from_file (
2943 scan_type : str ,
3044 detection : 'Detection' ,
@@ -58,18 +72,11 @@ def _get_code_snippet_syntax_from_file(
5872 code_lines_to_render .append (line_content )
5973
6074 code_to_render = '\n ' .join (code_lines_to_render )
61- return Syntax (
62- theme = _SYNTAX_HIGHLIGHT_THEME ,
75+ return _get_syntax_highlighted_code (
6376 code = code_to_render ,
6477 lexer = Syntax .guess_lexer (document .path , code = code_to_render ),
65- line_numbers = True ,
66- word_wrap = True ,
67- dedent = True ,
68- tab_size = 2 ,
69- start_line = start_line_index + 1 ,
70- highlight_lines = {
71- detection_line + 1 ,
72- },
78+ start_line = start_line_index ,
79+ detection_line = detection_line ,
7380 )
7481
7582
@@ -87,15 +94,11 @@ def _get_code_snippet_syntax_from_git_diff(
8794 violation = line_content [detection_position_in_line : detection_position_in_line + violation_length ]
8895 line_content = line_content .replace (violation , obfuscate_text (violation ))
8996
90- return Syntax (
91- theme = _SYNTAX_HIGHLIGHT_THEME ,
97+ return _get_syntax_highlighted_code (
9298 code = line_content ,
9399 lexer = 'diff' ,
94- line_numbers = True ,
95100 start_line = detection_line ,
96- dedent = True ,
97- tab_size = 2 ,
98- highlight_lines = {detection_line + 1 },
101+ detection_line = detection_line ,
99102 )
100103
101104
0 commit comments