canonical / canonical/sphinx-stack
Trailing spaces in copy-code blocks on Chrome
- Dominant language
- No language data
- Stars
- 37
- Forks
- 77
- Avg merge
- 1d 5h
- Merged PRs (30d)
- 3
Description
**Issue:** [Google Chrome inserts a trailing whitespace](https://stackoverflow.com/questions/38467334/why-does-google-chrome-always-add-space-after-selected-text) 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:
```
Old:
https://ubuntu.com/server/docs/lxd-containers
sudo snap install lxd
New
https://documentation.ubuntu.com/
sudo snap install lxd
New-fixed
https://documentation.ubuntu.com/
sudo snap install lxd
New-fixed-even-better
https://documentation.ubuntu.com/
sudo snap install lxd```
`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!
Contributor guide
Assessment
This issue has not been assessed yet.