Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve support for print media #319

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/furo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ def get_pygments_stylesheet() -> str:

lines.extend(_get_styles(light_formatter, prefix=".highlight"))

lines.append("@media not print {")

dark_prefix = 'body[data-theme="dark"] .highlight'
lines.extend(_get_styles(dark_formatter, prefix=dark_prefix))

Expand All @@ -344,6 +346,8 @@ def get_pygments_stylesheet() -> str:
lines.extend(_get_styles(dark_formatter, prefix=not_light_prefix))
lines.append("}")

lines.append("}")

return "\n".join(lines)


Expand Down
1 change: 1 addition & 0 deletions src/furo/assets/styles/base/_index.sass
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@import "print"
@import "screen-readers"
@import "theme"
@import "typography"
29 changes: 29 additions & 0 deletions src/furo/assets/styles/base/_print.sass
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This file contains styles for managing print media.

////////////////////////////////////////////////////////////////////////////////
// Hide elements not relevant to print media.
////////////////////////////////////////////////////////////////////////////////
@media print
// Hide icon container.
.content-icon-container
display: none !important

// Hide showing header links if hovering over when printing.
.headerlink
display: none !important

// Hide mobile header.
.mobile-header
display: none !important

// Hide navigation links.
.related-pages
display: none !important

////////////////////////////////////////////////////////////////////////////////
// Tweaks related to decolorization.
////////////////////////////////////////////////////////////////////////////////
@media print
// Apply a border around code which no longer have a color background.
.highlight
border: 0.1pt solid var(--color-foreground-border)
26 changes: 14 additions & 12 deletions src/furo/assets/styles/base/_theme.sass
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,27 @@ body
html body .only-dark
display: none !important

// Enable dark-mode, if requested.
body[data-theme="dark"]
@include colors-dark

html & .only-light
display: none !important
.only-dark
display: block !important

// Enable dark mode, unless explicitly told to avoid.
@media (prefers-color-scheme: dark)
body:not([data-theme="light"])
// Ignore dark-mode hints if print media.
@media not print
// Enable dark-mode, if requested.
body[data-theme="dark"]
@include colors-dark

html & .only-light
display: none !important
.only-dark
display: block !important

// Enable dark mode, unless explicitly told to avoid.
@media (prefers-color-scheme: dark)
body:not([data-theme="light"])
@include colors-dark

html & .only-light
display: none !important
.only-dark
display: block !important

//
// Theme toggle presentation
//
Expand Down
12 changes: 7 additions & 5 deletions src/furo/theme/furo/partials/_head_css_variables.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@
body {
{{ declare_css_variables(theme_light_css_variables, furo_pygments.light) }}
}
body[data-theme="dark"] {
{{ declare_css_variables(theme_dark_css_variables, furo_pygments.dark) }}
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
@media not print {
body[data-theme="dark"] {
{{ declare_css_variables(theme_dark_css_variables, furo_pygments.dark) }}
}
@media (prefers-color-scheme: dark) {
body:not([data-theme="light"]) {
{{ declare_css_variables(theme_dark_css_variables, furo_pygments.dark) }}
}
}
}
</style>