Problem
The "Copy button for code blocks" feature has been turned on for Super User. Along with it came this "feature" of language name (e.g. bash, python) automatically appearing at the top of each code block in some posts. The "feature" is a misfeature because:
1. The language is not always declared or detected right
The moderator who turned the "feature" on wrote:
you will need to adjust the syntax highlighting language settings for the tags you commonly see code in in order for this button to appear. I've done this for your python tag as a test and set it to
lang-py, and this example question now has the Copy Code button available.
and totally missed what happened to the first code snippet in the example question (click to see large image):
For a human it was clear the code is for ~/.inputrc. For a human who knows something about ~/.inputrc and about Python, it was clear the code had nothing to do with Python. There was no need to improve anything here, still the word python appeared at the top due to the misfeature.
There are many more posts affected.
Now, wrong language appearing in many places is not really what my bug report is about. I mentioned it here for completeness, because the issue is certainly among things that make the "feature" a misfeature; the issue is noted in this Meta post. My bug report is really about what follows.
2. The language name is shown inside the code block, like glued to the code, it looks like the beginning of the code, it can be selected along with the code
From another answer:
Here bash is the name of the language, added automatically, but it looks like the first line of the actual code. It is a general problem: even in the previous example python looks like something that according to the author belongs to the inside of ~/.inputrc, while it does not and the author has never meant it does. In the current example bash looks like something that according to the respective author shall be added to ~/.bashrc.
The new fancy copy button does not include the name of the language in what it copies, but manual selecting and copying still works (sorry for Polish locale, "Kopiuj" means "Copy"):
It should work, because it's the standard way of copying anything from a browser. Since python or bash is visually inside the code block and it can be selected and copied in the standard way as expected, it's easy to assume it does belong to the code. It takes some expertise to know it does not make sense in the context and it really does not belong.
Adding python to ~/.inputrc is a moderate issue: there will be a syntax error when Readline parses the file, not fatal though. Adding bash to ~/.bashrc is a substantial issue: it will be no syntax error but an infinite loop when an interactive Bash starts; bad experience. This may provoke a user who falls in this trap to vote down on the answer in belief that the code is broken. The code the author has provided is fine, the answer used to be good, the misfeature set a trap.
There are many more posts affected.
To avoid traps a user should:
- always use the copy button (but it adds other fluff; it is a separate, orthogonal issue not covered here);
- or remember that the first line from some code blocks shall not be selected for copying.
3. The language name is shown inside the code block, this makes (fragments of) some existing answers insane. Example (from this answer):
The text says "the line […] looks like this" and then there are more lines in the code block (visually three, logically two). Questions begging to be asked by readers are "how can a line look like three lines?" and "why is this so incoherent?". Well, there used to be one line and the answer used to be sane, the misfeature made this fragment insane.
It so happens I'm the author of this now-insane answer. I always try to write high quality answers and I don't like the thought that the misfeature has turned who-knows-how-many of them insane.
Proposed solutions
Fixes that target the misfeature (language name glued to code) and not the feature (copy button):
- Language name shall not be displayed at all. This will easily fix (1), (2) and (3). I like this solution.
- Language name shall be displayed aside and/or distinctively, so it's very obvious it's not a fragment of the code; selecting the whole code block shall not select the language name. This will fix (2) and (if done right) (3) but not (1).
- Over one million posts on Super User (and many more elsewhere, I guess) shall be reviewed and improved manually where needed. This may fix (3), possibly (1), probably not (2) by itself. I don't like this solution.
Immediate action
I imagine any of the above fixes may take some time (the last one for sure). If the only way to immediately turn the misfeature (language name glued to code) off is to turn the feature (copy button) off then please do. The feature may be turned on after it is separated from the misfeature or the misfeature is fixed.
Personally I care mainly about Super User and Unix & Linux SE (they have not got the misfeature yet, lucky them). I care less if the misfeature gets tested "in production" on Stack Overflow, although I suspect it's as harmful there as it is here on Super User.




