Reading all the examples posted it seems there could another approach to this - require the line to be of certain length for the newline in source to be removed. For example, if the newline character is before position 40 or 60, it is converted to HTML line break, otherwise it is not. This would actually handle every case mentioned above correctly.