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

Trailing spaces in copy-code blocks on Chrome #263

Open
s-makin opened this issue Jul 24, 2024 · 1 comment
Open

Trailing spaces in copy-code blocks on Chrome #263

s-makin opened this issue Jul 24, 2024 · 1 comment
Labels
improvement Make an existing functionality better

Comments

@s-makin
Copy link
Contributor

s-makin commented Jul 24, 2024

Issue: Google Chrome inserts a trailing whitespace at the end of a code block when you select the text by triple-clicking.

Why is this a problem?
With the copy-code extension active, if you triple-click to highlight (as many developers might be accustomed to), Chrome inserts a trailing space in the command which then means you can't run it directly because you get a unicode character at the end of the command.

This doesn't happen on Firefox at all, and on Chrome it doesn't happen if you use the copy-code button as intended, or click+drag to highlight.

The cause:
Sphinx seems to insert a bunch of tags around every word in the command, and then closes the code block with a that has spaces before it to create the line break, as follows. Note, I've included links to two pages from the server docs to illustrate the issue, since we have the same content on Discourse vs GitHub, both generated from standard Markdown:

<html>
<body>
Old:
https://ubuntu.com/server/docs/lxd-containers
<pre><code>sudo snap install lxd
</code></pre>
New
https://documentation.ubuntu.com/
<div><div><pre><span></span><span>sudo</span> <span>snap</span> <span>install</span> <span>lxd</span>
</pre></div>
</div>

New-fixed
https://documentation.ubuntu.com/
<div><div><pre><span></span><span>sudo</span> <span>snap</span> <span>install</span> <span>lxd</span></pre></div></div>

New-fixed-even-better
https://documentation.ubuntu.com/
<div><div><pre><span>sudo snap install lxd</span></pre></div></div>
</body>

Old refers to the Discourse docs where this doesn't happen.
New refers to the documentation using the starter pack where this does happen.
New-fixed is the most basic suggested fix, if it's possible to remove those additional spaces between the block-ending tags.
New-fixed-even-better is the ideal solution, where we would find some way to strip out not just the spaces between the block ending tags, but also the additional tags (some of them are even empty, when you examine the html).

Thanks in advance!

@ru-fu
Copy link
Contributor

ru-fu commented Jul 24, 2024

This sounds like the fix should ideally go to Sphinx (or the copy-code extension?).
I'm fine with tracking it here so one of us can look into it, but we should consider contributing it to wherever the problem originates from.

@ru-fu ru-fu added the improvement Make an existing functionality better label Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improvement Make an existing functionality better
Projects
None yet
Development

No branches or pull requests

2 participants