-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Partially Copying Code Blocks #3436
Comments
I would love this sort of functionality. When showing the necessary console commands to achieve something, it is helpful to show not just the output but also the prompt since the prompt shows useful information. e.g. I would like to show the entire code block below, but the only information I want to be copied is
|
it would also be useful when putting code in a context. For example, if you want to show that a line has to be inserted between 2 lines, you want to show these 2 lines, but you don't want them to be copied |
For excluding entire lines, it turns out pretty easy to create a code comment which you can use like this:
I added shiki transformers to my devDependencies: Then I added this to my .vitepress config.ts:
|
Unfortunately you still get the line-breaks for the missing lines. This can be fixed by wrapping vp-copy-ignore lines with the preceding line-break in an extra vp-copy-ignore span. I wrote a shell ShikiTransformer today which does this (+ handles prompt formatting properly). I'll clean it up and post it on github this weekend. You can try an example here. |
I have a fix in shiki 2.2.0 so this transformer can play nice with the word highlighting transformer. Once that's in vitepress then I'll fix the code and put it somewhere. In the meantime, I chucked my proof-of-concept transformer here. The line-breaks removal is in the The
The default pattern is pretty boring: So e.g. export default defineConfig({
markdown: {
codeTransformers: [
transformerShellPrompt({
languages: [
['ruckus-cli', /^(\w+)(?:\(([-\w]+)\))?(?:\:|>|#|%|\$) ?/d],
'terminal'
],
applyStyles: true
})
],
languageAlias: { 'ruckus-cli': 'shell', 'terminal': 'shell' },
}) |
Is your feature request related to a problem? Please describe.
Currently, whenever copying from a code block, all code exposed in that box will be copied. In an ideal world, within the same code block I am able to show a command as well as the resulting output of a command. However, as a user, when copying the code I only want the actual command without the outputs to be copied.
E.g.
Describe the solution you'd like
Being able to define a line or range of lines of code to be copied from a code block.
Describe alternatives you've considered
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: