@samitouri / QOS-React-2 / commits / 030a7b34c7

Add back \n-to-be-eaten for the plain-text elements

The comment hack to enable polyglot HTML isn't cross-browser, or simply doesn't work.

Austin Wright committed Feb 23, 2015 at 13:58 UTC 030a7b34c7ee3a92fad8113249d399db5c41ea71
1 file changed +6 -3
src/browser/ui/ReactDOMComponent.js
+6 -3
@@ -306,14 +306,17 @@ ReactDOMComponent.Mixin = {
306 || this._tag === 'textarea')
307 && ret.charAt(0) === '\n'
308 ) {
309 - // Add an invisible node that's not a newline, because the HTML syntax
310 - // ignores the first character in these tags if it's a newline
309 + // text/html ignores the first character in these tags if it's a newline
310 + // Prefer to break application/xml over text/html (for now) by adding
311 + // a newline specifically to get eaten by the parser.
312 + // (Alternately for textareas, replacing "^\n" with "\r\n" doesn't get eaten,
313 + // and the first \r is normalized out by HTMLTextAreaElement#value.)
314 // See: <http://www.w3.org/TR/html-polyglot/#newlines-in-textarea-and-pre>
315 // See: <http://www.w3.org/TR/html5/syntax.html#element-restrictions>
316 // See: <http://www.w3.org/TR/html5/syntax.html#newlines>
317 // See: Parsing of "textarea" "listing" and "pre" elements
318 // from <http://www.w3.org/TR/html5/syntax.html#parsing-main-inbody>
316 - return '<!---->' + ret;
319 + return '\n' + ret;
320 } else {
321 return ret;
322 }