Skip to content

Commit

Permalink
Improve code that sets custom CSS for dark themes
Browse files Browse the repository at this point in the history
- Enable it for Qt WebEngine too.
- Include style for background color and links.
- Disable it for export to HTML (webenv == True).

See #255 and #492 for discussion related to dark themes.
  • Loading branch information
mitya57 committed Mar 2, 2021
1 parent 0ddd13f commit 5343c00
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions ReText/tab.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,18 @@ def getHtmlFromConverted(self, converted, includeStyleSheet=True, webenv=False):
style += 'table { border-collapse: collapse; }\n'
style += 'img { max-width: 100%; }\n'
# QTextDocument seems to use media=screen even for printing
if globalSettings.useWebKit:
if not isinstance(self.previewBox, QTextEdit) and not webenv:
# https://github.com/retext-project/retext/pull/187
palette = QApplication.palette()
style += '@media screen { html { color: %s; } }\n' % palette.color(QPalette.ColorRole.WindowText).name()
fgColor = palette.color(QPalette.ColorRole.WindowText).name()
bgColor = palette.color(QPalette.ColorRole.Window).name()
linkColor = palette.color(QPalette.ColorRole.Link).name()
visitedLinkColor = palette.color(QPalette.ColorRole.LinkVisited).name()
style += ('@media screen {\n'
f' html {{ color: {fgColor}; background-color: {bgColor}; }}\n'
f' a, a * {{ color: {linkColor}; }}\n'
f' a:visited, a:visited * {{ color: {visitedLinkColor}; }}\n'
'}\n')
# https://github.com/retext-project/retext/issues/408
style += '@media print { html { background-color: white; } }\n'
headers += '<style type="text/css">\n' + style + '</style>\n'
Expand Down

0 comments on commit 5343c00

Please sign in to comment.