mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 07:37:19 +02:00
feat(mdx-loader): preserve hash in image src; support GH themed images (#6323)
* feat(mdx-loader): preserve hash in image src; support GH themed images * more refactor
This commit is contained in:
parent
472a4c881a
commit
217b62682d
8 changed files with 190 additions and 154 deletions
|
@ -160,6 +160,29 @@ import ThemedImage from '@theme/ThemedImage';
|
|||
</BrowserWindow>
|
||||
```
|
||||
|
||||
### GitHub-style themed images
|
||||
|
||||
GitHub uses its own [image theming approach](https://github.blog/changelog/2021-11-24-specify-theme-context-for-images-in-markdown/) with path fragments, which you can easily implement yourself.
|
||||
|
||||
To toggle the visibility of an image using the path fragment (for GitHub, it's `#gh-dark-mode-only` and `#gh-light-mode-only`), add the following to your custom CSS (you can also use your own suffix if you don't want to be coupled to GitHub):
|
||||
|
||||
```css title="src/css/custom.css"
|
||||
html[data-theme='light'] img[src$='#gh-dark-mode-only'],
|
||||
html[data-theme='dark'] img[src$='#gh-light-mode-only'] {
|
||||
display: none;
|
||||
}
|
||||
```
|
||||
|
||||
```md
|
||||

|
||||
```
|
||||
|
||||
<BrowserWindow>
|
||||
|
||||

|
||||
|
||||
</BrowserWindow>
|
||||
|
||||
## Static assets {#static-assets}
|
||||
|
||||
If a Markdown link or image has an absolute path, the path will be seen as a file path and will be resolved from the static directories. For example, if you have configured [static directories](../../static-assets.md) to be `['public', 'static']`, then for the following image:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue