0
Code source to syntax highlighted html using pygments
One script reply has been approved by the moderators Verified
Created by rubenfiszel 668 days ago Viewed 9127 times
0
Submitted by rubenfiszel Python3
Verified 668 days ago
1
from pygments import highlight
2
from pygments.lexers import guess_lexer
3
from pygments.formatters import HtmlFormatter
4

5

6
def main(code: str = "export function main() { console.log(\"Hello\") }"):
7
    lexer = guess_lexer(code)
8
    print(f"Detected lang: {lexer.name}")
9
    html_gen = highlight(code, lexer, HtmlFormatter())
10
    
11
    return {"html": html_gen}
12