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

Copy button for Code Blocks #461

Closed
1 task
Tracked by #1344
lorenzolewis opened this issue Aug 4, 2023 · 18 comments · Fixed by #742
Closed
1 task
Tracked by #1344

Copy button for Code Blocks #461

lorenzolewis opened this issue Aug 4, 2023 · 18 comments · Fixed by #742

Comments

@lorenzolewis
Copy link
Contributor

What version of starlight are you using?

0.6.1

What is your idea?

Add a copy button to code blocks so people can easily copy-paste example code.

Already a thread in Discord on this but figured it would be nice to turn it into an issue (for selfish reasons so I can track it downstream 😅): https://discord.com/channels/830184174198718474/1070481941863878697/1120347723128909914

Why is this feature necessary?

Make it easier for developers to follow code examples

Do you have examples of this feature in other projects?

The amazing Astro Docs: https://docs.astro.build/en/getting-started/#start-your-first-project

Participation

  • I am willing to submit a pull request for this issue.
@delucis
Copy link
Member

delucis commented Aug 4, 2023

Our intention is to do this (and more!) via https://github.com/expressive-code/expressive-code

@hippotastic has been waiting on an Astro bug fix — hopefully happening as we speak in withastro/astro#7943 — to get this working well.

@D3vil0p3r
Copy link
Contributor

Our intention is to do this (and more!) via https://github.com/expressive-code/expressive-code

@hippotastic has been waiting on an Astro bug fix — hopefully happening as we speak in withastro/astro#7943 — to get this working well.

Since the withastro/astro#7943 has been merged, the Copy button is on way to be implemented?

@hippotastic
Copy link
Contributor

Yes, it is! I'm currently working on a PR to properly integrate Expressive Code into Starlight. You should be already able to use it yourself right now by installing astro-expressive-code and adding it to your integrations list before MDX/Starlight.

My PR is taking a bit because I'm currently traveling, and more importantly, I want to provide the best possible integration experience. For example, I also want to ensure the syntax highlighting & frame themes match your chosen Starlight site theme in both dark & light modes by default, and that any i18n strings are passed through properly.

@D3vil0p3r
Copy link
Contributor

It is interesting and I thank you for your work! Could you please link the PR you are working on?

@hippotastic
Copy link
Contributor

hippotastic commented Aug 29, 2023

It's not published yet, sorry about that! I'm used to only creating a PR when I'm done on my end. It wouldn't help you either, as I'm currently experimenting to find the best way to integrate the oklab/oklch color spaces into my core package with minimal impact on the bundle size. :)

Currently looking at culori/fn because it's already being used in Starlight.

@Rajkumar0718
Copy link

how configure copy code button in code block .give some example

@trueberryless
Copy link
Contributor

@hippotastic
Do you know an ETA until implemented?
Or do you recommend installing astro-expressive-code by ourselves for now?

@hippotastic
Copy link
Contributor

hippotastic commented Sep 16, 2023

I'm pretty far with my development! The toughest challenge was integrating Starlight's dynamic theming using CSS variables, because I wanted to make sure you can use these configuration options without the default code blocks looking out of place. This is done now. :)

The last challenge is how to connect Starlight's i18n dictionary to Expressive Code, but I'll probably just implement a quick adapter workaround to make this work and refine this in later releases.

My current ETA for the PR is in 3 days, and I'd expect some more days then to react to reviews before merging.

If you need it earlier and can live without the dynamic theming and i18n integration, installing astro-expressive-code yourself (e.g through astro add) and moving its entry in the Astro config's integrations array in front of Starlight & MDX is all you need to do. :)

@D3vil0p3r
Copy link
Contributor

@hippotastic if you need more days to refine it completely, don't worry, do that. I think we can wait in order to have a refined and completed solution. Thank you for your job!

@trueberryless
Copy link
Contributor

@hippotastic
WOW! Great work, dude. I'm very patient so 1 week is kinda nothing for me. That means, take your time because we all appreciate your work later even more! Thank you so much for implementing this!

@hippotastic
Copy link
Contributor

Thank you for the kind words, everyone! I'm glad that you enjoy Expressive Code as much as I enjoy working on it! :)

@D3vil0p3r
Copy link
Contributor

Hello mates ^^ Any news about this feature?

@HiDeoo
Copy link
Member

HiDeoo commented Nov 5, 2023

Any news about this feature?

Lots of news indeed, you can follow the progress in this pull request or read the latest update in this message 👍

@D3vil0p3r
Copy link
Contributor

Thank you for this ticket. Is there a sample code to use this new feature in mdx files?

@HiDeoo
Copy link
Member

HiDeoo commented Nov 20, 2023

Thank you for this ticket. Is there a sample code to use this new feature in mdx files?

This will automatically works out of the box for all MD and MDX files when using the code block syntax.

@D3vil0p3r
Copy link
Contributor

Do we need only to update Astro Starlight to the latest version to have this feature available?

@kevinzunigacuellar
Copy link
Member

Do we need only to update Astro Starlight to the latest version to have this feature available?

It's available since version 0.13

@hippotastic
Copy link
Contributor

Yes, you should only need to update Starlight (how to update).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants