50

The sixth Community Asks Sprint, which is the final one of 2025, has now concluded. The focus was on site design and usability, and we got a number of requests for things to improve. The first ask we decided to take on was not actually raised on the announcement post, but it is something that has been needing to be addressed for quite a while and I am happy to announce that we ultimately found a way to get it done.

Issues addressed during this sprint

  • Copy Button on Stack Overflow - As of today, users will be able to copy blocks of code directly from posts on Stack Overflow, by clicking the new Copy button in the top right corner of the code block:

    Image of a code block on Stack Overflow with a Copy button

    The copy will include three lines of attribution, which will be rendered as comments using the format appropriate for the language of the code block in question. This is something users have been asking for for almost as long as Stack Overflow has been around. We are rolling it out first on Stack Overflow, but there is potential to add it to other tech sites in the future.

  • Spoiler accessibility improvements - We made spoilers tabbable so you don’t need to use the mouse cursor to access them, and added the option to hit "enter" to reveal them when they're focused. These changes will apply to all sites that use spoilers.

  • Spoilers in comments - We have also introduced spoilers in comments, which we will be testing out first on Puzzling Stack Exchange. The syntax for comment spoilers is [!spoiler goes here!]. Once we make sure they are working appropriately on Puzzling, we will turn them on for other sites that use spoilers.

We would have liked to be able to get to more than a handful of asks during this sprint, but the Copy button turned out to be quite a big issue to tackle. Though this wasn’t something the community requested us to address during this specific sprint, we do feel like this represents a big benefit to users, making life easier for everyone who uses Stack Overflow to solve problems. We can also enable this feature on other tech sites that use code blocks, let us know here if this functionality would benefit other Stack Exchange communities.

Bug reports about the copy button can be made directly as an answer to this post, or linked here if a bug report is posted separately on MSO (or MSE).

What’s next?

I’m glad that, in addition to the copy button, we were also able to make spoilers more accessible to use on the sites where they are a crucial feature. However, there were a lot more requests made than we were able to complete this sprint, so we will share the rest of the asks from the announcement post with teams running Community Asks Sprints in the future. The next Community Asks Sprint will be after the new year, and we look forward to continuing to make improvements to users' experience on the Stack Exchange network in 2026. We will announce the date for the next sprint once we have it.

15
  • 5
    Tabbing spoilers isn't working for me (here or on Puzzling) -- has this not been released yet? Commented Nov 4 at 18:06
  • 11
    There's a lot of bugs for the copy code button... should that probably have a singular place for us to provide feedback and bugs for? or do they each just go on their own question. We're already getting individual bug reports on MSO, that may end up duplicated here, given there's no clear place for where these belong Commented Nov 4 at 18:16
  • 1
    @bobble whoops, it should have been, but we are working on that right now! Commented Nov 4 at 18:31
  • 4
    @KevinB I added a line about reporting bugs. either way will do, but if independent posts are made it is helpful to link them here. Commented Nov 4 at 18:34
  • 1
    I can't remember how often I had thought that a copy button is so simple to implement and so useful for a programming library and I could not understand why the low hanging fruits weren't collected. They finally do. Better late than never. +1 Commented Nov 4 at 22:20
  • I'm curious whether the "comment" spoiler markdown also works for Q&A posts? And if not, why not? (Inline spoilers would be beneficial in some Q&A contexts). Does this mean that comments no longer stick to being a small subset of post-supported markdown? Commented Nov 5 at 6:19
  • Will The Key be updated to also include the attribution? Commented Nov 5 at 7:55
  • Will the spoiler syntax count against the comment's character length? Commented Nov 5 at 15:04
  • Also, it seems each click of the 'copy' button completely overwrites the clipboard. Not necessarily a bug, but it might be nice for users if multiple clicks within a single post, at least, just append rather than replace. Just a thought/idea I had... might not be good or useful in practice. Commented Nov 5 at 15:17
  • 1
    @Robotnik it doesn't work for posts, only for comments. Commented Nov 5 at 18:58
  • 2
    @TylerH the additional brackets and exclamation points will count, but the markup for rendering the spoilers is added when the page is displayed, so that doesn't count. Commented Nov 5 at 18:58
  • 11
    How a simple feature-request (copy button) turns out into overcomplex and buggy implementation, which will cost much more time to fix for developers? The whole idea of sprints as rushy and poorly though nitpicking of what needs to be done, doing it somehow and then fixing bugs afterwards.. is it worth it? How about a "standard" approach? Maybe working on a backlogs, prioritizing, product management and testing are the right way? Hmm.. Commented Nov 7 at 13:53
  • 5
    @Sinatr - I do also kinda think that asking the community what our priorities are, then turning around and doing something else (as beneficial and sought-after as it is!) was a bit... rude? I dunno. It just rubs the wrong way for me. @ SE - Maybe next time just say "Community Asks sprint will primarily focus on [this long awaited feature request] but suggest any other (smaller) changes we can get to if there's time" Commented Nov 9 at 22:11
  • 3
    You didn't get a single software developer to sign-off on the design did you? The language tag being barely distinguishable from an actual line of code is just ridiculous. Even code comments appear more muted. Make it smaller, more muted or just remove it all together Commented Nov 10 at 4:26
  • 4
    As initiated by @FranckDernoncourt, please add the “Copy Button for code blocks” to the Webmasters site. Our Meta discussion regarding this is here. Thanks! Commented Nov 11 at 2:47

27 Answers 27

53

Please adjust the retrieval date in the attribution comment to be in YYYY-MM-DD format, which is the more universal ISO 8601 date format. Currently it appears to be in the format of whatever locale the copier is in. That's... OK, until someone copies something that was copied by someone in a different locale/date format.

(Credit to VLAZ for noticing this)

4
  • 4
    Re "Currently it appears to be in the format of whatever locale the copier in": Yes, I got "# Retrieved 04/11/2025, License - CC-BY-SA 4.0" (for the first code block in this answer). Which is somewhat ambiguous. Commented Nov 4 at 19:46
  • 1
    That's not OK for me, that sucks! YYYY-MM-DD format is always much clearer. Commented Nov 4 at 20:46
  • 10
    my question is- why not just use a permalink to the latest revision at time of copying? Commented Nov 5 at 0:40
  • 25
    The date format has been updated, thanks for the suggestion! Commented Nov 5 at 18:15
46

The attribution comments include the wrong license; it assumes the current site's license instead of the license the post is currently under. For example, Can (a== 1 && a ==2 && a==3) ever evaluate to true? was last modified in 2018, when the license was CC BY SA 3.0. However when copying the code via the new copy button, it displays the wrong license (CC BY SA 4.0):

// Source - https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever->evaluate-to-true/48270314#48270314 // Posted by Kevin B // Retrieved 11/4/2025, License - CC-BY-SA 4.0 const a = { i: 1, toString: function () { return a.i++; } } if(a == 1 && a == 2 && a == 3) { console.log('Hello World!'); } 

(Credit to Kevin B for this)

1
  • 20
    Hi Tyler (and Kevin B), thanks for reporting this! A fix has been deployed. Commented Nov 5 at 14:28
44

50% 50%

Please remove the language name from the header of the code block, for it is often misleading and wrong.

This is not a duplicate of https://meta.stackexchange.com/a/414576/147640 where the problem was that the correct language name is known, but cannot be displayed.
This is for when the correct language is not explicitly recognized by the syntax highlighter as a separate thing.

Example: VBA, VB.NET and VBScript are all different languages.
The syntax highlighter only has the VB.NET syntax, which was fine for the specific purpose of syntax highlighting, because the syntax is close enough to be highlighted correctly most of the time.
But now that the name of the actually used language, vbnet, is displayed in the code block, all VBA code blocks on the site are incorrectly labeled vbnet:

This code block is actually VBA

Example of a VBA block labeled vbnet

Misusing the // tags is a recurring source of confusion, when the OP uses one language and thinks they are using another. Having a code block explicitly labeled vbnet when it is not greatly exacerbates this problem.

I'm sure examples of the same can be found around others tags too.

13
  • 8
    Alternatively: just remove the automation: let authors/editors set the displayed language manually Commented Nov 6 at 21:49
  • 2
    This. Please. Or rather remove the header! Detecting language is unreliable (my experience - xaml detected as php). Maybe showing language should be only done if language is specifed explicitly. Maybe you can have 2 small copy buttons to copy with attributions in comments (who ever needs or asks for this???) and copy ONLY code block? Then just don't show button if language is not specified? Commented Nov 7 at 14:30
  • 4
    Another example: shell languages. The bash syntax highlighting is close enough for other shells like zsh, csh, ksh, etc., but there are significant differences in the actual syntax. This question now has multiple blocks labelled bash, even though almost all of the code is specific to zsh. It's confusing. Commented Nov 8 at 13:10
  • so, the root cause is that the syntax highlighter needs more supported language tags? Commented Nov 13 at 8:37
  • 4
    @JulesKerssemakers It's never going to have enough. The root cause is that the internal name of the highlighting rules package used by the syntax highlighter should not be presented as the name of the language. Commented Nov 13 at 8:48
  • +1, but you may want to respond to the rationale stated in this comment: “we wanted to display the detected code language so that users would know the attribution commenting format. If the language is wrongly detected, the commenting might be wrong and we didn't want to break anyone's code.” In cases where the guess is wrong, but the correct option exists, displaying the guess aids editors in finding and correcting the problem. Commented Nov 14 at 14:11
  • 4
    @KRyan Not sure what to respond to there as that argument is complete nonsense which has been already pointed out in the following comments. "In order to optimize the experience for those who paste the code and press Compile without looking, with have mislabeled all code blocks on the site". a) Excellent choice of those for whom to optimize the experience, and b) It's not going to work even for them because, remember, they aren't looking. Commented Nov 14 at 14:22
  • @Sinatr Remember, you can manually specify the language used in syntax highlighting. Commented Nov 14 at 18:03
  • 4
    Codeblocks for Bash now include bash as their first line. So stupid. bash is a valid command, it starts a new shell. The misfeature breaks answers, especially those that say "put this in your .bashrc. Experienced users will spot the abomination, but a newbie might not. If he or she manually copies the codeblock and pastes into .bashrc as advised, this will create an infinite loop when Bash starts, not a nice situation. The detected code language shall not be glued to the code! Commented Nov 15 at 21:22
  • @KamilMaciorowski Not sure what you are talking about. The misdetected name of the language is not included as the part of the copied code. Commented Nov 17 at 10:37
  • 1
    @GSerg I wrote "if he or she manually copies the codeblock". My point is the name of the language (misdetected or not, irrelevant) looks like the very beginning of the code and if one chooses to select and copy the code manually then there is the risk he or she will copy the name along with the actual code provided by the author, not being aware the name was never meant to be inside the code. I gave the example where the name is a valid command and the described scenario may lead to very bad experience, not just to a syntax error. Commented Nov 17 at 10:57
  • 2
    @CoarseRosinflower, it's not mandatory to speciy language when inserting code snippets. It would be A LOT of work to wix what they did everywhere. The language detection is working terribly wrong. The comments (really?) with attributions are: 1) useless 2) can be inserted as text, rather then "comments". The rookie (obviously) developer didn't even realise the complexity of the problem when he took his decision without consulting with senior. Commented Nov 17 at 11:20
  • @GSerg The misdetected name is included in a manual copy with Ctrl-C. Commented Nov 21 at 21:38
44

Currently the copy code button uses the current URL you are browsing to generate its link, leading to cases like this where the attribution points to a comment rather than the answer that is being copied from:

// Source - https://stackoverflow.com/questions/79802090/why-is-1e9-commonly-used-for-initialization-explain-with-an-example?noredirect=1#comment140821354_79802090 // Posted by Vedanshu // Retrieved 11/4/2025, License - CC-BY-SA 4.0 let maxVal = -1e9; let arr = [-5, -2, -100, -50]; for (let num of arr) { if (num > maxVal) maxVal = num; } console.log(maxVal); // -2 
5
  • 12
    Absolutely. It needs to use the post url (of the question or answer), like the one generated when you click [share] - although one might not want to include the user id. This is especially relevant for questions with lots of answers that might be hidden on a different page (depending on sort order). Commented Nov 4 at 21:55
  • 12
    Hello! Thanks for the report, a fix for this has been deployed. Commented Nov 6 at 20:31
  • Same issue when you click the copy button from a review (it links to the review instead) Commented Nov 8 at 9:36
  • 1
    @Mo_: Are you still encountering this problem, after the fix above was deployed? Commented Nov 14 at 22:57
  • @V2Blast It's fixed for the answer and the question in late answer. But for other answers, it still links to the review. Same for suggested edits. The "other ansewr" tab is still broken. Commented Nov 15 at 8:07
43

It is excellent that the Copy button has been introduced on Stack Overflow; I have been hoping for this feature for over a decade. However, it would be preferable if it occupied less vertical space.

Currently on Stack Overflow:

enter image description here

By comparison, GitHub uses much less vertical space:

enter image description here

Same on Hugging Face:

enter image description here

The addition of vertical space is even more egregious on single-line code blocks, where the Copy button double the vertical space they occupy:

enter image description here

By comparison, GitHub:

enter image description here

I'd suggest doing something similar to GitHub.

12
  • 3
    like this: i.sstatic.net/8Awl5gTK.gif :) Commented Nov 4 at 21:45
  • @M-- exactly. But you're taking risks sharing gifs on MSE :) Commented Nov 4 at 21:46
  • 1
    @M-- Well, not quite like that--that copy functionality does not include any attribution details. Commented Nov 4 at 21:59
  • 2
    @TylerH PRs are welcome stackapps.com/q/10803 :) Commented Nov 4 at 22:03
  • 2
    This can be fixed using custom CSS: .js-copy-button { font-size: 0 !important; }. Commented Nov 5 at 9:25
  • 14
    Another problem with the vertical space is that it applies with a delay, causing the content to jump. This is really noticeable on pages with lots of answers with lots of snippets, where the syntax-highlighting (i.e. language detection) takes a while; if you scroll down to a post before that you can an annoying yank. Commented Nov 5 at 10:20
  • 3
    Agree that it's taking some valuable vertical space. But we wanted to display the detected code language so that users would know the attribution commenting format. If the language is wrongly detected, the commenting might be wrong and we didn't want to break anyone's code. Commented Nov 5 at 19:04
  • 18
    @setman that doesn't sound like a solid argument for that design to me. Anyone who knows what they're doing when copypasting from SO will easily be able to spot and correct a wrong comment format, especially if they're not coding in notepad but in any editor with syntax highlighting. Anyone who does not know what they're doing and blindly copypastes stuff from SO will probably either not read the language tag or fail to understand the implications of a wrong tag. Commented Nov 6 at 9:21
  • @l4mpi a simple sudo systemctl restart apache2 that I was too lazy to type was "autotagged" php with the // comment format instead of bash... btw php also accepts the # comment format Commented Nov 6 at 23:23
  • 3
    @setman I agree with l4mpi's points, but even more simply, the detected language could go elsewhere. The word "Copy" doesn't really have to be there, you could easily replace it by the language. Or leave the "Copy" but show the language once it has been clicked (currently "Copied with attribution", could e.g. be "Copied Python code with attribution"). It doesn't need to introduce a new line to the code block. Commented Nov 8 at 9:38
  • @setman I like that it's displayed because it shows which language the auto detector chose. But why not display it on the side of the post? Commented Nov 8 at 9:39
  • @setman I knowing the commenting format is the purpose, why not put the language name in the label of the copy button itself? (as suggested below) Commented Nov 8 at 15:00
32

One bug in the (undocumented?) additional feature that guesses at the language used is that it is sometimes wrong (originally reported on Meta Stack Overflow):

New code block design guesses incorrectly at what the language is, even when explicitly stated

I just loaded a question and saw what I assume is a new feature in code blocks where the site tells us at a glance what it thinks the language is in said code block:

Screenshot of HTML code in a question tagged 'HTML' showing 'xml' as the type of code being displayed, which is incorrect.

This question is tagged and the actual code fences explicitly state the code is HTML as well:

Screenshot of the markup showing HTML explicitly listed with the code fences

This might just be specific to HTML/XML, since other questions tagged, e.g. seem to 'guess' correctly. The question where I saw this is: Name attribute on details element

Can this please be fixed to not guess at the very least when the language is explicitly stated in the code fences, and preferably also not when a (single) language tag is used in the question?

(Or better yet, if you think you detect a language that is not tagged in the question, prompt the user to confirm whether that language is correct before allowing them to post the question, and if not, change the guess or auto-add the language tag. That would save on a fair amount of "you can't close this question as a duplicate with your gold badge because the question didn't have the correct language tag beforehand).

9
  • 1
    With or without space after the three backticks. I am not sure. A space used to be a formatting error (it wouldn't have any effect (different from just the three backticks)). I could be wrong. Commented Nov 4 at 19:55
  • FWIW it also detects <!-- language: lang-html --> as XML. So, I think they just didn't check to make sure HTML was detected correctly for this feature. Commented Nov 4 at 20:07
  • 12
    thanks for the report - we didn't change anything about how language highlighting works, this was an issue with language aliases that never came up because we weren't surfacing language names before. we implemented a fix that should be live soon (probably tomorrow) that special cases html/xml. Commented Nov 4 at 21:17
  • 5
    @kristinalustig While this is now fixed for HTML, it's not fixed for other questions with unknown languages or multiple languages: stackoverflow.com/questions/51047722/… for example is tagged R and Python, but has code blocks which the system guesses SCSS, Haskell, and Rust (all in a single post!). Commented Nov 5 at 20:53
  • 1
    @kristinalustig here is another one: R answer tagged perl Commented Nov 6 at 7:34
  • 1
    Thanks all, this is definitely a deeper issue with hljs's language recognition, and thus separate from the original issue of confusing language aliases in that specific circumstance. For now, manually overriding the language should be a workable solution in most cases, though I recognize that it's far from ideal. Could you please create a separate meta post bug report where these misidentified language issues can be collected so that we can triage separately? It's probably a larger issue than we can tackle immediately and I don't want it to get lost in the shuffle. Commented Nov 6 at 14:59
  • 1
    @kristinalustig when will the fix be fixed? It's literally wrong 80% of the time in my >9k answers. I cannot afford to go back and fix. See for e.g. this mis-identifies c++ as ini, cpp, scss, rust, rust, less, php, php, ruby, cpp, cpp, scss, less, dart,lisp, cpp, rust, php .... shell, haskell. That's all in a single answer tagged c++ Commented Nov 12 at 13:59
  • 2
    @sehe See my MSE bug report on this bigger issue here: meta.stackexchange.com/questions/414631 Also, FWIW, I know it's not a good fix, but for e.g. that post and any future ones, if you're just writing one language for the entire post, you can fix that issue by adding <!-- language-all: lang-cpp --> to the top of the post; all code blocks in the post that follow will then use C++ syntax highlighting (example: i.sstatic.net/4aYyHewL.png) Commented Nov 12 at 14:25
  • @TylerH Thanks. That's something that the site needs to implicitly add based on the language tag. As it has been for at least a decade, ever since syntax highlighting for code blocks was added. Commented Nov 12 at 15:17
25

Copying posts written by a now-deleted user (such as Can (a== 1 && a ==2 && a==3) ever evaluate to true?) results in the attribution comment being blank for "Posted By: ":

// Source - https://stackoverflow.com/questions/48270127/can-a-1-a-2-a-3-ever-evaluate-to-true/48288599#48288599 // Posted by // Retrieved 11/4/2025, License - CC-BY-SA 4.0 var a = { r: /\d/g, valueOf: function(){ return this.r.exec(123)[0] } } if (a == 1 && a == 2 && a == 3) { console.log("!") } 

It should instead still show the deleted username (e.g. user555141 in this case).

(Screenshot of answer)

(Credit to VLAZ and Kevin B both for this one)

1
  • 14
    Thanks for catching this, a fix has been deployed. Commented Nov 5 at 14:29
21

There are now two copy buttons in Stack Snippets:

screenshot of Stack Snippet showing two forms of Copy links which leads to confusion

The original one (below the code blocks) still copies all the content to the answer field, but the top two just copy that specific code block (e.g. just the CSS or just the (mislabeled as XML) HTML, with attribution, but not in Stack Snippet format. This will likely lead to confusion for readers/answerers. To make matters worse, no information is shown via a tooltip on hover to help users along.

Can the original Stack Snippet "Copy" button be expanded to say "Copy to answer" or something similar? And/Or can the new Copy button for each code block be expanded to "Copy with attribution"

(link to answer shown in screenshot above: Prevent long <legend> from overflowing <fieldset>)

2
  • 11
    "Can the original Stack Snippet "Copy" button be expanded to say "Copy to answer" or something similar?" which is what it originally said? :) Commented Nov 4 at 20:02
  • 7
    A solution to this has been deployed, we have changed the snippets copy button to "Copy to answer". Thanks for the report! Commented Nov 6 at 20:33
18

Copy button should not move on scroll

copy button moved to the left side of a code block when scrolled horizontally


Example question: Prevent long <legend> from overflowing <fieldset>

1
  • 8
    This is fixed now, thanks for the report! Commented Nov 5 at 18:11
18

It would be more visually appealing if the copy button and the language label were vertically aligned. Currently it looks a bit messy:

enter image description here

Example of a better alignment, from ChatGPT desktop program on Windows:

enter image description here

Or from https://learn.microsoft.com/en-us/windows/wsl/install:

enter image description here

4
  • 14
    Considering that trying to guess the prog-lang is not really feasible (meta.stackexchange.com/q/355852), I'd rather see the label dropped altogether, and then include the attribution as plain text. I don't think folks are incapable of commenting out a couple of lines manually. Commented Nov 4 at 21:51
  • 6
    @M-- fully agreed about dropping the prog-lang label, and even when guessed correctly, users typically know the language anyway. Commented Nov 4 at 21:56
  • 3
    Yeah, the language tag is not even correct in the example screenshot (the command is related to python, but is not python code and must be executed in the shell). Removing it would make more sense than trying to improve the layout. Commented Nov 6 at 10:56
  • 3
    In that example it's pretty annoying if attribution gets included in the copy. A one-line pip install does not need attribution... Commented Nov 8 at 13:46
15

As an alternative to the newly introduced copy button for code blocks on Stack Overflow, I've updated my userscript (see the StackApps post for more info) to offer a superior (imo), cross-site experience.

The advantages of having this script installed:

  • Works on all Stack Exchange websites (not just Stack Overflow)

  • Guaranteed plain-text attribution. The official SO feature often incorrectly guesses the programming language and comments out the attribution with the wrong syntax (see the relevant bug report), creating extra work. This script provides the attribution as plain text, letting you decide how to comment it out

  • Gives the right attribution (i.e. link to the post, author's name, date of retrieval, and license info) for all posts (regular Q&A's, community wikis, posts by deleted users, etc.)

  • The copy button only appears on hover (unlike SO's feature), saving screen space. It cleanly overrides (removes) the default Stack Overflow copy button

Click to install the updated version with a script manager. Note: I have only tested this with Tampermonkey on Firefox.

14

Please add the “Copy Button for code blocks” to the Code Review site as well.

On Code Review people share code from a project they own or maintain for peer review. Potential answerers will often want to run the posted code themselves in order to review it. A copy button for code blocks would make that much easier.

Update (November 16, 2025): The results of a poll on Code Review Meta were generally in favor of the feature (Yes: +18/-1, No: +1/-2 after 11 days) and it has been turned on.

8
  • 8
    I would suggest raising a feature request on Code Review's Meta, requesting this change and explaining the reasoning. Then, if there's sufficient community support for the change, raise a custom flag for a mod to look at the post, asking them to add the [status-review] tag so the request is on the CMs' radar. (That said, I personally agree that it would make sense to enable this functionality there, at least once the kinks have been worked out.) Commented Nov 4 at 18:48
  • 5
    @V2Blast: OK, I can delete the question here and ask on CR Meta first. – Perhaps it can be clarified in the question what the procedure to “.... let us know here if this functionality would benefit other Stack Exchange communities” should be, exactly. Commented Nov 4 at 18:50
  • That's fair. I'm not one of the CMs working on this particular initiative; my suggestion is just how the CM team has typically preferred that site setting change requests be made in the past, since we want to make sure that the community is in support of the change (and that it'll actually benefit that site) before we make that change. Commented Nov 4 at 18:56
  • 4
    I've undeleted this answer, since there's no reason you can't also suggest it here – I'm just saying it'll be good to get the community's support before we actually implement the change. Sharing those suggestions here of what sites would benefit from this feature can still be a good starting point for that process. Commented Nov 4 at 18:59
  • 10
    Posted on Code Review Meta: Should we adopt the "Copy button for code blocks” feature on Code Review? Commented Nov 4 at 19:29
  • 2
    @V2Blast This is a long-standing request on TeX SE. There is now another Meta request for this (at least the third such request to my knowledge). We were previously told it would not be added as it was deemed inadvisable for the main Stack sites. Since that's no longer the case, please could staff reconsider TeX SE's history of requests for this feature? Commented Nov 7 at 17:16
  • 2
    @cfr: I found the current feature request about it here: Enable the new copy code button on TeX.SE – I've added the [featured] tag, so if about a week goes by and there's a general consensus that the community would like this feature enabled, please flag the post for mod attention and ask them to add the [status-review] tag. Commented Nov 7 at 17:25
  • @V2Blast thanks. as you can see there, requests go back at least 14 years ... Commented Nov 7 at 19:31
11

Code blocks don't always have a copy button. I think the common denominator is the syntax guessing -- if it guesses the language (even wrongly), there is a copy button. If it doesn't guess the language, there's no copy button.

Example 1: (incorrectly) identified code blocks as Java:

Drools code identified as "java"

Example 2: code block without language identification and without copy button:

Drools code with no language identification or copy button

9
  • 6
    This is by design. When we don't have a language prediction, we can't figure out how to comment out the attribution. We felt that having wrongly commented out attribution was worse than no copy button at all. Commented Nov 4 at 20:02
  • 3
    @setman That would make sense if this is about the language label, but that makes absolutely no sense with regard to attribution. Why would we need to know the language in order to know: A) the URL of the content, B) the author of the post, or C) the date the code was copied? Surely you can add the copy button and not expose the language label at the same time? Commented Nov 4 at 21:55
  • 10
    @TylerH The problem is not with figuring out the attribution, it is with figuring out how to format is as a comment. Commented Nov 4 at 22:00
  • 3
    @Bergi Ah, I see. Well, in that case just default to an arbitrary choice and hope the copier is not so braindead that they can't fix that aspect before trying to, for example, run the code they copied. Commented Nov 4 at 22:01
  • 9
    @setman Let me propose a solution (it would resolve bunch of bugs and FRs in one go); don't guess the prog-lang (reasons given here: meta.stackexchange.com/q/355852). Add the attribution as plain text. Most people are more than capable to comment out a couple of lines manually. Commented Nov 4 at 22:02
  • 2
    @M-- we got a few opinions on the feature and heard that manually commenting out the attribution would be too annoying. Commented Nov 5 at 19:11
  • 4
    @setman if it identified the right prog-lang reliably, I'd agree with you. But it fails on so many instances; see this question of mine: stackoverflow.com/q/51047722 so many different langs (haskell, perl, scss, kotlin, etc.) while everything is just R. Besides the issue with wrong commenting syntax, it is misleading when you label the code block as something that it isn't. Again, I refer to the link I shared above; I'd argue that incorrectly highlighted syntax is less problematic than incorrectly labeled code. Commented Nov 5 at 23:07
  • I'd be curious to know if there's a complete list of languages somewhere. Right now, none of the code blocks in the [batch-file] tag have highlighting (and subsequently the copy button) and it seems insane that a language with over 50,000 questions isn't included in the new feature. Commented Nov 8 at 6:37
  • 1
    @setman, how can "we'll do the best we can" possibly be more annoying than "we could help you, but we won't"? Even if the best you can do still requires manual intervention, that's better than nothing. Sure, it's great when the added license and attribution text are automatically formatted as comments in the source language, but that's the icing on top, not a key feature. Commented Nov 12 at 23:10
9

If I understand correctly, your attribution comments do not follow your own requirements for attribution, because they do not include a link to the author's profile.

4
  • 5
    The requirements can only come from the license itself. Their requirements are probably more like recommendations. The text of the BY part of the license says something like "identification of the Creator.. in any reasonable manner" and "hyperlink to the Licensed Material to the extent reasonably practicable", so there is some leeway how to do that. Commented Nov 4 at 22:10
  • 1
    @NoDataDumpNoContribution Actually, the license says "in any reasonable manner requested by the Licensor", so if I am reading this correctly Stack Exchange has the right to specify these requirements. Commented Nov 4 at 23:19
  • 3
    Stack Exchange is not the licensor, we are. This is between users, the company only offers the platform. Actually, I'm not sure what we request here. Do we as users can be assumed to have requested this? Probably not automatically. But what if somebody requested it on his profile page? What if the user copying never visited that page? In the most extreme case I would ever have visited only one page and copied from there. What isn't written there, I don't have to take into account. Commented Nov 5 at 6:05
  • 2
    @NoDataDumpNoContribution Ah, I see your point, and I think you are right. There is a reference to "appropriate attribution" in the terms of service, but you are right that if it's not in the ToS then it probably has no legal value and it has to be considered a recommendation. Still, it's interesting that SE does not follow their own recommendations... Commented Nov 5 at 10:29
8

In certain situtions the language of a code block is guessed incorrectly, leading to the attribution comment to be in the wrong format. Pasting the code then leads to compile errors.

This is a common occurrence for questions where multiple languages are involved. For example, questions regarding the build files of a Kotlin app are usually tagged with , but the Gradle version catalog (one part of the build files) is in the TOML format. When the TOML code block is not explicitly marked as toml (which the vast majority of posts do not do), the language is incorrectly guessed as kotlin. The generated comment will use double slashes //: Correct for Kotlin, but wrong for TOML. # should be used there instead.

Long story short: If this code block wouldn't have been marked with toml, it would incorrectly be guessed to be Kotlin code, and copying it would result in this wrong comment:

// Source - https://stackoverflow.com/a/79810492 // Posted by tyg, modified by community. See post 'Timeline' for change history // Retrieved 2025-11-06, License - CC BY-SA 4.0 kotlin = "2.2.21" 

However, it needs to be this instead to not produce compile errors when pasted:

# Source - https://stackoverflow.com/a/79810492 # Posted by tyg, modified by community. See post 'Timeline' for change history # Retrieved 2025-11-06, License - CC BY-SA 4.0 kotlin = "2.2.21" 

One could argue that not marking a code block with the correct language is the root cause for the problem here. But the reality is that most users don't even know about the possibility to define the language for a code block, and not all that do employ it everywhere where it is needed. Unless the editor is changed to enforce this, I don't think this can be the solution.

Although the automatic language detection was always flawed, this change makes the fact much more visible. What is the intended solution for situations like these?

0
8

Please change the appearance of the language indicator at the top of the block so that it looks different to a code comment. This could be by centre- or right-aligning it, or by using a distinctive style, e.g. border or underline.

As it stands, it doesn't look like a header, and it's easy to select it along with the code (the normal way, via PRIMARY selection - the button only copies to CLIPBOARD selection, which is too cumbersome for normal use).

3
  • 4
    Yes, please! – Or make it part of the button label (“Copy XML”) or leave it out altogether. Commented Nov 7 at 17:28
  • 1
    As a 'I use btw', I would appreciate PRIMARY selection. (Either as a OS lookup or user setting) [CTRL] + [v] is kinda foreign to me, and I'd probably mess up a couple times. Commented Nov 8 at 10:59
  • I've posted this feature request as a question, complete with a screenshot to demonstrate the problems with the new language labels: meta.stackexchange.com/questions/414926/… Commented Nov 21 at 17:27
7

Some posts are edited by multiple users collaboratively. All authors must be credited. How do you handle that in the attribution comments?

6
  • 3
    I'm not disagreeing with you, but do you have a source or further explanation for what you mean by "all authors must be credited"? E.g. are you talking about a CC By SA attribution requirement? Also, edits can be made that don't touch code, which is all that is copied with this new feature. How do you suggest it be determined whether an edit to a post included edits to the code? Finally, what kind of code edits should be considered? Formatting? Tabs vs spaces replacements? Typo fixes? Or whole rewrites? etc. Commented Nov 4 at 21:58
  • 6
    @TylerH Whenever you make an edit to a question or answer, you create a derivative work according to the CC license. The authors of the creative work are all authors of the previous work and the editor. The attribution requires to name all authors, not just the initial one. For example, if I would edit this answer, I would become an author of it regardless of what I change. However only of the edited version, not the previous versions. But the previous versions aren't shown except in the history. SO is doing it sloppily here as if they have no idea how CC-BY-SA really works. Commented Nov 4 at 22:03
  • @NoDataDumpNoContribution So if you're just copying code, and the code is unchanged between versions, you don't need to cite the second author/editor. Commented Nov 4 at 22:10
  • 2
    @TylerH Most likely they mean the actual version of the article, seeing that they also link to it, but in principle they could also go back in time for each code snippet to the last version that contained it unchanged and copy from there with link, time stamp and license version from then. Would be more complicated but minimize the author list. Commented Nov 4 at 22:15
  • 6
    Thanks for bringing this up! We rolled out a change to address this and while it doesn't directly list everyone that has edited the post, it now informs the user that the post was modified by the community and lets them know that they can view the post's timeline to see this data. Commented Nov 6 at 20:43
  • 1
    @ChristopherDoucette While this is not what the answerer wanted, could it be that the post was edited but only by a single person and the warning would not be necessary? Also if the timeline has all the information, maybe something else could be used to get it also here? Commented Nov 7 at 17:31
6

I like copying the code by selecting it, now I have to be careful to not select the language code. So it just made copy-pasting the code harder. The language code should never be copied to the clipboard, there's no use case where you'd want to copy a language code together with the source, it just ends up being a nuisance I later have to delete inside my editor.

5

In dark mode, when the buttons have the focused state (Ex. via tab navigation), their background is the same colour as the text. Seems like this is a recurring issue (Text colour for hovered Ask Question button is similar to button background) with buttons and the site CSS.

5

Please consider adding the "copy" button/feature to the "revisions" page for posts as well (and correctly select the license version based on the date of a given revision you copy from). For example, the answer post Can (a== 1 && a ==2 && a==3) ever evaluate to true? was last edited in 2022, so the post is currently under CC BY SA 4.0, however, the latest revision didn't change any of the code.

Someone might have a legitimate reason for wanting to use code from Stack Overflow but also avoid a newer version of the CC BY SA license. Allowing the user to scroll down to a revision from, say, 2018, when the code and post were still under v3.0 of the CC BY SA license, could be useful and would also be a great overture toward respecting users' licensing/content authorship rights and facilitating users' ability to find code posted here more useful to their needs.

3
  • I know what you want, just want to additionally point out that copying code from a revision page (or the actual page, it doesn't matter if there is no change in the code) with or without the copy button, gives the user the choice of the license for each of the revisions where the code is exactly as copied. Users could just fill in the required information by themselves for example. Commented Nov 5 at 17:27
  • 1
    @NoDataDumpNoContribution The license per revision is not exposed anywhere on the Revisions page so a user would have to just know when the dates were for each license change or look that information up. Putting the feature here would automate that process and make sure it's correct every time a copy is made. Commented Nov 5 at 21:06
  • 3
    Best would be the timeline, which displays the license for every edit and every comment. Of course the feature would be more convenient but even without it's not impossible. Commented Nov 5 at 21:16
5

Please could the "guessed" language tag be made something like user-select: none; so it is not possible to accidentally select it when trying to copy the snippet by the old drag-to-select-text, then copy method.

It seems vast swathes of JSON are guessed as Javascript which is a problem as JSON doesn't support comments so the old select and copy method will be needed.

1
  • Select/copy copies not only the guessed language but also the “Copy” label of the button. Commented Nov 13 at 19:39
4

If one has the edit post privilege, clicking a copy button in the preview area will also save the post.

2
  • 5
    Weird - I wasn't getting the button in previews. Still, if it does show up, it's the same problem we have seen at least 2-3 times before - the buttons are <button> elements that don't specify a type attribute, thus by default they will submit whatever form they are in. The fix is to use <button type="button">. And then maybe write it down on a post-it note. Commented Nov 5 at 14:53
  • 5
    Thanks for the report, this has been fixed. Commented Nov 5 at 18:10
4

This code block is formatted as toml:

I have the following problems with it:

  1. That the language is detected as ini may not be technically wrong, but it is quite confusing because this line of code belongs in the Gradle version catalog (which happens to be in the TOML format), not in some random ini file.

  2. Furthermore, it is not obvious at first glance that the text "ini" describes the format of the code block and does not belong to the code itself. For very short code blocks - especially one-liners as this one - the effect is more pronounced.

  3. Using the new Copy button adds the license as well, which is not always desired. Instead of removing the license after I pasted the code, I want to copy the code as usual by simply selecting it and pressing CTRL+C. This, however, also copies the "ini" text as well if I'm not carefully placing the mouse cursor. In effect this feels like a degradation to the previous user experience.

I do not even see the added value of having the detected language displayed at all. If you do not want to remove it entirely, I suggest to at least move the text out of the way, like right-aligning it near the Copy button, and making it non-selectable as not to interfere with manual text selection.

5
  • 2
    ini is not even a language so that's odd; it's just a file extension used for text-based properties and values for programs to read. I'm surprised to learn it's even an option. Commented Nov 6 at 19:13
  • 5
    @TylerH yes- it's the formatting used for INI files which contain key-value pairs. Commented Nov 6 at 19:14
  • 1
    @VLAZ I mean I'm aware of what INI files contain, I use themall the time. There's not really any formatting beyond new lines in those files, so it's odd that there's even an option for that; it's not something complex enough to warrant syntax highlighting, in my opinion. At least not when there's way more important cases to provide highlighting for that currently don't have highlighting options. Commented Nov 6 at 19:54
  • 3
    @TylerH INI files have formal grammar and syntax - headers, comments, key-value pairs, as well as formal definition of data types - strings, numbers, and path values. While it's not the same amount of syntax as a programming language, it's still more convenient to have highlighting for relevant sections. And the grammar is of comparable size to JSON which also has syntax highlighting. Commented Nov 6 at 19:58
  • 1
    I agree that the current highlighting is not great. But also, it's cheap and what is provided by highlight.js. This highlighting makes it much easier to visually distinguish the different parts of the syntax. Commented Nov 6 at 20:08
4

C++ code blocks are labelled cpp. This is confusing, because CPP is the name of the C preprocessor. They should be labelled with the name of the language.

9
  • 6
    Eh, not really. .cpp has been the name of the C++ file extensions since the dawn of time. C++ compilers are often named something-cpp. I have never actually heard of the C preprocessor getting referred to as "cpp" however. In general it is referred to as "pp" and that's how the formal standard refers to it too, "pp-token" etc. That being said, I agree that "C++" would be a better name. Commented Nov 7 at 9:43
  • 2
    I'm pretty sure K&R's original preprocessor was called cpp (though I haven't actually checked) and GCC's is also called cpp, so that's a pretty continuous pedigree. I've never seen a compiler ending -cpp - in the GNU suite, those are always preprocessors. As to file names, .cpp, .C, .cc are all commonly used suffixes (recognised by Make's built-in rules), and I'm sure I've seen .c++ used in some codebases. Commented Nov 7 at 9:50
  • It's actually never referred to like that, other than maybe through the gcc URL leading to the preprocessor documentation. Notable from the very preprocessor documentation are the chapters. 4.2.7 __has_cpp_attribute and 4.2.8 __has_c_attribute, so not even the gcc preprocessor uses cpp to refer to the preprocessor, but to the C++ language. Commented Nov 7 at 9:54
  • 2
    Note that, as somebody who started programming in C before C++ even existed, and then switched over later, my understanding has always been that cpp refers to c plus plus. Commented Nov 7 at 12:04
  • 3
    The name of the language is "C++". That's how code blocks in that language should be labelled, not by one of the file extensions recognized for such code. Commented Nov 12 at 23:19
  • 1
    @Lundin, The C preprocessor is not only referred to as "cpp" in documentation and URLs. It is available by that name as a binary executable on many systems. POSIX does not appear to standardize that, but it's nevertheless very traditional. Speaking only for myself, I knew the C preprocessor as "cpp" long before I understood that the same symbol was sometimes used to refer to C++ in contexts that do not allow the '+' character to appear in identifiers. Commented Nov 12 at 23:29
  • 1
    In any case, the fundamental point here is that the label should identify the source language by its name, not by one of the filename extensions sometimes used for naming files containing source written in that language. Commented Nov 12 at 23:32
  • @JohnBollinger "cpp" was already used to refer to C++ back in 1990 and Borland Turbo C++ so the notation is hardly new; in fact it seems to have been around for as long as C++, pretty much. Yes, C existed before that, but the use of the abbreviation "cpp" has de facto meant C++ for some 35 years by now. As I mentioned, even the gcc preprocessor in itself uses that terminology. Any earlier use might exists but that's a story for retrocomputing.stackexchange.com and not relevant to this discussion. Commented Nov 13 at 13:00
  • 2
    @Lundin, I distinguish between the symbol "cpp" being used in source-language identifiers and it being used to name or refer to the language itself or compilers for it. At best, "cpp" is ambiguous, which is all the more reason not to use it as a label. And it is in any case uncontroversial that "cpp" is not the name of the language. Labeling C++ source as "C++" would be clearly superior to labelling it "cpp", notwithstanding any particular person's assessment of just how bad "cpp" is in that role. Commented Nov 13 at 14:48
0

You may be able to lean on Highlight.JS to get comment defintions for languages. Something along the lines of

hljs.listLanguages().reduce((res,lang)=>{ res[lang] = hljs.getLanguage(lang).contains?.filter(e=>e.scope==="comment"); return res;} ,{}); 

The stuff in there is defined in terms of regex, so for end, "$" would be your undefined.

See also https://highlightjs.readthedocs.io/en/latest/language-guide.html#comments.

1
  • 8
    Nice idea to try and lean on Highlight.JS here. I don't think we can use hljs.listLanguages() for grabbing definitions of how comments are generated. These contain regex for detecting comments, not generating comments. Converting a regex like /\/\*\*(?!\/)/ or /\/{3,} ?/ into a usable comment generation definition would be difficult. Commented Nov 5 at 1:08
-1

The SPDX format of comments might be appropriate here for the attribution comments. There's the benefit that it's standard, fairly well adopted, has a fair amount of integration with related ecosystem tooling, and indicates where the snippet ends.

// SPDX-SnippetBegin // SPDX-License-Identifier: CC-BY-SA-4.0 // SPDX-SnippetCopyrightText: 2025 starball <https://stackoverflow.com/u/11107541> // SPDX-SnippetAttributionText https://stackoverflow.com/revisions/12345/1 console.log("hello world!"); // SPDX-SnippetEnd 

See also:

For crediting multiple contributors, there's not analog to SPDX-FileContributor for snippets, but you could just do a comma-separated list in SPDX-SnippetCopyrightText.

2
  • 7
    Appropriate, probably yes. But I don't like it, it makes the comment look quite messy. I'd be worried that more people delete the entire attribution than edit out the SPDX tags they don't need. This could be very useful as a user setting though! Commented Nov 4 at 22:05
  • 2
    @Bergi yeah I agree about the poor visual aesthetic and I also think it increases risk of deletion. it's functional though, and as someone who uses SPDX comments for my source files, this isn't too hard on the eyes. it's only a little (subjective) longer than what's in the current attribution implementation, and I wouldn't say it's overly wasteful of space. Commented Nov 4 at 22:13
-2

The additional comment header first seems like a nice addition, but it's not very practical. Consider not doing it for smaller snippets. You are also not obligated to do it.

The button simply copies some text into the clipboard. Only when the user pastes from there into something that again is published attribution rules of the license can apply. The user would be responsible for the attribution. This is just a courtesy.

But is it also convenient? Most code I read shows links to SO sometimes but not that often. And it often wouldn't have to. There is fair use for example. As a result people would probably remove these lines again, wasting time and undoing the time saved by clicking the button.

On the webpage, you don't show these comments for any code snippet as well.

Therefore, for the sake of practicality, consider condensing the additional comment into a single line and/or leave it out for small code snippets (say less than 10 lines) completely.

2
  • 1
    "additional comment header is a nice addition" - strongly disagree. It's useless. No one asked for it. I will be deleting it anyway. Always. It's useless noise. You are FREE to copy code from my answers 1:1 and sell your apps without attribution. If SO think differently, that's another story, which you can ignore. You may only consider attributions if you copy content of StackOverflow to some other web-site as text to be shown. Then a link to post is a good thing. Commented Nov 17 at 11:24
  • @Sinatr I agree with you. That why I edited it somewhat. I also think about blocking this copy button and replacing it with another external made button. On the other hand, others might not be so generous than you. I think fair use is most likely dealing with short snippets anway. Commented Nov 17 at 12:17

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.