This issue has been ongoing since at least 2018, as reported in T191700 and by me in April 2018.
To reproduce:
- Edit a page in VisualEditor.
- Type a name of a page.
- Add a hyperlink to that page (click the chain icon, then click Done or the article name in the list).
- Switch to source editor and see that the link forms like [[Example]], then switch back to VisualEditor.
- Select the new link and press Ctrl+I or Ctrl+B to turn it italic or bold (will use italic as example).
- Switch back to source editor. It is now [[Example|''Example'']].
The frustrating workaround I have been using for 2 years is as follows:
- Un-hyperlink the word.
- Italicise the word first.
- Re-hyperlink the word.
- Now it looks like ''[[Example]]''.
I recently noticed some progress in this bug. I found out (unrelated) that editing the text of an unformatted hyperlink then changing it back to the original text now unpipes the link, which is functionality I had been waiting for. It turns out this also applies to links applied to text after formatting, as above. It goes like this:
- Complete steps 1–9
- Add a character in the text of the link (like "Examfple").
- Switch to source editor. It now looks like ''[[Example|Examfple]]''. Switch back to VisualEditor.
- Remove the character so the text is back to being the same as the link.
- Switch to source editor. It now looks like ''[[Example]]'', which is amazing.
You can actually mix both of these behaviours by applying italics before hyperlink and bold after hyperlink. Then it gets really ridiculous. You will see '[[Example]]'' change to ''[[Example|'''Example''']]'' and back to ''[[Example]]''.
Interesting trivia
VisualEditor force-capitalises the hyperlink the first time you change it to italics or bold, but if you un-italicise it and italicise it again, every other time after that it will insert a lowercase link. I.e.:
- [[example]]
- [[Example|''example'']]
- [[example]]
- [[example|''example'']]
- [[example]]
- [[example|''example'']]
I was told in 2018 that this issue was addressed/couldn't easily be fixed. I wholly refuse to believe that.