From c369abbfeebd6607a3dc63b3b59e2e80c607d49a Mon Sep 17 00:00:00 2001 From: iska Date: Sun, 5 Apr 2015 13:30:34 +0200 Subject: [PATCH] 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. --- HTMLKit/HTMLListOfActiveFormattingElements.m | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/HTMLKit/HTMLListOfActiveFormattingElements.m b/HTMLKit/HTMLListOfActiveFormattingElements.m index 1a61c51..3088ce2 100644 --- a/HTMLKit/HTMLListOfActiveFormattingElements.m +++ b/HTMLKit/HTMLListOfActiveFormattingElements.m @@ -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]; }