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

"Copy" in code blocks inject double newlines #7170

Closed
3 of 4 tasks
jippi opened this issue May 11, 2024 · 8 comments
Closed
3 of 4 tasks

"Copy" in code blocks inject double newlines #7170

jippi opened this issue May 11, 2024 · 8 comments
Labels
bug Issue reports a bug resolved Issue is resolved, yet unreleased if open

Comments

@jippi
Copy link

jippi commented May 11, 2024

Context

I want to make it easier for folks to copy configuration examples from my documentation page, by using the copy feature.

Bug description

When clicking the copy icon in all code blcoks on my documentation site, I get extra blank newlines in between the content.

I initially thought it was due to Annotations in code blocks, but does not seem to be the case.

Manually "drag cursor over text and copy" works fine.

Related links

Reproduction

Click any copy icon from my related links section and see that you get double newlines

For example; the Generate labels via script code block:

Expected

label:
  # Generate list of labels via script
  - strategy: generate
    # With a description (optional)
    description: "Modified this service directory"
    # With the color $pink
    color: "$pink"
    # From this script, returning a list of labels
    script: >
      /* Generate a list of files changed in the MR inside pkg/service/ */
      merge_request.modified_files_list("pkg/service/")

      /* Remove the filename from the path
        pkg/service/example/file.go => pkg/service/example */
      | map({ filepath_dir(#) })

      /* Remove the prefix "pkg/" from the path
         pkg/service/example => service/example */
      | map({ trimPrefix(#, "pkg/") })

      /* Remove duplicate values from the output */
      | uniq()

Actual

label:

  # Generate list of labels via script

  - strategy: generate

    # With a description (optional)

    description: "Modified this service directory"

    # With the color $pink

    color: "$pink"

    # From this script, returning a list of labels

    script: >

      /* Generate a list of files changed in the MR inside pkg/service/ */

      merge_request.modified_files_list("pkg/service/")



      /* Remove the filename from the path

        pkg/service/example/file.go => pkg/service/example */

      | map({ filepath_dir(#) })



      /* Remove the prefix "pkg/" from the path

         pkg/service/example => service/example */

      | map({ trimPrefix(#, "pkg/") })



      /* Remove duplicate values from the output */

      | uniq()

Steps to reproduce

  1. Go to any page
  2. Click the copy icon
  3. Paste into any editor or window

Browser

No response

Before submitting

@facelessuser
Copy link
Contributor

This seems to have been introduced in one of the recent Material releases. Locally, I had mkdocs-material-9.5.6, but after updating to mkdocs-material-9.5.21, I was able to reproduce the issue.

I should note that I could only reproduce with the line_spans: __span option. I suspect that the copy logic gets tripped up by line spans and injects extra new lines. That is my guess at least.

@squidfunk
Copy link
Owner

Thanks for reporting. Please provide a minimal reproduction, as requested by our bug reporting guidelines.

@squidfunk squidfunk added the needs reproduction Issue lacks a minimal reproduction .zip file label May 11, 2024
@jippi
Copy link
Author

jippi commented May 11, 2024

Bisecting releases, it works as expected in 9.5.17 and fails in 9.5.18 and above; and removing line_spans: __span makes it work across all versions

jippi added a commit to jippi/scm-engine that referenced this issue May 11, 2024
@squidfunk
Copy link
Owner

Fixed in 937d7cc. I was able to reproduce it and found out that it's related to 4eb1a43, which fixes line highlights on mobile, but introduced the side effect of empty lines when copying.

@squidfunk squidfunk added bug Issue reports a bug resolved Issue is resolved, yet unreleased if open and removed needs reproduction Issue lacks a minimal reproduction .zip file labels May 12, 2024
@luonghuyquang
Copy link

You did 'Fixed empty lines when copying (9.5.18 regression)'.
Do we need to install specific version 9.5.18?
An upgrade would install 9.5.21 again.

@squidfunk
Copy link
Owner

squidfunk commented May 12, 2024

I'm in the process of creating a release for this. "9.5.18 regression" means the bug was introduced in 9.5.18 and it worked before, which was confirmed by the OP, saying that downgrading to 9.5.17 fixes the issue.

@squidfunk
Copy link
Owner

Released as part of 9.5.22.

@jippi
Copy link
Author

jippi commented May 12, 2024

Thank you @squidfunk ❤️

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

4 participants