diff --git a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp
index 6e917766d7..821ee3fc4e 100644
--- a/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp
+++ b/Libraries/LibWeb/Parser/HTMLDocumentParser.cpp
@@ -945,8 +945,13 @@ void HTMLDocumentParser::handle_in_body(HTMLToken& token)
}
if (token.is_start_tag() && token.tag_name() == "a") {
- if (m_list_of_active_formatting_elements.last_element_with_tag_name_before_marker("a")) {
- TODO();
+ if (auto* element = m_list_of_active_formatting_elements.last_element_with_tag_name_before_marker("a")) {
+ PARSE_ERROR();
+ run_the_adoption_agency_algorithm(token);
+ m_list_of_active_formatting_elements.remove(*element);
+ m_stack_of_open_elements.elements().remove_first_matching([&](auto& entry) {
+ return entry.ptr() == element;
+ });
}
reconstruct_the_active_formatting_elements();
auto element = insert_html_element(token);
diff --git a/Libraries/LibWeb/Parser/StackOfOpenElements.h b/Libraries/LibWeb/Parser/StackOfOpenElements.h
index e7637c5855..d6dbd18d27 100644
--- a/Libraries/LibWeb/Parser/StackOfOpenElements.h
+++ b/Libraries/LibWeb/Parser/StackOfOpenElements.h
@@ -57,6 +57,7 @@ public:
bool contains(const Element&) const;
const NonnullRefPtrVector& elements() const { return m_elements; }
+ NonnullRefPtrVector& elements() { return m_elements; }
void pop_until_an_element_with_tag_name_has_been_popped(const FlyString&);