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 kotlin, 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?
.png)


