views:

1388

answers:

3

We've got an application where users can enter "notes" into a rich edit control (Telerik's RedEditor, but that doesn't matter here). We had a user enter notes from w/in Safari that had a <span></span> in the middle of the note, and that span had a style on it specifying white-space:pre The HTML of the note was in the form of:

<div> This is a note <span class="Apple-tab-span" style="white-space: pre; ">   </span> and here's more of the note. </div>

Simple enough, the style should apply to the span, and the span had 4 spaces in it. There should have been 4 spaces in the resulting output.

Here's the problem. IE seems to apply that white-space: pre; style not only to the span, but to the enclosing div! Therefore, this long line that should have wrapped since it's not in the span, now pushed the document out until the line fits on the page.

What am I missing. I know IE has problems, but this doesn't seem right, even for IE.

So, the question(s):

1) Am I correct that the white-space attribute should only have applied to the span?

2) Can this be resolved somehow? Remember, I'm not in control of the content being entered. And it's entered from a mac w/Safari and being viewed in IE.

Edit: The doctype on the page in question is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;

A: 

Are you using a Standards Mode DOCTYPE? In Quirks Mode, IE incorrectly applies ‘white-space’ only to block elements. (I couldn't get it to leak the white-space out of the span though, it just simply didn't work.)

I'm not in control of the content being entered.

It's unusual to allow raw HTML content to be entered; in that case you can't really fix up any browser weirdnesses!

bobince
Raw HTML content can't be entered (well, I guess it could, but wasn't), this was more likely a cut/paste from some other document on the Mac. It's a private site used by researchers so we're more concerned with capability than XSS protection.
WaldenL
A: 

1) Yes you are correct.

2) I've had a lot of problems with Telerik controls specifically the RTE changing raw HTML entered into it. I suggest that you check your database and see what HTML is being stored there.

Hope that helps

Darko

Darko Z
This was text entered through the normal (not html) view, but I hear what you're saying about it changing stuff. However, we then output this HTML on another page (just emitted there, no editor) and that's where the problem occurs. So it's not the editor.
WaldenL
A: 

I'm not sure what you're trying to achieve with an space in a span with pre as its style. If you're trying to make the sentence have a space there and not word wrap, put the no-wrap style on the whole div. If all you want is a space, put the html entity &nbsp directly between the two words and they will not break apart. Or if you are trying to create an arbitrary space greater than a single space, forget about pre and just give that span a width.