Created
August 31, 2020 17:17
-
-
Save akarsh1995/5a07ddb217dcab56c9fdb850e66dca25 to your computer and use it in GitHub Desktop.
Use this syntax highlighter to highlight syntax of almost any language.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pygments import highlight | |
| from pygments.lexers import PythonLexer | |
| from pygments.formatters import HtmlFormatter | |
| code = '''helloworld_string = 'Hello! World' | |
| print f"{helloworld_string}"''' | |
| template = '''<html> | |
| <head> | |
| <title>How to use Pygments</title> | |
| <style type="text/css"> | |
| {} | |
| </style> | |
| </head> | |
| <body> | |
| {} | |
| </body> | |
| </html> | |
| ''' | |
| if __name__ == '__main__': | |
| formatted_html = highlight(code, PythonLexer(), HtmlFormatter()) | |
| css_style = HtmlFormatter().get_style_defs('.highlight') | |
| print(template.format(css_style, formatted_html)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pygments |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment