Headache with cards adding unwanted spaces after words and not showing spaces added in the editor

I’m getting mysterious spaces after words. My setup is like this.

  1. Sentence (part a)
  2. Sentence (part b - the word).
  3. Sentence (part c)

The single word in sentence part b has the necessary spaces to separate it from the other words in the sentence (added in on the .txt file).

In the picture above the result is correct even though strangely enough the spaces I’ve added are not showing up.

Note the space is there as shown in this excel spreadsheet.
When I come to words without a space at the end there is still a space added.

Note in the editor there are no spaces.

In the excel spreadsheet you can see for this card there is only a space at the start of the word.
This is the html used on all the aforementioned cards.

Why am I having this problem? Why do the spaces I’ve added at the start and end not show up in the editor.

Thanks in advance.

Anki’s editor might not be the best editor when you’re trying to edit whitespaces as it does some HTML rendering, which includes removing every white space that does not separate two words. This can be prevented to some extent, but the best would simply be to edit it in the HTML editor, where you can see the raw text (without rendering).