|
12 | 12 | from markdown import Markdown
|
13 | 13 | from pygments import lex
|
14 | 14 | from pygments.lexers.markup import MarkdownLexer
|
| 15 | +from pygments.formatters.html import HtmlFormatter |
15 | 16 | from pygments.token import Generic
|
16 | 17 | from pygments.lexer import bygroups
|
17 | 18 | from pygments.styles import get_style_by_name, get_all_styles
|
@@ -389,10 +390,15 @@ def load_style(self, stylename):
|
389 | 390 | )
|
390 | 391 | # self.export_options_text_area.tag_configure(str(Generic.StrongEmph), font=('Monospace', 10, 'bold', 'italic'))
|
391 | 392 | self.syntax_highlighting_tags.append(str(Generic.StrongEmph))
|
392 |
| - self.css = 'body {background-color: %s; color: %s}' % ( |
393 |
| - self.style.background_color or 'white', |
394 |
| - self.text_area.tag_cget("Token.Text", "foreground") or 'black', |
395 |
| - )# used string%interpolation here because f'string' interpolation is too annoying with embeded { and } |
| 393 | + self.formatter = HtmlFormatter() |
| 394 | + self.pygments = self.formatter.get_style_defs(".highlight") |
| 395 | + # Previous version. |
| 396 | + self.css = 'body {background-color: %s; color: %s }\nbody .highlight{ background-color: %s; }\n%s' % ( |
| 397 | + self.style.background_color, |
| 398 | + self.text_area.tag_cget("Token.Text", "foreground"), |
| 399 | + self.style.background_color, |
| 400 | + self.pygments |
| 401 | + )#used string%interpolation here because f'string' interpolation is too annoying with embeded { and } |
396 | 402 | self.preview_document.add_css(self.css)
|
397 | 403 | return self.syntax_highlighting_tags
|
398 | 404 |
|
|
0 commit comments