Add "Noah's Ark Clause", three per family, to the list of active formatting elements

When adding new elements to the list, if there are already three same elements present, then remove
the oldest one before inserting the new.
This commit is contained in:
iska
2015-04-05 13:30:34 +02:00
parent a62ccfdc51
commit c369abbfee
@@ -45,6 +45,21 @@
- (void)addElement:(HTMLElement *)element
{
NSUInteger existing = 0;
for (HTMLElement *node in _list.reverseObjectEnumerator.allObjects) {
if ([node isEqual:[HTMLMarker marker]]) {
break;
}
if (node.namespace == element.namespace &&
[node.tagName isEqualToString:element.tagName] &&
[node.attributes isEqualTo:element.attributes]) {
existing++;
}
if (existing == 3) {
[_list removeObject:node];
break;
}
}
[_list addObject:element];
}