From f05ddd5a512b848140e501679d37d937bf574fc8 Mon Sep 17 00:00:00 2001 From: iska Date: Sun, 1 Mar 2015 03:29:37 +0100 Subject: [PATCH] Add Parser methods for creating and inserting elements for given tokens https://html.spec.whatwg.org/multipage/syntax.html#create-an-element-for-the-token https://html.spec.whatwg.org/multipage/syntax.html#insert-an-html-element --- HTMLKit/HTMLParser.m | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/HTMLKit/HTMLParser.m b/HTMLKit/HTMLParser.m index 5db0831..3489116 100644 --- a/HTMLKit/HTMLParser.m +++ b/HTMLKit/HTMLParser.m @@ -382,6 +382,25 @@ [parent appendChildNode:comment]; } +#pragma mark - Elements + +- (HTMLElement *)createElementForToken:(HTMLTagToken *)token inNamespace:(HTMLNamespace)namespace +{ + HTMLElement *element = [[HTMLElement alloc] initWithTagName:token.tagName + attributes:token.attributes + namespace:namespace]; + return element; +} + +- (HTMLElement *)insertElementForToken:(HTMLTagToken *)token +{ + HTMLElement *element = [self createElementForToken:token inNamespace:HTMLNamespaceHTML]; + HTMLNode *adjustedInsertionLocation = [self appropriatePlaceForInsertingANodeWithOverrideTarget:element]; + [adjustedInsertionLocation appendChildNode:element]; + [_stackOfOpenElements addObject:element]; + return element; +} + #pragma mark - Insertion Modes - (void)HTMLInsertionModeInitial:(HTMLToken *)token