Why does markdown do this? (whitespace trimming and other features)

I’m not sure if this will solve a problem for you, but Discourse has a traditional markdown linebreaks site setting that is disabled by default. When enabled, two trailing spaces are required to create a line break.

Here’s an example with that setting enabled:

Here’s an example with the setting disabled (the default value of the setting):

It might be worth looking at this page and trying its 10 minute markdown tutorial: Markdown Reference. The Discourse new user tutorial links to that page, but it likely gets overlooked by a lot of users who take the tutorial: