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.
This commit is contained in:
parent
fe4f739eb3
commit
0dcc44870e
|
|
@ -97,8 +97,7 @@ def highlight_code(language_name, code):
|
||||||
lexer = get_lexer_by_name('bash')
|
lexer = get_lexer_by_name('bash')
|
||||||
else:
|
else:
|
||||||
# If no language is specified, guess the lexer
|
# If no language is specified, guess the lexer
|
||||||
print("LEXER NAME " + lexer_name)
|
lexer = guess_lexer('\n'.join(code.split('\n')[1:-1]))
|
||||||
lexer = guess_lexer(code.split('\n')[1:-1])
|
|
||||||
if not lexer:
|
if not lexer:
|
||||||
# If no lexer is guessed, default to bash
|
# If no lexer is guessed, default to bash
|
||||||
lexer = get_lexer_by_name('bash')
|
lexer = get_lexer_by_name('bash')
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue