-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
NSAttributedString+DTCoreText.h
139 lines (102 loc) · 3.76 KB
/
NSAttributedString+DTCoreText.h
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// NSAttributedString+DTCoreText.h
// DTCoreText
//
// Created by Oliver Drobnik on 2/1/12.
// Copyright (c) 2012 Drobnik.com. All rights reserved.
//
@class DTCSSListStyle;
@class DTTextBlock;
/**
Convenience Methods that mimick similar methods available on Mac
*/
@interface NSAttributedString (DTCoreText)
/**
@name Working with Text Attachments
*/
/**
Retrieves the DTTextAttachment objects that match the given predicate.
With this method you can for example find all images that have a certain URL.
@param predicate The predicate to apply for filtering or `nil` to not filter by attachment
@param theClass The class that attachments need to have, or `nil` for all attachments regardless of class
@returns The filtered array of attachments
*/
- (NSArray *)textAttachmentsWithPredicate:(NSPredicate *)predicate class:(Class)theClass;
/**
@name Calculating Ranges
*/
/**
Returns the index of the item at the given location within the list.
@param list The text list.
@param location The location of the item.
@returns Returns the index within the list.
*/
- (NSInteger)itemNumberInTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location;
/**
Returns the range of the given text list that contains the given location.
@param list The text list.
@param location The location in the text.
@returns The range of the given text list containing the location.
*/
- (NSRange)rangeOfTextList:(DTCSSListStyle *)list atIndex:(NSUInteger)location;
/**
Returns the range of the given text block that contains the given location.
@param textBlock The text block.
@param location The location in the text.
@returns The range of the given text block containing the location.
*/
- (NSRange)rangeOfTextBlock:(DTTextBlock *)textBlock atIndex:(NSUInteger)location;
/**
Returns the range of the given href anchor.
@param anchorName The name of the anchor.
@returns The range of the given anchor.
*/
- (NSRange)rangeOfAnchorNamed:(NSString *)anchorName;
/**
Returns the range of the hyperlink at the given index.
@param location The location to query
@param URL The URL that is found at this location or `NULL` if this is not needed
@returns The range of the given hyperlink.
*/
- (NSRange)rangeOfLinkAtIndex:(NSUInteger)location URL:(NSURL * __autoreleasing*)URL;
/**
Returns the range of a field at the given index.
@param location The location of the field
@returns The range of the field. If there is no field at this location it returns {NSNotFound, 0}.
*/
- (NSRange)rangeOfFieldAtIndex:(NSUInteger)location;
#ifndef COVERAGE
// exclude method from coverage testing, those are just convenience methods
/**
@name Converting to Other Representations
*/
/**
Encodes the receiver into a generic HTML prepresentation.
@returns An HTML string.
*/
- (NSString *)htmlString;
/**
Encodes the receiver into a generic HTML fragment representation. Styles are inlined and no html or head tags are included.
@returns An HTML string.
*/
- (NSString *)htmlFragment;
/**
Converts the receiver into plain text.
This is different from the `string` method of `NSAttributedString` by also erasing placeholders for text attachments.
@returns The receiver converted to plain text.
*/
- (NSString *)plainTextString;
#endif
/**
@name Creating Special Attributed Strings
*/
/**
Create a prefix for a paragraph in a list
@param listCounter The value for the list item.
@param listStyle The list style
@param listIndent The amount in px to indent the list
@param attributes The attribute dictionary for the text to be prefixed
@returns An attributed string with the list prefix
*/
+ (NSAttributedString *)prefixForListItemWithCounter:(NSUInteger)listCounter listStyle:(DTCSSListStyle *)listStyle listIndent:(CGFloat)listIndent attributes:(NSDictionary *)attributes;
@end