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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make code blocks copyable in default theme #703

Closed
rdwatters opened this issue Aug 6, 2018 · 18 comments
Closed

Make code blocks copyable in default theme #703

rdwatters opened this issue Aug 6, 2018 · 18 comments
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version

Comments

@rdwatters
Copy link

Feature request

What problem does this feature solve?

This is interesting phrasing, since many features don't solve a problem as much as provide an enhancement 馃槈 . That said, execCommand is a common feature of code blocks in technical documentation. If you're writing large amounts of code, it's often easier to have the user click a copy button (icon or text or whatever) and have a confirmation of some kind saying the text has been copied to the clipboard.

What does the proposed API look like?

Go here and hover the first code block: https://angular.io/guide/displaying-data

How should this be implemented in your opinion?

Plenty of options for implementation, including the popular clipboard.js. I think turning this feature on/off should be as simple as a boolean in the config.

Are you willing to work on this yourself?**

I wish I could, but I'm more of a technical writer than a frontend developer, so this feels a bit brazen.

Cheers all around to VuePress (just discovered this project a couple days ago and it's AWESOME!) and to the Vue community in general. Thanks!

@ulivz ulivz added the type: feature request Request to add a new feature label Aug 7, 2018
@shershen08
Copy link

shershen08 commented Aug 16, 2018

I am creating a sample implementation of this here: https://github.com/shershen08/vuepress/tree/dev/add-copytoclipboard
However this functionality falls between the markdown-it parser tool that's used under the hood and the Vue.js app wrapper UI, so some feedback on the best to choose approach would be appreciated

@shershen08
Copy link

I've created a implementation, that behaves like this: https://www.youtube.com/watch?v=YJ3lnB9AxcM&feature=youtu.be
Will create a PR soon

@ulivz
Copy link
Member

ulivz commented Aug 20, 2018

This is from PR's template:

To avoid wasting your time, it's best to open a feature request issue first and wait for approval before working on it.

@shershen08 Thanks for your work, but for now we don't accept any new feature requests to master. because we will focus on the next version. you can create a PR after our next version is released.


This feature can still be done through the plugin API which is in VuePress Next.

@ulivz ulivz added version: next Planned to do or already included in the next(1.0.0) version plugin scope and removed plugin scope labels Aug 20, 2018
@shershen08
Copy link

Thanks for clarification @ulivz - I've seen this note in PR template, but I didn't get it right that an extra separate issue should be created before working on feature PR.

Is this feature being worked on in VuePress Next already ? If not yet, what could be the road map to add this functionality ?

@dovy
Copy link

dovy commented Mar 25, 2019

@rdwatters took your work and refractored it into a plugin using the same style as the code from @vuepress/plugin-medium-zoom.

Anyone is welcome to merge this into core if desired.

https://github.com/dovy/plugin-clipboard-copy

Installing as as simple as placing in your root repo and adding this to your ~/.vuepress/config.js file:

['plugin-clipboard-copy', true]

Should work out of the box for anyone.

@dovy
Copy link

dovy commented Mar 25, 2019

Published now too for anyone who wants to install and use. https://www.npmjs.com/package/@dovyp/plugin-clipboard-copy

['@dovyp/plugin-clipboard-copy', true]

@ulivz
Copy link
Member

ulivz commented Mar 27, 2019

@dovy Thanks for the great job, and could you also help do following 2 things?

  1. Follow the naming convention of VuePress's plugin to prefix your plugin name with vuepress-plugin, which will take better SEO and simple usage.

  2. Adding your fresh plugin to https://github.com/ulivz/awesome-vuepress.

@ulivz ulivz closed this as completed Mar 27, 2019
@dovy
Copy link

dovy commented Mar 27, 2019

@ulivz attempting to do so.

https://github.com/dovy/vuepress-clipboard-copy
https://www.npmjs.com/package/@dovyp/vuepress-clipboard-copy

I am, however, having an issue: https://cldup.com/XO80nEM6oI.png

I get around this issue by including the plugin in a ~/@dovyp folder of my VuePress (I renamed to show you the issue).

Steps to reproduce:

  1. run yarn install
  2. Verify ~/node_modules/@dovyp/vuepress-clipboard-copy
  3. Update my config.js to have ['@dovyp/vuepress-clipboard-copy', true] in the plugins declaration.

I wonder if I have an issue in my https://github.com/dovy/vuepress-clipboard-copy/blob/master/package.json file. I have tried numerous things.

That being said, I am more than willing to have you just bring this into the core and be an official plugin of VuePress. I have no worry of ownership here. It's primarily @shershen08's work after all.

@ulivz
Copy link
Member

ulivz commented Mar 27, 2019

You should use @dovyp/vuepress-plugin-clipboard-copy instead of @dovyp/vuepress-clipboard-copy.

@dovy
Copy link

dovy commented Mar 27, 2019

Fixed. I missed the -plugin due to text breaking.

https://github.com/dovy/vuepress-plugin-clipboard-copy/
['@dovyp/vuepress-plugin-clipboard-copy', true]

:)

@howar31
Copy link

howar31 commented Apr 19, 2019

@dovy Thanks for your plugin but I found some small issue there.

There will be a scroll bar in Windows system if the code block has only one line:

image

and also on Mac OS but looks a little nicer though:

image

Maybe we need some overflow-y: hidden; or some what :/


Update: I'm currently doing CSS override on theme level in .vuepress/styles/index.styl with:

.content pre, .content pre[class*=language-] {
    overflow-y: hidden;
}

but I think this will be better to be done in plugin itself.

dovy added a commit to dovy/vuepress-plugin-clipboard-copy that referenced this issue Apr 20, 2019
@dovy
Copy link

dovy commented Apr 20, 2019

@howar31 good call. Updated, credited to you, and published to NPMJS.

@howar31
Copy link

howar31 commented Apr 21, 2019

I've noticed another issue that the copy icon will be moved if scroll horizontally:

image

I'll take a look how to fix this issue and update later.

@devopsprosiva
Copy link

@dovy I'm trying to use your plugin with vuepress@1.0.0-alpha.47. However I don't see the copy button enabled. Any suggestion?

Here's my .vuepress/config.js.

module.exports = {
  title: 'Hello VuePress',
  description: 'Just playing around',
  plugins: ['@dovyp/vuepress-plugin-clipboard-copy'],
}

@ulivz
Copy link
Member

ulivz commented May 11, 2019

@devopsprosiva You should create issue to @dovyp/vuepress-plugin-clipboard-copy instead of only mentioning here.

@devopsprosiva
Copy link

@ulivz Thanks. Created the issue dovy/vuepress-plugin-clipboard-copy#1

@sdsa-cci
Copy link

Do this plugin work with Vuepress2?

@sdsa-cci
Copy link

How do we create a codeblock

@rdwatters took your work and refractored it into a plugin using the same style as the code from @vuepress/plugin-medium-zoom.

Anyone is welcome to merge this into core if desired.

https://github.com/dovy/plugin-clipboard-copy

Installing as as simple as placing in your root repo and adding this to your ~/.vuepress/config.js file:

['plugin-clipboard-copy', true]

Should work out of the box for anyone.

I've installed your plugin and setup the config, but what's the markdown code for this to work?
I need the following block to be copyable.

<div class="language-json">
{
 "district_id": 1,
 "prefix": "+91"
}
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature request Request to add a new feature version: next Planned to do or already included in the next(1.0.0) version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants