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

Support GitHub-style themed images #6007

Closed
2 tasks done
Josh-Cena opened this issue Nov 25, 2021 · 4 comments
Closed
2 tasks done

Support GitHub-style themed images #6007

Josh-Cena opened this issue Nov 25, 2021 · 4 comments
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.

Comments

@Josh-Cena
Copy link
Collaborator

Josh-Cena commented Nov 25, 2021

Have you read the Contributing Guidelines on issues?

Description

A remark plugin to turn GitHub themed images:

![GitHub-Mark-Light](https://user-images.githubusercontent.com/3369400/139447912-e0f43f33-6d9f-45f8-be46-2df5bbc91289.png#gh-dark-mode-only)![GitHub-Mark-Dark](https://user-images.githubusercontent.com/3369400/139448065-39a229ba-4b06-434b-bc67-616e2ed80c8f.png#gh-light-mode-only)

GitHub-Mark-LightGitHub-Mark-Dark

How does it work?

GitHub just uses CSS to hide the images with a given fragment. So you can even have them separated:

Dark mode only:

GitHub-Mark-Light

Light mode only:

GitHub-Mark-Dark

I guess we don't have to implement this part, just use the existing theme image component

Into the ThemedImage JSX:

<ThemedImage
  alt="GitHub Mark"
  sources={{
    light: useBaseUrl('/img/github-light.png'),
    dark: useBaseUrl('/img/github-dark.png'),
  }}
/>

Has this been requested on Canny?

No

Motivation

GitHub has added support for themed images: https://github.blog/changelog/2021-11-24-specify-theme-context-for-images-in-markdown/

We have tried hard in the past to support GitHub features, it's now time for us to support this one.

API design

This will be done under the hood as part of mdx-loader and only exposed in the future as a preset option after #5999.

ThemedImage may be more natural and well-integrated with our theme approach, but we may also use plain CSS like GitHub does...?

Have you tried building it?

No response

Self-service

  • I'd be willing to contribute this feature to Docusaurus myself.
@Josh-Cena Josh-Cena added feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future. status: needs triage This issue has not been triaged by maintainers and removed status: needs triage This issue has not been triaged by maintainers labels Nov 25, 2021
@slorber
Copy link
Collaborator

slorber commented Nov 25, 2021

Related to discussion: https://twitter.com/wooorm/status/1463877371140923398

I don't really like the gh- prefix 😅

Maybe it should be part of the remark gfm plugin?

@Josh-Cena
Copy link
Collaborator Author

Josh-Cena commented Nov 25, 2021

I don't really like the gh- prefix 😅

Me neither, feels like it's not really extensible. But after all this doesn't have to be documented—it can just be a nice little feature for existing GitHub users.

Maybe it should be part of the remark gfm plugin?

It's either we or no-one. GitHub themselves just used CSS (Titus mentioned that as well). Both images end up in the markup, with one hidden:

image

So remark-gfm doesn't need to do anything special—they just need to ask users to implement the same CSS. (In fact, what can they do? Themed images can't be purely HTML anyways) I'm fine with us using CSS to hide it as well, but adding a little remark plugin would make the ThemedImage component more useful than it currently is

@Josh-Cena Josh-Cena added status: blocked This issue is blocked by another issue or external dep and can't be pushed further. and removed status: blocked This issue is blocked by another issue or external dep and can't be pushed further. labels Dec 4, 2021
@Josh-Cena
Copy link
Collaborator Author

I decided that nothing should be done. This could easily be achieved with CSS in userland.

@felipecrs
Copy link
Contributor

Just in case someone stumbles upon this like I did, Docusaurus now supports it:

https://docusaurus.io/docs/next/markdown-features/assets#github-style-themed-images

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature This is not a bug or issue with Docusausus, per se. It is a feature request for the future.
Projects
None yet
Development

No branches or pull requests

3 participants