Highlight markup gets included in hashtag

Steps to reproduce

Type __#tag__.
Works great.

Type ~~#tag~~. Or type #tag, highlight the tag and press the shortcut that adds this markup.
No hashtag is obtained. No rendering occurs.

Edit the above and put a space before the #. The hashtag is created but includes the trailing ~~. And it renders weird. Put a space before the trailing ~~. It works.

Type ==#tag==.
Same behavior as above.
Put spaces before and after ‘#tag’. It works. But now the highlighting has spaces around it. Undesirable to have spaces, but there’s no other way given this bug.