Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(html): Handle mismatched tags #14

Merged
merged 1 commit into from
Jul 20, 2023
Merged

Conversation

James-LG
Copy link
Owner

  • Adds an extension point for handling mismatched tags in malformed HTML
  • Adds several mismatched tag handlers
  • Implements Display on HtmlDocument

Fixes #13

Comment on lines +38 to +72
pub struct ParseOptionsBuilder {
reducers: Vec<Box<dyn FnOnce(ParseOptions) -> ParseOptions>>,
}

impl ParseOptionsBuilder {
/// Creates a new [ParseOptionsBuilder].
pub fn new() -> Self {
Self {
reducers: Vec::new(),
}
}

/// Set the type of [MismatchedTagHandler] the parser should use.
pub fn with_mismatched_tag_handler(mut self, handler: Box<dyn MismatchedTagHandler>) -> Self {
let reducer = |options| ParseOptions {
mismatched_tag_handler: handler,
..options
};
self.reducers.push(Box::new(reducer));
self
}

/// Build the [ParseOptions].
pub fn build(self) -> ParseOptions {
self.reducers
.into_iter()
.fold(ParseOptions::new(), |options, f| f(options))
}
}
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order of builder method calls in maintained with self.reducers.

src/html/mod.rs Outdated

match html_node {
HtmlNode::Tag(tag) => {
// TODO: Deal with auto-closed tags like <br>
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: Still some TODOs lurking

@James-LG James-LG force-pushed the jameslg/malformed_handler branch from 49d022a to ffac82f Compare July 20, 2023 00:13
- Adds an extension point for handling mismatched tags in malformed HTML
- Adds several mismatched tag handlers
- Implements Display on HtmlDocument
@James-LG James-LG force-pushed the jameslg/malformed_handler branch from ffac82f to 2fc5295 Compare July 20, 2023 00:23
@James-LG James-LG merged commit e426eb2 into master Jul 20, 2023
@James-LG James-LG deleted the jameslg/malformed_handler branch July 20, 2023 00:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTML document parsing should handle malformed input
1 participant