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

Code copy button adds new line #6327

Closed
4 tasks done
maxsitt opened this issue Nov 13, 2023 · 5 comments
Closed
4 tasks done

Code copy button adds new line #6327

maxsitt opened this issue Nov 13, 2023 · 5 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@maxsitt
Copy link

maxsitt commented Nov 13, 2023

Context

No response

Bug description

Currently, when copying code with the code copy button, a new line is automatically added when pasting the copied code somewhere else. This does not happen if the code is copied manually by selecting everything in the code block.

Especially when copying code that should be run in a Terminal/command prompt, the new line that is automatically added when copying the code with the code copy button can lead to problems in some cases, e.g. code is run immediately when pasting. Expected behaviour of the code copy button should be exactly the same as for copying code manually: copy only the content in the code block without adding a new line.

Related links

Reproduction

9.4.8-code-copy-button.zip

Steps to reproduce

  1. Create new mkdocs project with all required packages up to date (2023-11-13).
  2. Add the code copy button feature to the mkdocs.yml:
    theme:
      name: material
      features:
      - content.code.copy
    
  3. Add a code block in index.md.
  4. From the served/built site, copy the code manually by selecting the content in the code block and paste it to an empty text document: no new line is added.
  5. Copy the code with the code copy button: a new line is added.

Browser

No response

Before submitting

@squidfunk squidfunk added the needs investigation Issue must be investigated by the maintainers label Nov 14, 2023
@squidfunk
Copy link
Owner

Thanks for reporting. Fixed in 34d789b. We now remove trailing whitespace when copying. We deliberately decided not to remove leading whitespace, as I'm not sure what the implications of that might be – there are just too many languages. Trailing whitespace should be fine, except for when you're doing tutorials in the language Whitespace, probably.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs investigation Issue must be investigated by the maintainers labels Nov 14, 2023
@maxsitt
Copy link
Author

maxsitt commented Nov 14, 2023

Thanks for the quick fix! :)

@squidfunk
Copy link
Owner

Released as part of 9.4.9.

@btbf
Copy link

btbf commented Jan 25, 2024

I honestly did not want this to be fixed. Sometimes you want a line break at the end.
I would like to be able to set this option for each block.

@squidfunk
Copy link
Owner

I honestly did not want this to be fixed. Sometimes you want a line break at the end.

Well, thank you! Your comment clearly communicates: there are always different use cases. We cannot possibly please everyone, albeit we try so hard. Unfortunately, we're likely keeping it that way, as it's quite useful for the majority.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open
Projects
None yet
Development

No branches or pull requests

3 participants