Add "tree construction dispatcher" and token handling stub
https://html.spec.whatwg.org/multipage/syntax.html#tree-construction
This commit is contained in:
@@ -7,9 +7,11 @@
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "HTMLNamespaces.h"
|
||||
|
||||
@interface HTMLElement : NSObject
|
||||
|
||||
@property (nonatomic, strong, readonly) NSString *tagName;
|
||||
@property (nonatomic, assign, readonly) HTMLNamespace namespace;
|
||||
|
||||
@end
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
//
|
||||
// HTMLElementTypes.h
|
||||
// HTMLKit
|
||||
//
|
||||
// Created by Iska on 19/02/15.
|
||||
// Copyright (c) 2015 BrainCookie. All rights reserved.
|
||||
//
|
||||
|
||||
#import "HTMLElement.h"
|
||||
#import "HTMLNamespaces.h"
|
||||
|
||||
#define matches(x, ...) [[NSSet setWithObjects:__VA_ARGS__, nil] containsObject:x]
|
||||
|
||||
NS_INLINE BOOL IsNodeMathMLTextIntegrationPoint(HTMLElement *node)
|
||||
{
|
||||
return (node.namespace == HTMLNamespaceMathML && matches(node.tagName, @"mi", @"mo", @"mn", @"ms", @"mtext"));
|
||||
}
|
||||
|
||||
NS_INLINE BOOL IsNodeHTMLIntegrationPoint(HTMLElement *node)
|
||||
{
|
||||
if (node.namespace == HTMLNamespaceMathML && [node.tagName isEqualToString:@"annotation-xml"]) {
|
||||
#warning Implement HTML Element Attributes
|
||||
} else if (node.namespace == HTMLNamespaceSVG) {
|
||||
return matches(node.tagName, @"foreignObject", @"desc", @"title");
|
||||
}
|
||||
return NO;
|
||||
}
|
||||
@@ -24,4 +24,64 @@
|
||||
|
||||
@implementation HTMLParser
|
||||
|
||||
#pragma mark - Parse
|
||||
|
||||
- (id)parse
|
||||
{
|
||||
for (HTMLToken *token in _tokenizer) {
|
||||
[self handleToken:token];
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)handleToken:(HTMLToken *)token
|
||||
{
|
||||
BOOL (^ treeConstructionDispatcher)(HTMLElement *node) = ^BOOL(HTMLElement *node){
|
||||
|
||||
if (node == nil) {
|
||||
return YES;
|
||||
}
|
||||
if (node.namespace == HTMLNamespaceHTML) {
|
||||
return YES;
|
||||
}
|
||||
if (IsNodeMathMLTextIntegrationPoint(node)) {
|
||||
if (token.type == HTMLTokenTypeStartTag) {
|
||||
return !matches([(HTMLStartTagToken *)token tagName], @"mglyph", @"malignmark");
|
||||
}
|
||||
if (token.type == HTMLTokenTypeCharacter) {
|
||||
return YES;
|
||||
}
|
||||
}
|
||||
if (node.namespace == HTMLNamespaceMathML && [node.tagName isEqualToString:@"annotation-xml"]) {
|
||||
if (token.type == HTMLTokenTypeStartTag) {
|
||||
return [[(HTMLStartTagToken *)token tagName] isEqualToString:@"svg"];
|
||||
}
|
||||
}
|
||||
if (IsNodeHTMLIntegrationPoint(node)) {
|
||||
return token.type == HTMLTokenTypeStartTag || token.type == HTMLTokenTypeCharacter;
|
||||
}
|
||||
if (token.type == HTMLTokenTypeEOF) {
|
||||
return YES;
|
||||
}
|
||||
|
||||
return NO;
|
||||
};
|
||||
|
||||
if (treeConstructionDispatcher(self.adjustedCurrentNode)) {
|
||||
[self handleToken:token byApplyingRulesForInsertionMode:_insertionMode];
|
||||
} else {
|
||||
[self handleTokenByApplyingRulesForParsingTokensInForeignContent:token];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)handleToken:(HTMLToken *)token byApplyingRulesForInsertionMode:(HTMLInsertionMode)insertionMode
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
- (void)handleTokenByApplyingRulesForParsingTokensInForeignContent:(HTMLToken *)token
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user