# The Great Newline Schism

**URL:** <https://discourse.codinghorror.com/t/the-great-newline-schism/123>\
**Category:** blog\
**Created:** [January 18, 2010, 12:00am UTC](https://discourse.codinghorror.com/t/the-great-newline-schism/123 "2010-01-18T00:00:00Z")\
**Posts on this page:** 1\
**Showing post:** 15

<div class="post-metadata">

**Author:** ![Shadow2531](https://discourse-cdn.codinghorror.com/letter_avatar_proxy/v2/letter/s/f04885/32.png) [@Shadow2531](https://discourse.codinghorror.com/u/Shadow2531)\
**Post date:** [February 16, 2010, 12:00am UTC](https://discourse.codinghorror.com/t/the-great-newline-schism/123/15 "2010-02-16T00:00:00Z")

</div>

There’s a common and accepted way to normalize newlines (using js regex for examples):

```
.replace(/\r\n|\r/g, "\n");
.replace(/\r\n|\r|\n/g, "\r\n");
.replace(/\r\n|\n/g, "\r");

```

The first method is used for server-sent events (not regex, but the normalizing of \r\n and \r to \n via parsing).

The second method is used in HTML5 for textarea value getters/setters. Opera does this already. However, Webkit currently uses the first method and Gecko and IE do different things depending on the situation.

You can use ` __lookupGetter/Setter__ ` and ` __defineGetter/Setter__ ` or `Object.getOwnPropertyDescriptor` and `Object.defineProperty` to patch a textarea’s ‘value’ getter and setter to work around the differences in newline normalization.

Newlines being right for a textarea’s value is important because it affects the value’s length, which many sites (like Twitter) use as character counters to enforce limits.

I absolutely hate the newline deal though. I wish we could get rid of it and just use only \n everywhere.

As for a Unicode newline, I once tried to switch to using it (just to be  
Unicode-proper and all that), but couldn’t find anything that handled it  
display-wise.

---

_[View the full topic](https://discourse.codinghorror.com/t/the-great-newline-schism/123)._
