From 0dcc44870e0980c5cd0a635f4b7859a7a5aa4dbf Mon Sep 17 00:00:00 2001 From: Hayden Johnson Date: Thu, 10 Apr 2025 20:33:18 -0700 Subject: [PATCH] Fix: Correctly guess lexer when no language is specified The `guess_lexer` function was not correctly handling code snippets when no language was specified. It was only considering the second line of the code, which could lead to incorrect lexer selection. This commit joins the lines of code (excluding the first and last) back into a single string before passing it to `guess_lexer`, ensuring the entire code block is considered for lexer identification. --- assistant.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/assistant.py b/assistant.py index ec41920..94bf203 100755 --- a/assistant.py +++ b/assistant.py @@ -97,8 +97,7 @@ def highlight_code(language_name, code): lexer = get_lexer_by_name('bash') else: # If no language is specified, guess the lexer - print("LEXER NAME " + lexer_name) - lexer = guess_lexer(code.split('\n')[1:-1]) + lexer = guess_lexer('\n'.join(code.split('\n')[1:-1])) if not lexer: # If no lexer is guessed, default to bash lexer = get_lexer_by_name('bash')