I’m having a go at this and managed to get leading/trailing dashes on usernames working fine, including on mentions.
Not so lucky with the underscore at start+end of a username because on the message composer the markdown parser seems to have precedence before the @ mentions: the username gets rendered in italic instead of a link.
I’m a bit stuck at the moment on that as I’m not sure where to look to address this. Any tip @Falco?