Don't append newlines inside a span

(cherry picked from commit adb2f21897d9aa8233c9851ea89f2aa6c41df8a3)