-
Notifications
You must be signed in to change notification settings - Fork 70
/
Copy pathHTMLParser.h
52 lines (37 loc) · 1.98 KB
/
HTMLParser.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
// HTMLParser.h
//
// Public domain. https://github.com/nolanw/HTMLReader
#import <Foundation/Foundation.h>
#import "HTMLDocument.h"
#import "HTMLElement.h"
#import "HTMLEncoding+Private.h"
/**
An HTMLParser turns a string into an HTMLDocument.
For more information, see http://www.whatwg.org/specs/web-apps/current-work/multipage/tree-construction.html
@see HTMLTokenizer
*/
@interface HTMLParser : NSObject
/**
Initializes a parser with what appears to be some HTML.
@param string A string of HTML.
@param encoding The (possibly presumed) string encoding of the document. May change during parsing, causing this parser to be irrelevant.
@param context A context element used for parsing a fragment of HTML, or nil if the fragment parsing algorithm is not to be used.
For more information on the context parameter, see http://www.whatwg.org/specs/web-apps/current-work/multipage/the-end.html#parsing-html-fragments
*/
- (instancetype)initWithString:(NSString *)string encoding:(HTMLStringEncoding)encoding context:(HTMLElement *)context NS_DESIGNATED_INITIALIZER;
/// The HTML being parsed.
@property (readonly, copy, nonatomic) NSString *string;
/// The document's presumed string encoding.
@property (readonly, assign, nonatomic) HTMLStringEncoding encoding;
/// Instances of NSString representing the errors encountered while parsing the document.
@property (readonly, copy, nonatomic) NSArray *errors;
/// The parsed document. Lazily created on first access.
@property (readonly, strong, nonatomic) HTMLDocument *document;
/// A block called when the string encoding has changed, making this parser useless.
@property (copy, nonatomic) void (^changeEncoding)(HTMLStringEncoding newEncoding);
@end
/**
Returns a parser suitable for some data of an unknown string encoding.
@param contentType The value of the HTTP Content-Type header associated with the data, if any.
*/
extern HTMLParser * ParserWithDataAndContentType(NSData *data, NSString *contentType);