Skip to content

Conversation

jackhp95
Copy link

This API aims to conform to the HTML 5 specification, and does a perfect job of that.

However, the toVirtualDom function will break because setAttribute and HTML 5 follow different specs.

This PR proposes this change to avoid runtime exceptions in the Elm runtime. https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute

Ideally, elm/virtual-dom would skip adding the attribute or filter the invalid characters, but that's a bigger ask.

Feel free to reject this PR, but I did want to float the idea.

This API aims to conform to the HTML 5 specification, and does a perfect job of that.

However, the [toVirtualDom](https://package.elm-lang.org/packages/hecrj/html-parser/latest/Html-Parser-Util#toVirtualDom) function will break because `setAttribute` and HTML 5 follow different specs.

This PR proposes this change to avoid runtime exceptions in the Elm runtime.
https://developer.mozilla.org/en-US/docs/Web/API/Element/setAttribute

Ideally, `elm/virtual-dom` would skip adding the attribute or filter the invalid characters, but that's a bigger ask.

Feel free to reject this PR, but I did want to float the idea.
@hecrj
Copy link
Owner

hecrj commented Jul 11, 2025

I think it makes more sense to have this as a different "sanitization" step after parsing; rather than adapting the parsing logic itself. Maybe a Util.sanitize function of some sort?

@jackhp95
Copy link
Author

Agreed, I like that idea!

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.

2 participants