code-block-pro icon indicating copy to clipboard operation
code-block-pro copied to clipboard

Newlines are Discarded from Code Copied to Clipboard

Open vishnumaiea opened this issue 1 year ago • 14 comments

I just noticed that whenever I copy code using the Copy button, the code copied to the clipboard discards newlines (CRLF, etc.). You can see this on the following page.

https://www.circuitstate.com/tutorials/how-to-create-a-standalone-raspberry-pi-pico-c-cpp-project-in-windows-and-build-from-command-line-and-vs-code/

Simply copy any code there using the copy button and paste it into a notepad. The notepad contents look like below for me.

image

My actual code looks like below.

image

If copied by drag selection, it works as expected and the newlines are preserved when the code is pasted.

vishnumaiea avatar Oct 03 '23 10:10 vishnumaiea

It doesn't happen locally when I try it but I see it happening on your site. Do you want to maybe list out your plugins or try deactivating them again? Not sure if you have that test site still set up.

https://github.com/KevinBatdorf/code-block-pro/assets/1478421/df4a3ed5-e0b8-484f-87ed-eaa3c6cde6da

KevinBatdorf avatar Oct 03 '23 16:10 KevinBatdorf

Interesting. The staging site is sill up. Let me check.

vishnumaiea avatar Oct 03 '23 18:10 vishnumaiea

Found it. This time the culprit is the Flying Scripts plugin. It defers loading/executing Js until a user action happens. I use it to delay Google Ads. I have the following keywords to defer the Javascript. See any problem here?

adsbygoogle.js
reactive_library_fy2019.js
show_ads_impl_fy2019.js
recaptcha

vishnumaiea avatar Oct 03 '23 18:10 vishnumaiea

I tried removing each of the keywords one by one but had no effect even after removing all of them. Only when I deactivated the plugin, did the Copy button start working correctly.

vishnumaiea avatar Oct 03 '23 18:10 vishnumaiea

What's odd is the formatting is being changed before it's even in the browser. It could be because I used the attribute data-code and they are doing something with that.

CleanShot 2023-10-03 at 14 45 14

KevinBatdorf avatar Oct 03 '23 18:10 KevinBatdorf

For now, I will keep the Flying Scripts plugin deactivated. I don't see a performance impact even after disabling it. So it should be good.

vishnumaiea avatar Oct 03 '23 18:10 vishnumaiea

I had a similar issue with LiteSpeed cache. I fixed it by excluding front.js from the Deferred / Delayed JS pipeline.

saranshkataria avatar Mar 24 '24 04:03 saranshkataria

That's valuable feedback, thank you. I'll look into that

KevinBatdorf avatar Mar 25 '24 19:03 KevinBatdorf

I had a similar issue with LiteSpeed cache. I fixed it by excluding front.js from the Deferred / Delayed JS pipeline.

Hey, thanks a ton for your reply because I would have never resolved this issue without it! I'm still struggling to resolve this issue while the LiteSpeed Cache plugin is enabled. Similarly to you, I added the front.js file to all excludes inside of Page Optimization > [8] Tuning as you can see in the image below. That didn't seem to work for me, but I was able to track this issue back to the same plugin because the issue was resolved when I disabled it.

Page_Optimization_‹MonzterDev—WordPress-_Googl-05-05-24_04-02-36

MonzterDev avatar May 05 '24 08:05 MonzterDev

Thanks for the feedback. Can you link to the plugin? Ultimately, these html minification plugins/services shounld't be removing whitespace from within HTML attributes. At least not by default.

Is there a setting related to that under the HTML Settings tab there?

KevinBatdorf avatar May 05 '24 08:05 KevinBatdorf

Thanks for the feedback. Can you link to the plugin? Ultimately, these html minification plugins/services shounld't be removing whitespace from within HTML attributes. At least not by default.

Is there a setting related to that under the HTML Settings tab there?

Gonna take a look for that setting now, but in the meantime...here's a link to their Plugin, Github Repo, and Docs!

MonzterDev avatar May 05 '24 08:05 MonzterDev

Thanks for the feedback. Can you link to the plugin? Ultimately, these html minification plugins/services shounld't be removing whitespace from within HTML attributes. At least not by default.

Is there a setting related to that under the HTML Settings tab there?

It seems disabling the HTML Minify setting in the [3] HTML Settings tab solves this issue. I removed front.js from the excludes and as long as the HTML Minify setting was disabled, the copy feature functions as normal.

MonzterDev avatar May 05 '24 08:05 MonzterDev

Thanks for sharing the GitHub. i'll see if I can somehow add an exception so their code doesn't process it by default

KevinBatdorf avatar May 05 '24 08:05 KevinBatdorf

Thanks for sharing the GitHub. i'll see if I can somehow add an exception so their code doesn't process it by default

Wow, thanks for being outstanding! Fast replies, helpful solutions, and even looking into adding an exception... I really appreciate all the effort you put into creating and maintaining this plugin as well as helping those who use it! 😄

MonzterDev avatar May 05 '24 08:05 MonzterDev