forked from Cocoanetics/DTCoreText
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSAttributedString+HTML.h
More file actions
75 lines (60 loc) · 3.45 KB
/
Copy pathNSAttributedString+HTML.h
File metadata and controls
75 lines (60 loc) · 3.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// NSAttributedString+HTML.h
// DTCoreText
//
// Created by Oliver Drobnik on 1/9/11.
// Copyright 2011 Drobnik.com. All rights reserved.
//
@class NSAttributedString;
/**
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:].
*/
@interface NSAttributedString (HTML)
/**
@name Creating an NSAttributedString
*/
/**
Initializes and returns a new `NSAttributedString` object from the HTML contained in the given object and base URL.
@param data The data in HTML format from which to create the attributed string.
@param docAttributes Currently not in used.
@returns Returns an initialized object, or `nil` if the data can’t be decoded.
@see [DTHTMLAttributedStringBuilder initWithHTML:options:documentAttributes:] for a list of available options
*/
- (id)initWithHTMLData:(NSData *)data documentAttributes:(NSDictionary * __autoreleasing*)docAttributes;
/**
Initializes and returns a new `NSAttributedString` object from the HTML contained in the given object and base URL.
@param data The data in HTML format from which to create the attributed string.
@param baseURL An `NSURL` that represents the base URL for all links within the HTML.
@param docAttributes Currently not in used.
@returns Returns an initialized object, or `nil` if the data can’t be decoded.
@see [DTHTMLAttributedStringBuilder initWithHTML:options:documentAttributes:] for a list of available options
*/
- (id)initWithHTMLData:(NSData *)data baseURL:(NSURL *)baseURL documentAttributes:(NSDictionary * __autoreleasing*)docAttributes;
/**
Initializes and returns a new `NSAttributedString` object from the HTML contained in the given object and base URL.
@param data The data in HTML format from which to create the attributed string.
@param options Specifies how the document should be loaded.
@param docAttributes Currently not in used.
@returns Returns an initialized object, or `nil` if the data can’t be decoded.
@see [DTHTMLAttributedStringBuilder initWithHTML:options:documentAttributes:] for a list of available options
*/
- (id)initWithHTMLData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary * __autoreleasing*)docAttributes;
/**
@name Working with Custom HTML Attributes
*/
/**
Retrieves the dictionary of custom HTML attributes active at the given string index
@param index The string index to query
@returns The custom HTML attributes dictionary or `nil` if there aren't any at this index
*/
- (NSDictionary *)HTMLAttributesAtIndex:(NSUInteger)index;
/**
Retrieves the range that an attribute with a given name is active for, beginning with the passed index
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:
@param name The name of the custom attribute to remove
@param index The string index to query
@returns The custom HTML attributes dictionary or `nil` if there aren't any at this index
*/
- (NSRange)rangeOfHTMLAttribute:(NSString *)name atIndex:(NSUInteger)index;
@end