Adding Your Theme
00:00
In your app.py
profile, in the code function inside of the context dictionary, create a new key-value pair with the key style_definitions
and formatter.
get_style_defs()
as a value.
00:14
By calling formatter.get_style_defs()
, you will get all the styling that the dracula theme has. And now you can use the style_definitions
variable in your base HTML template to wrap those styles and attach them to your code box. Inside of <body>
, create a new tag named <style>
and inside the style block, add your style_definitions
variable in curly braces.
00:40
So Flask dumps all this content that Pygments has in stock for you inside the style block. And once you save base.html
and reload the browser, you will see that the code now has a nice syntax highlighting.
00:53 That’s a pretty big step. However, if you look closely, the parentheses are not really visible.
01:01 And if you remember the dracula theme from before, it was actually a dark theme. So something is still missing in our CSS code for our code image generator.
Become a Member to join the conversation.