Skip to content

Add copy button for code blocks #86851

Closed
@GuillaumeGomez

Description

@GuillaumeGomez

As discussed in #86363, we could add a button allowing to copy the content of the source code. For this, I'll unify the content for the "run" button as well so it's not duplicated in case the run button is there as well. Or we could simply generate the button content when clicking on it using JS (because the "copy to clipboard" can only be done with JS), meaning we also generate the hidden lines (but keep them invisible).

Second point: for now the "run" button is always visible but its opacity goes to 1 when you hover it. I'll change this behaviour by hiding those buttons and only making them appear when hovering the code example so it improves the reading experience. However, I'll keep the opacity change behaviour when going on top of the button.

Last thing: should we add this copy button to all code blocks or only the rust ones?

cc @rust-lang/rustdoc

Metadata

Metadata

Labels

A-rustdoc-jsArea: Rustdoc's JS front-endA-rustdoc-uiArea: Rustdoc UI (generated HTML)T-rustdocRelevant to the rustdoc team, which will review and decide on the PR/issue.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions