Hi,
also apologies for resurrecting such an old thread, but I believe it would make sense to give you an update on this matter, for all people discovering this discussion when searching for a solution.
In this manner, I would like to refer to the content within another discussion I just added.
https://meta.discourse.org/t/copying-code-fenced-text/102390/20
Edit
@dax just made me aware about the fact that this feature is already in Discourse core. Thank you!