This builds on GH-6359 and changes the logic so that a newline is only inserted between fragments if the previous fragment does not end with a newline.