Preserve the correct number of newlines from input

Fixes issue #962
Merge pull request #973 from DanielleSucher/fix-issue-962

Fix issue 962