denoland / denoland/std

@std/xml: support a "lax-mode" to allow parsing html

Open
#7,212 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
3.6k
Forks
681
PR merge metrics
No merged PRs in 30d

Description

XML is basically a stricter version of HTML, so most of the work is already done and it shouldn't require too much refactoring

Parsing HTML is a quite common use case (like when scraping websites, parsing web pages, etc) but since the data is external we can't expect them to be exact html

Parsing html without requiring a full virtual dom library (like jsdom / happy-dom /linked-dom) would be quite nice for general use case, but also for tests validations when testing http documents serves

There are already precedent of having a more leniant parsing in other libs
- quick-xml (Rust): check_end_names(false)
- libxml2 XML_PARSE_RECOVER / lxml recover=True
- htmlparser2 and fast-xml-parser in the JS ecosystem
- [`jsr:@libs/xml`](https://jsr.io/@libs/xml) (which i maintain and like to rely on `@std/xml` now rather than a compiled wasm version of quick-xml)

What would be required:
- Supporting unquoted attribute values: `` (value ends at whitespace, `>`, or `/`)
- Valueless attributes `` (same as `disabled=""`)
- Unclosed / mismatched elements: `` auto-closes intervening open elements (stray closing tags are ignored, elements still open at EOF are auto-closed instead of throwing)
- Duplicate attributes: first occurrence wins instead of throwing.

Btw the sync parse does not offer any way to recover the xml processing instructions nor the doctype atm

cc @tomas-zijdemans

Contributor guide

Open the contributing guide

Research direction

Start by reading the @std/xml parser entry point and tracing its current strict handling of attributes, closing tags, and duplicate attributes. Done means a lax mode supports the four listed recovery behaviors, while preserving strict parsing when lax mode is not enabled.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
data
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.