Only remove whitespace from end of text node

Given an element like

    <p>
        <b>A</b> B
    </p>

the current code would remove the space before `B`.

This PR fixes the issue by only removing whitespace from the end of any text node.