Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What line endings to use for cross-platform compatibility?

My webapp lets users download text files. Currently the text files have Unix-style \n line endings, and as a result, when opened in Notepad on Windows (and probably other Windows utilities), the line breaks are missing. Because of the popularity of Notepad among my users, I am thinking of changing the line endings to a Windows-style \r\n. But will that cause some kind of problems on non-Windows platforms or alternative editors?

(Side comment: it so happens that these files are being generated on the fly, so I could condition the line ending format on the user's OS, but at this point I'm trying to be minimalistic, and also just curious in general. Using Django, by the way.)

like image 486
RexE Avatar asked Oct 02 '22 19:10

RexE


1 Answers

I think the best option is to let your users decide. Give them a dropdown box to choose Windows/UNIX/Mac style line endings. You can keep the files normalized to UNIX style endings since they are the easiest to work with.

I am not sure if you can generate text files with a universal style of line endings. Most tools like git normalize their files and leave the users to configure which style of output they prefer. Jeff has written a great article on line endings which goes into some historical context.

like image 87
arocks Avatar answered Oct 22 '22 18:10

arocks