Skip to content

RFE: parser option to report ignored and inserted tags #845

@vassudanagunta

Description

@vassudanagunta

I understand why htmlparser2 gracefully handles malformed HTML, automatically closing unclosed tags and skipping extraneous close tags: because that is how browsers handle it and it is even part of the HTML spec.

But there are use cases where one needs to know that these things are happening. For example I am using the parser as a tool that does some validation and reformatting. I want to know that a tag wasn't closed, or that a close was inserted because it was missing.

Would you be open to an option wherein those events are reported?

For example, there could be a strict mode, which would report these events via onerror or a separate handler callback, OR as follows:

  • in strict mode, onclosetag is called for all closing tags, including skipped ones.
  • when onclosetag is called, it includes an additional arg indicating if the tag was skipped or inserted.

This would be backward compatible, and would not affect performance when disabled.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions