Skip to content Skip to sidebar Skip to footer

Using Only Cr As Linebreak Inside Pre Tag Doesn't Work

At work, we stumbled upon Bugzilla creating HTML output that led to lines much too long because the browser didn't break the lines. This was happening on Chrome, but not on Firefox

Solution 1:

The GM script works because apparently JS converts CR's (\r) to LF (\n), dynamically on writes to the DOM.

See this test at jsFiddle. Notice how the CR (decimal 13), at the end of the 2nd line, gets converted to LF (decimal 10).

Solution 2:

Yes, the HTML RFC defines a line break as: http://www.w3.org/TR/html401/struct/text.html#line-breaks

A line break is defined to be a carriage return (
), a line feed (
), or a carriage return/line feed pair. All line breaks constitute white space.

However, a bare carriage return is extremely rare. I'm not surprised it doesn't work. But technically, I'd say that FF4 and Chrome are in the wrong.

Not sure why your greasemonkey script is working. My guess is that getting el.innerHTML is converting CR to CR-LF or LF.

Post a Comment for "Using Only Cr As Linebreak Inside Pre Tag Doesn't Work"