diff --git a/HTMLKit/HTMLDocument.h b/HTMLKit/HTMLDocument.h
index cc4e1b3..213cb67 100644
--- a/HTMLKit/HTMLDocument.h
+++ b/HTMLKit/HTMLDocument.h
@@ -10,6 +10,13 @@
#import "HTMLDocumentType.h"
#import "HTMLQuirksMode.h"
+typedef NS_ENUM(short, HTMLDocumentReadyState)
+{
+ HTMLDocumentLoading,
+ HTMLDocumentInteractive, // Not used
+ HTMLDocumentComplete
+};
+
@interface HTMLDocument : HTMLNode
@property (nonatomic, strong) HTMLDocumentType *documentType;
@@ -18,4 +25,6 @@
@property (nonatomic, copy, readonly) NSString *compatMode;
+@property (nonatomic, assign, readonly) HTMLDocumentReadyState readyState;
+
@end
diff --git a/HTMLKit/HTMLDocument.m b/HTMLKit/HTMLDocument.m
index 1ea44d3..4c6a6ce 100644
--- a/HTMLKit/HTMLDocument.m
+++ b/HTMLKit/HTMLDocument.m
@@ -10,4 +10,13 @@
@implementation HTMLDocument
+- (instancetype)init
+{
+ self = [super initWithName:@"#document" type:HTMLNodeDocument];
+ if (self) {
+ _readyState = HTMLDocumentLoading;
+ }
+ return self;
+}
+
@end
diff --git a/HTMLKit/HTMLParser.m b/HTMLKit/HTMLParser.m
index 0ae3706..76fbab9 100644
--- a/HTMLKit/HTMLParser.m
+++ b/HTMLKit/HTMLParser.m
@@ -17,6 +17,11 @@
#import "HTMLMarker.h"
#import "NSString+HTMLKit.h"
+
+@interface HTMLDocument (Private)
+@property (nonatomic, assign) HTMLDocumentReadyState readyState;
+@end
+
@interface HTMLParser ()
{
HTMLTokenizer *_tokenizer;
@@ -242,6 +247,9 @@
- (id)parse
{
for (HTMLToken *token in _tokenizer) {
+ if (_document.readyState == HTMLDocumentComplete) {
+ break;
+ }
[self processToken:token];
}
return nil;
@@ -340,7 +348,7 @@
- (void)stopParsing
{
[_stackOfOpenElements popAll];
-#warning Finalize
+ _document.readyState =HTMLDocumentComplete;
}
#pragma mark -