Skip to content

Commit

Permalink
Finalize parsing for <ruby> elements in the HTML Parser
Browse files Browse the repository at this point in the history
  • Loading branch information
iabudiab committed Dec 23, 2015
1 parent 572918e commit 6c28dad
Showing 2 changed files with 16 additions and 19 deletions.
23 changes: 16 additions & 7 deletions HTMLKit/HTMLParser.m
Original file line number Diff line number Diff line change
@@ -519,7 +519,7 @@ - (void)reconstructActiveFormattingElements

- (void)generateImpliedEndTagsExceptForElement:(NSString *)tagName
{
while ([self.currentNode.tagName isEqualToAny:@"dd", @"dt", @"li", @"option", @"optgroup", @"p", @"rp", @"rt", nil] &&
while ([self.currentNode.tagName isEqualToAny:@"dd", @"dt", @"li", @"option", @"optgroup", @"p", @"rb", @"rp", @"rt", @"rtc", nil] &&
![self.currentNode.tagName isEqualToString:tagName]) {
[_stackOfOpenElements popCurrentNode];
}
@@ -528,7 +528,7 @@ - (void)generateImpliedEndTagsExceptForElement:(NSString *)tagName
- (void)generateAllImpliedEndTagsThoroughly
{
while ([self.currentNode.tagName isEqualToAny:@"caption", @"colgroup", @"dd", @"dt", @"li", @"option", @"optgroup", @"p",
@"rp", @"rt", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", nil]) {
@"rb", @"rp", @"rt", @"rtc", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", nil]) {
[_stackOfOpenElements popCurrentNode];
}
}
@@ -1158,8 +1158,8 @@ - (void)HTMLInsertionModeInBody:(HTMLToken *)token
[self HTMLInsertionModeInTemplate:token];
} else {
for (HTMLElement *node in _stackOfOpenElements) {
if ([node.tagName isEqualToAny:@"dd", @"dt", @"li", @"optgroup", @"option", @"p", @"rp"
@"rt", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", @"body", @"html", nil]) {
if ([node.tagName isEqualToAny:@"dd", @"dt", @"li", @"optgroup", @"option", @"p", @"rb", @"rp",
@"rt", @"rtc", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", @"body", @"html", nil]) {
[self emitParseError:@"EOF reached with unclosed element <%@> in <body>", node.tagName];
break;
}
@@ -1462,14 +1462,23 @@ - (void)processStartTagTokenInBody:(HTMLStartTagToken *)token
}
[self reconstructActiveFormattingElements];
[self insertElementForToken:token];
} else if ([tagName isEqualToAny:@"rp", @"rt", nil]) {
} else if ([tagName isEqualToAny:@"rb", @"rtc", nil]) {
if ([_stackOfOpenElements hasElementInScopeWithTagName:@"ruby"]) {
[self generateImpliedEndTagsExceptForElement:nil];
if (![self.currentNode.tagName isEqualToString:@"ruby"]) {
[self emitParseError:@"Unexpected start tag <%@> outside of <ruby> in <body>", tagName];
}
}
[self insertElementForToken:token];
} else if ([tagName isEqualToAny:@"rp", @"rt", nil]) {
if ([_stackOfOpenElements hasElementInScopeWithTagName:@"ruby"]) {
[self generateImpliedEndTagsExceptForElement:@"rtc"];
if (![self.currentNode.tagName isEqualToString:@"rtc"] &&
![self.currentNode.tagName isEqualToString:@"ruby"]) {
[self emitParseError:@"Unexpected start tag <%@> outside of <ruby> or <rtc> in <body>", tagName];
}
}
[self insertElementForToken:token];
} else if ([tagName isEqualToString:@"math"]) {
[self reconstructActiveFormattingElements];
AdjustMathMLAttributes(token);
@@ -1507,8 +1516,8 @@ - (void)processEndTagTokenInBody:(HTMLEndTagToken *)token
[self emitParseError:@"Unexpected end tag </body> without body element in scope in <body>"];
}
for (HTMLElement *node in _stackOfOpenElements) {
if ([node.tagName isEqualToAny:@"dd", @"dt", @"li", @"optgroup", @"option", @"p", @"rp"
@"rt", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", @"body", @"html", nil]) {
if ([node.tagName isEqualToAny:@"dd", @"dt", @"li", @"optgroup", @"option", @"p", @"rb", @"rp", @"rt",
@"rtc", @"tbody", @"td", @"tfoot", @"th", @"thead", @"tr", @"body", @"html", nil]) {
[self emitParseError:@"Misnested end tag </%@> with open element <%@> in <body>", tagName, node.tagName];
break;
}
12 changes: 0 additions & 12 deletions HTMLKitTests/HTML5LibTreeConstructionTest.m
Original file line number Diff line number Diff line change
@@ -33,12 +33,6 @@ + (NSDictionary *)loadHTML5LibTreeConstructionTests
continue;
}

if ([testFile hasPrefix:@"ruby"]) {
// <ruby> and friends are not yet completely supported
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=26189
continue;
}

NSString *testFilePath = [path stringByAppendingPathComponent:testFile];
NSArray *tests = [HTML5LibTreeConstructionTest loadTestsWithFileAtPath:testFilePath];
[testsMap setObject:tests forKey:testFile];
@@ -74,12 +68,6 @@ + (NSArray *)loadTestsWithFileAtPath:(NSString *)filePath
HTML5LibTreeConstructionTest *test = [HTML5LibTreeConstructionTest new];
test.testFile = filePath.lastPathComponent;

if ([rawTest rangeOfString:@"ruby"].location != NSNotFound) {
// <ruby> and friends are not yet completely supported
// https://www.w3.org/Bugs/Public/show_bug.cgi?id=26189
continue;
}

if ([rawTest rangeOfString:@"#script-off"].location != NSNotFound) {
// Ignore tests for "scripting flag disabled" case
continue;

0 comments on commit 6c28dad

Please sign in to comment.