Skip to content

Conversation

@sfc-gh-dmatthews
Copy link
Contributor

📚 Context

The copy button is missing from codeblocks (except those that are inside of docstrings). This PR fixes that and adds a parameter to optionally hide the copy button, such as for blocks used to show file structures.

🧠 Description of Changes

After

image

Before

image

Contribution License Agreement
By submitting this pull request you agree that all contributions to this project are made under the Apache 2.0 license.

@sfc-gh-dmatthews sfc-gh-dmatthews requested review from a team and removed request for sfc-gh-kmcgrady December 8, 2025 05:57
@snehankekre
Copy link
Contributor

snehankekre commented Dec 8, 2025

Just noticed an unintended side effect on code blocks on the API reference page

After image
Before image

@sfc-gh-dmatthews
Copy link
Contributor Author

Thanks @snehankekre! This was a little fiddly, but I think I have a fix. However, it's a little cleaner to change all the code blocks with the theme instead of just RefCards, but if it's design-vetoed, I can move the color changes into more special-casing in the RefCard CSS.

@sfc-gh-dmatthews sfc-gh-dmatthews added platform javascript Pull requests that update Javascript code and removed platform labels Dec 18, 2025
* feature/code-block-language-header

* Include none language

* Debug none language

* Hide language when none

* Use right padding

* Add header to Autofunctio code
* feature/code-block-description

* Filename color

* Replace language with filename; optionally both

* Revert content changes

* Revert more content changes
* feature/code-block-description

* Filename color

* Replace language with filename; optionally both

* Revert content changes

* Revert more content changes

* feature/try-it-code-block-button

* Use named target

* Design edits

* Fix gray code header in dark mode

* Remove filename

* Design tweaks

* Update Autofunction code block to match
@sfc-gh-dmatthews sfc-gh-dmatthews requested a review from a team as a code owner December 19, 2025 22:26
@sfc-gh-tteixeira
Copy link
Contributor

sfc-gh-tteixeira commented Dec 20, 2025

Ok, I took a design pass and also did a tiny bit of refactoring to avoid some code duplication and to address hydration errors.

One thing: I returned the code blocks to the old dark style (even in light mode). I found the colors just weren't working, and would take a lot more finagling to make them work. So this felt like the simpler solution. Besides, I think they look really distinctive this way!

PTAL

@sfc-gh-tteixeira
Copy link
Contributor

Oh, I also added support for hiding the header bar of a code block. Just use <Code hideHeader={true}>


if (metaString) {
// Supported boolean flags (standalone words)
const booleanFlags = ["try", "showAll", "hideCopyButton"];
Copy link
Contributor Author

@sfc-gh-dmatthews sfc-gh-dmatthews Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const booleanFlags = ["try", "showAll", "hideCopyButton"];
const booleanFlags = ["try", "showAll", "hideCopyButton", "hideHeader"];

@sfc-gh-tteixeira We need to keep this section of [...slug].js in sync with <Code> as well. There's probably a way to fix it with IDE extensions, but for a basic Markdown setup, you can see code highlighting in your IDE with the native Markdown blocks but not our custom <Code> block. Hence, I prefer to use the native Markdown block to the extent possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand what you're saying here. Can you clarify?

Copy link
Contributor Author

@sfc-gh-dmatthews sfc-gh-dmatthews Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can configure the Markdown parsing to accept arguments and flags for code blocks. In the IDE, this makes for a better experience (both in terms of overall format and for syntax highlighting).

Use a Markdown block (which is interpreted/rendered with <Code>):
image

Use <Code> directly:
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This edit allows:

```python hideHeader
foo
``` 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

javascript Pull requests that update Javascript code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants