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

💄 Dark and Light Image Variants #2225

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions guide/src/format/images/rust-logo-blk-dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions guide/src/format/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,21 @@ Which, of course displays the image like so:

![The Rust Logo](images/rust-logo-blk.svg)


## Light and Dark Image Variants

Separate light mode and dark mode images may be presented to the viewer by adding `#light-only` or `#dark-only` to an image path:

```markdown
![rust logo standard edition](images/rust-logo-blk.svg#only-light)
![rust logo dark mode](images/rust-logo-blk-dark.svg#only-dark)
```

Try switching the theme to see the effect below (brush icon at the top left of the page):

![rust logo standard edition](images/rust-logo-blk.svg#only-light)
![rust logo dark mode](images/rust-logo-blk-dark.svg#only-dark)

## Extensions

mdBook has several extensions beyond the standard CommonMark specification.
Expand Down
10 changes: 10 additions & 0 deletions src/theme/css/general.css
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ table tbody tr:nth-child(2n) {
background: var(--table-alternate-bg);
}

.light img[src$="#only-dark"],
.rust img[src$="#only-dark"] {
display:none;
}

.navy img[src$="#only-light"],
.ayu img[src$="#only-light"],
.coal img[src$="#only-light"] {
display:none;
}

blockquote {
margin: 20px 0;
Expand Down