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

[gitbook] Copy to clipboard buttons for code blocks #776

Merged
merged 3 commits into from Sep 20, 2019
Merged

Conversation

RLesur
Copy link
Collaborator

@RLesur RLesur commented Sep 19, 2019

The aim of this PR is to resolve #775.

I propose the following implementation:

  • use clipboard.js: this is a maintained lightweight JS library for copying to clipboard. It is already used by pkgdown. There exists a gitbook copy-code plugin but it seems to be unmaintained. @yihui, tell me if you agree to integrate clipboard.js in bookdown or if you would prefer to use the copy-code plugin.

  • a very basic styling for copy-to-clipboard buttons. @behrman, contrary to pkgdown there is no tooltip. For tooltips, we should add another library in bookdown and I feel that the extra benefit of tooltips would be very small.

@RLesur RLesur requested a review from yihui Sep 19, 2019
@behrman
Copy link

@behrman behrman commented Sep 20, 2019

I've tested the feature branch, and it seems to work fine. We do get a tooltip if we hover over the copy-to-clipboard icon for a sufficient amount of time. I think this is fine.

@RLesur
Copy link
Collaborator Author

@RLesur RLesur commented Sep 20, 2019

@behrman For the tooltip, we do get the user agent button tooltip. Its design and styling may vary from one browser to another.

The main difference with pkgdown is that the tooltip content is not updated after a succesfull copying (the user sees Copied! with pkgdown).

There is another difference: in case of failure, there is a specific message in the pkdown tooltip, see https://github.com/r-lib/pkgdown/blob/d01672efa3baa80fd7ab238b7143080b0daf49a4/inst/assets/pkgdown.js#L108-L110
With the current PR, the copying action can silently fail.

@behrman
Copy link

@behrman behrman commented Sep 20, 2019

@RLesur You've done a fine job with the design of the tooltip messages for pkgdown. There may be some advantage to have consistent behavior between that and bookdown, though I don't know the downsides of doing this. I think the current behavior is fine.

@yihui yihui added this to the v0.14 milestone Sep 20, 2019
yihui
yihui approved these changes Sep 20, 2019
Copy link
Member

@yihui yihui left a comment

Looks perfect. Thank you!

@yihui yihui merged commit e720461 into master Sep 20, 2019
2 checks passed
@RLesur RLesur deleted the copy-to-clipboard branch Sep 20, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 6, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants