When you copy a block of "pretty printed" code in Internet Explorer 8 and paste it in notepad, all text appears on one line. See for example:

This is some code
This is the third line of the code

This will appear as:

Hello This is some code This is the third line of the code
0x20-^                 ^
  • 1
    Seems to be a regression to this bug. – waiwai933 Mar 21 '11 at 4:37
  • Yes, I've noticed this too. Thanks for bringing this up. – Gabe Mar 21 '11 at 4:40
  • I don't have IE8 to check it.. :( | Well for the time being upgrade to IE9.. i use it and i didn't face that problem. :) – Shekhar_Pro Mar 21 '11 at 13:52
  • 1
    I also get this problem in internet explorer 9. It's very annoying having to click "edit" on the question to get the code with line breaks intact. – Martin Smith Mar 25 '11 at 13:24
  • I thought I'm the only one that sins in clicking edit ;) this is annoyance number one, I guess either not many use IE, not many have enough reputation in meta to up vote for this, (or not many know about meta), or not many need to copy code, or many have reputation above 2000 in SO. One of the above for sure. – Eran Medan Mar 27 '11 at 2:03
  • Is not bug of IE, from the SuperUser site the code is pasted without any problem, the problem arise only in StackOverflow. – mjsr May 4 '11 at 23:25
  • So the two websites are using different version of google prettify? – Salman A May 5 '11 at 13:46
  • Interesting. For me, copying with line breaks intact works fine on SU for both FF4 and IE9. However, it works on SO for FF4 only; IE9 converts the breaks to tabs. – Pops Jun 6 '11 at 16:25
  • +1 for @Martin Smith's "edit" workaround! – kmote May 24 '12 at 14:23

The cause is that Stack Overflow's version of prettify only checks for IE6, IE7 and IE8. When IE9 came out, the old workaround stopped working!

From: https://stackoverflow.com/content/js/prettify-full.js (2011-06-13):

    var a = navigator && navigator.userAgent &&
        navigator.userAgent.match(/\bMSIE ([678])\./);
  • sounds like a problem that will hang around for a long time until the regex can be improved to match for all cases of IE. – Brian Jun 13 '11 at 12:49
  • sorry, missed this earlier; just checked in the fix – Jeff Atwood Aug 21 '11 at 4:32
  • I'm using IE8. The code from the OP's post pastes fine. BUT the code in this answer (@Sladkey's) pastes on one line. What is the difference? – kmote May 24 '12 at 14:21
  • Please note it is also still broken for me on dba.stackexchange.com (using IE8). (cf. meta.dba.stackexchange.com/questions/691/…) – kmote May 24 '12 at 14:25

The problem should only occur when Prettify kicks in, because when that happens the literal newlines are replaced in the DOM with <br> elements (which IE doesn't respect in this case, for whatever reason). From a quick test, since the code is inside of a <pre> anyway, not replacing the newlines seems to work consistently across browsers (IE8/9, Firefox 3.6/4, Chrome 11/13, Safari 5, Opera 11) so long as you don't include the <br> elements.

I think that Prettify is responsible for this swap in the first place, so preventing it might be problematic. However, it might be possible to add in a post-processing hook that undoes this operation. I'll look into that later to see what might be involved and to verify that this won't cause any other issues.

Edit: It seems that this issue was already well-documented, so the real question as waiwai993 points out is what caused the regression?


I can confirm that this is currently a problem with IE9. See for example this SO answer. I can copy/paste using Chrome 11 fine, but with IE9 I get everything on a single line.

  • ditto for IE8 (pastes referenced sample to single line). – kmote May 24 '12 at 14:27
  • I can confirm that I am able to reproduce this issue for IE7, IE8 and IE9. – Matt Oct 1 '12 at 7:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .