0
Code source to syntax highlighted svg using pygments
One script reply has been approved by the moderators Verified
Created by rubenfiszel 669 days ago Viewed 9121 times
0
Submitted by rubenfiszel Python3
Verified 669 days ago
1
from pygments import highlight
2
from pygments.lexers import guess_lexer
3
from pygments.formatters import SvgFormatter
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
    svg_gen = highlight(code, lexer, SvgFormatter())
10
    
11
    return {"svg": svg_gen}
12