|
|
|
from pygments import highlight as highlight_ |
|
from pygments.formatters import HtmlFormatter, TerminalFormatter |
|
from pygments.lexers import PythonLexer, SqlLexer |
|
|
|
|
|
def highlight(code: str, language: str = "python", formatter: str = "terminal"): |
|
|
|
if language.lower() == "python": |
|
lexer = PythonLexer() |
|
elif language.lower() == "sql": |
|
lexer = SqlLexer() |
|
else: |
|
raise ValueError(f"Unsupported language: {language}") |
|
|
|
|
|
if formatter.lower() == "terminal": |
|
formatter = TerminalFormatter() |
|
elif formatter.lower() == "html": |
|
formatter = HtmlFormatter() |
|
else: |
|
raise ValueError(f"Unsupported formatter: {formatter}") |
|
|
|
|
|
return highlight_(code, lexer, formatter) |
|
|