Re: -[NSAttributedString initWithData:...] compresses spaces?
Re: -[NSAttributedString initWithData:...] compresses spaces?
- Subject: Re: -[NSAttributedString initWithData:...] compresses spaces?
- From: Glen Simmons <email@hidden>
- Date: Thu, 27 Apr 2006 17:34:02 -0500
On Apr 27, 2006, at 5:28 PM, Douglas Davidson wrote:
On Apr 27, 2006, at 3:12 PM, Glen Simmons wrote:
I'm using -[NSAttributedString
initWithData:options:documentAttributes:error:] with some XHTML
that looks like this:
<html xmlns="http://www.w3.org/1999/xhtml">
<p>
<font face="Lucida Grande" size="5">a</font>
<font face="Garamond" size="5"> </font>
<font face="Lucida Grande" size="5">a</font>
</p>
</html>
The problem is that the NSAttributedString I end up with only has
one space between the two a's instead of the 4 that it should. How
can I get it to preserve the spaces?
NSAttributedString is behaving correctly here; any browser would do
the same. If you like you could spend some quality time with the
HTML, XHTML, and XML specs, and find out exactly what they specify
with regard to treatment of whitespace, but I warn you that it's
not pretty.
The usual way to get multiple spaces in HTML is to use non-breaking
spaces (either literal or entities), or a mixture of nbsp
and ordinary spaces, in such a way as never to have consecutive
ordinary spaces. That's what NSAttributedString does when it
writes out HTML.
If you really want your whitespace to be read in as ordinary spaces
rather than as nbsp and spaces, there is an Apple-specific
mechanism for that. Surround your mixture of nbsp and spaces with
<span class="Apple-converted-space"></span>, and it will be
converted back into spaces when NSAttributedString reads it in.
Try saving as HTML in TextEdit, and you'll see all of this in
action. You can control what flavor of HTML is generated, and
whether <span class="Apple-converted-space"> is used, by
manipulating the "HTML saving options" in the "Open and Save"
portion of TextEdit's preferences.
As usual, Douglas is there with the answer. :) I kind of figured it
was something like that. Thanks for the info.
Glen
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden