blocks to the clipboard correctly?
We\'ve noticed that IE7 has an odd behavor with code blocks posted on Stack Overflow. For example, this little code block:
public PageSizer(string href, int inde
This looks like a bug in IE, BR tags inside the PRE or CODE are not being converted into newlines in the plain text copy buffer. The rich text copy buffer is fine, so the paste works as expected for applications like wordpad.
The prettify script, that colours the code, removes all the whitespace and replaces it with HTML tags for spaces and new lines. The generated code looks something like this:
code
code
code
code
The PRE and CODE tags are rendered by defaults with the CSS style of {whitespace: pre}. In this case, IE is failing to turn the BR tags into newlines. It would work on your original HTML because IE will successfully turn actual newlines into newlines.
In order to fix it you have 3 options. (I am presuming you want nice HTML and the ability to work well with and without javascript enabled on the client):
You could place the code inside a normal div and use CSS to render it using {whitespace: pre}. This is a simple solution, although might not please an HTML markup purist.
You could have two copies of the code, one using proper PRE / CODE tags and another in a normal div. In your CSS you hide the normal div. Using javascript you prettify the normal div and hide the pre/code version.
Modify the prettify script to recognise that it is acting on a PRE or CODE element and to not replace the whitespace in that event.
Notes:
What is important is not the HTML in your source, but the HTML that is generated after the prettify script has ran on it.
This bug is still present even if the white-space mode of the PRE is changed to normal using CSS.