From ThoughtBridges
Jump to: navigation, search

Line Endings

Metapattern Code: LINE_END_CRLF (with two underscore characters)

For Graphics Designers

Different operating systems favor different conventions to determine what constitutes the end of a line in a text file.

If no attention is paid to this issue, you might end up with script files that look like gobbledygook when opened in Notepad on Windows.

If the LINE_END_CRLF metapattern was applied by the software developer, the script file (often a file with a .jsx or .js file name extension) will use carriage return + line feed (CR+LF) line endings.

Carriage return and line feed are two special ‘codes’ that can be inserted between the bytes that compose the text of the script.

  • Linux and Mac OS X normally use just a line feed character (numeric character code 10 in ASCII and Unicode) as the line ending.
  • Mac OS (pre Mac OS X) uses a carriage return (numeric character code 13 in ASCII and Unicode).
  • Windows uses a combination of two consecutive codes: carriage return followed by line feed (numeric character code 10 followed by code 13 in ASCII and Unicode)

Luckily, most modern text editors are smart about this, and graciously handle text file with the ‘wrong’ line endings.

Notepad on Windows is an exception: it will only work well with carriage return + line feed line endings.

Notepad++ ( is smart enough to handle this properly.

The idea is to standardize on a line ending that has the best chance of being interpreted correctly.

By using carriage return + line feed as the 'standardized' line ending, the file will show correctly in most circumstances.

It will work in Notepad on Windows (dumb program) and it will work in TextWrangler or BBEdit on Mac OS X (smart program); the same applies to the most common text editors in use.

If you have a script file that has the LINE_END_CRLF metapattern applied, and you need to re-save it, make sure you re-save it correctly so the line endings are respected.

In TextWrangler on Mac OS X, use the ‘File - Save As...’ menu item and make sure the ‘Line Breaks’ popup is set to ‘Windows (CRLF)’.

In Notepad++ on Windows, use

For Software Developers

Once your script is complete, make sure you save it with CRLF line endings.

To avoid the line ending changing during the download process, it is best to store your script in an archive file of sorts.

ZIP archives are best supported - they can be used both on Mac and on Windows.

By storing your file into a ZIP archive, the line endings will not be disrupted by the download process.

Detailed description of the metapattern

The script file uses carriage return + line feed line endings (Windows line endings).

Related metapatterns