From 7717cb74726fc128732f7ba0d7d1efb647872679 Mon Sep 17 00:00:00 2001 From: iska Date: Sat, 28 Feb 2015 01:03:02 +0100 Subject: [PATCH] Add implementation for the parser's Initial Insertion Mode https://html.spec.whatwg.org/multipage/syntax.html#the-initial-insertion-mode --- HTMLKit/HTMLParser.m | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/HTMLKit/HTMLParser.m b/HTMLKit/HTMLParser.m index b01eb36..58d5450 100644 --- a/HTMLKit/HTMLParser.m +++ b/HTMLKit/HTMLParser.m @@ -347,7 +347,47 @@ - (void)HTMLInsertionModeInitial:(HTMLToken *)token { + switch (token.type) { + case HTMLTokenTypeCharacter: + { + if ([token.asCharacterToken isWhitespaceToken]) { + return; + } + break; + } + case HTMLTokenTypeComment: + { + [self insertComment:token.asCommentToken asChildOfNode:_document]; + return; + } + case HTMLTokenTypeDoctype: + { + HTMLDOCTYPEToken *doctypeToken = token.asDoctypeToken; + HTMLDocumentType *doctype = [[HTMLDocumentType alloc] initWithName:doctypeToken.name + publicIdentifier:doctypeToken.publicIdentifier + systemIdentifier:doctypeToken.systemIdentifier]; + + if (!doctype.isValid) { + [self emitParseError:@"Invalid DOCTYPE"]; + } + + _document.documentType = doctype; + _document.quirksMode = doctype.quirksMode; + + if (doctypeToken.forceQuirks) { + _document.quirksMode = HTMLQuirksModeQuirks; + } + [self switchInsertionMode:HTMLInsertionModeBeforeHTML]; + return; + } + default: + break; + } + +#warning Check "iframe srcdoc" + [self switchInsertionMode:HTMLInsertionModeBeforeHTML]; + [self reprocessToken:token]; } - (void)HTMLInsertionModeBeforeHTML:(HTMLToken *)token