Working with HTML in NSAttributedString
Working with HTML in NSAttributedString
- Subject: Working with HTML in NSAttributedString
- From: j o a r <email@hidden>
- Date: Sat, 24 Nov 2001 23:57:27 +0100
Hello,
While trying to implement support for very rudimentary HTML browsing in
my application I came across a problem.
The basics are simple, you get most of it for free using the AppKit
version of NSAttributedString and only need to make sure that the text
you pass it is recognized as HTML and that the base URL is known. After
that you simply need to tell your TextView how to handle clicks on the
links in the HTML page, and to make sure that the cursor changes shape
over the links. Easy.
Now to the problem. If the HTML in question has any tables (very
common...) they are represented as a series of "attachments" in the
attributed string - every other attachment containing a type of object
called "HTMLDocument". A HTML document with only one table in it will be
represented as an attributed string of length 2, for the two attachments
representing this table. The problem is that since the string is no
longer a flat string, but probably some sort of hierarchial structure
populated with unknown types, my code for parsing the attributed string
to find the links breaks - and I need to find them in order to set the
cursor rects in the TextView.
Are there any sample code available on how to handle this? I don't find
any public references to the HTMLDocument type in the docs, but I do
find it when peeking into HTMLDisplay.framework - which is a private
framework.
Would I need to use the private framework to be able to work with this
data, or can I do it with the public frameworks? Should I start to
attempt to recursively parse the attachments returned, or is there some
completely different method to solve this problem?
I have tried to search the archives for an answer, but so far failed to
find one.
Best regards,
j o a r