-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
html2: Improve support for parsing <table> elements
- Loading branch information
1 parent
949edf6
commit 265f154
Showing
5 changed files
with
176 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <[email protected]> | ||
// SPDX-FileCopyrightText: 2023-2025 Robin Lindén <[email protected]> | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
|
@@ -49,6 +49,18 @@ class Actions : public html2::IActions { | |
}(); | ||
} | ||
|
||
html2::QuirksMode quirks_mode() const override { | ||
switch (document_.mode) { | ||
case dom::Document::Mode::NoQuirks: | ||
return html2::QuirksMode::NoQuirks; | ||
case dom::Document::Mode::Quirks: | ||
return html2::QuirksMode::Quirks; | ||
case dom::Document::Mode::LimitedQuirks: | ||
return html2::QuirksMode::LimitedQuirks; | ||
} | ||
return html2::QuirksMode::LimitedQuirks; | ||
} | ||
|
||
bool scripting() const override { return scripting_; } | ||
|
||
void insert_element_for(html2::StartTagToken const &token) override { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <[email protected]> | ||
// SPDX-FileCopyrightText: 2023-2025 Robin Lindén <[email protected]> | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
|
@@ -31,6 +31,7 @@ class IActions { | |
|
||
virtual void set_doctype_name(std::string) = 0; | ||
virtual void set_quirks_mode(QuirksMode) = 0; | ||
virtual QuirksMode quirks_mode() const = 0; | ||
virtual bool scripting() const = 0; | ||
virtual void insert_element_for(html2::StartTagToken const &) = 0; | ||
virtual void pop_current_node() = 0; | ||
|
@@ -59,13 +60,13 @@ class IActions { | |
template<auto const &scope_elements> | ||
bool has_element_in_scope_impl(std::string_view element_name) const { | ||
for (auto const element : names_of_open_elements()) { | ||
if (is_in_array<scope_elements>(element)) { | ||
return false; | ||
} | ||
|
||
if (element == element_name) { | ||
return true; | ||
} | ||
|
||
if (is_in_array<scope_elements>(element)) { | ||
return false; | ||
} | ||
} | ||
|
||
return false; | ||
|
@@ -97,6 +98,11 @@ class IActions { | |
|
||
return has_element_in_scope_impl<kScopeElements>(element_name); | ||
} | ||
|
||
bool has_element_in_table_scope(std::string_view element_name) const { | ||
static constexpr auto kScopeElements = std::to_array<std::string_view>({"html", "table", "template"}); | ||
return has_element_in_scope_impl<kScopeElements>(element_name); | ||
} | ||
}; | ||
|
||
} // namespace html2 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// SPDX-FileCopyrightText: 2023-2024 Robin Lindén <[email protected]> | ||
// SPDX-FileCopyrightText: 2023-2025 Robin Lindén <[email protected]> | ||
// | ||
// SPDX-License-Identifier: BSD-2-Clause | ||
|
||
|
@@ -46,7 +46,7 @@ using InsertionMode = std::variant<Initial, | |
AfterHead, | ||
InBody, | ||
Text, | ||
// InTable, | ||
InTable, | ||
// InTableText, | ||
// InCaption, | ||
// InColumnGroup, | ||
|
@@ -63,7 +63,6 @@ using InsertionMode = std::variant<Initial, | |
// AfterAfterFrameset | ||
>; | ||
|
||
struct InTable {}; | ||
struct InTableText {}; | ||
struct InCaption {}; | ||
struct InColumnGroup {}; | ||
|
@@ -107,6 +106,10 @@ struct Text { | |
std::optional<InsertionMode> process(IActions &, html2::Token const &); | ||
}; | ||
|
||
struct InTable { | ||
std::optional<InsertionMode> process(IActions &, html2::Token const &); | ||
}; | ||
|
||
struct AfterBody { | ||
std::optional<InsertionMode> process(IActions &, html2::Token const &); | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters