Declared in NSAttributedString+HTML.h

Overview

Methods for generating an NSAttributedString from HTML data. Those methods exist on Mac but have not been ported (publicly) to iOS. This project aims to remedy this.

For a list of available options to pass to any of these methods please refer to [DTHTMLAttributedStringBuilder initWithHTML:options:documentAttributes:].

Instance Methods

HTMLAttributesAtIndex:

Retrieves the dictionary of custom HTML attributes active at the given string index

- (NSDictionary *)HTMLAttributesAtIndex:(NSUInteger)index

Parameters

index

The string index to query

Return Value

The custom HTML attributes dictionary or nil if there aren’t any at this index

Declared In

NSAttributedString+HTML.h

initWithHTMLData:baseURL:documentAttributes:

Initializes and returns a new NSAttributedString object from the HTML contained in the given object and base URL.

- (id)initWithHTMLData:(NSData *)data baseURL:(NSURL *)baseURL documentAttributes:(NSDictionary *__autoreleasing *)docAttributes

Parameters

data

The data in HTML format from which to create the attributed string.

baseURL

An NSURL that represents the base URL for all links within the HTML.

docAttributes

Currently not in used.

Return Value

Returns an initialized object, or nil if the data can’t be decoded.

Declared In

NSAttributedString+HTML.h

initWithHTMLData:documentAttributes:

Initializes and returns a new NSAttributedString object from the HTML contained in the given object and base URL.

- (id)initWithHTMLData:(NSData *)data documentAttributes:(NSDictionary *__autoreleasing *)docAttributes

Parameters

data

The data in HTML format from which to create the attributed string.

docAttributes

Currently not in used.

Return Value

Returns an initialized object, or nil if the data can’t be decoded.

Declared In

NSAttributedString+HTML.h

initWithHTMLData:options:documentAttributes:

Initializes and returns a new NSAttributedString object from the HTML contained in the given object and base URL.

- (id)initWithHTMLData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary *__autoreleasing *)docAttributes

Parameters

data

The data in HTML format from which to create the attributed string.

options

Specifies how the document should be loaded.

docAttributes

Currently not in used.

Return Value

Returns an initialized object, or nil if the data can’t be decoded.

Declared In

NSAttributedString+HTML.h

rangeOfHTMLAttribute:atIndex:

Retrieves the range that an attribute with a given name is active for, beginning with the passed index

- (NSRange)rangeOfHTMLAttribute:(NSString *)name atIndex:(NSUInteger)index

Parameters

name

The name of the custom attribute to remove

index

The string index to query

Return Value

The custom HTML attributes dictionary or nil if there aren’t any at this index

Discussion

Since a custom HTML attribute can occur in multiple individual attribute dictionaries this extends the range from the passed index outwards until the full range of the custom HTML attribute has been found. Those range extentions have to have an identical value, as established by comparing them to the value of the custom attribute at the index with isEqual:

Declared In

NSAttributedString+HTML.h