canonical / sphinx-docs-starter-pack

A documentation starter-pack
https://canonical-starter-pack.readthedocs-hosted.com/
Other
14 stars 36 forks source link

Trailing spaces in copy-code blocks on Chrome #263

Open s-makin opened 1 month ago

s-makin commented 1 month ago

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 commented 1 month ago

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.