Skip to content

feat: support self closing tags such as <p/> #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

berenddeboer
Copy link

Currently they lead to parser errors, but this is perfectly valid HTML.

Copy link
Owner

@hecrj hecrj left a comment

Choose a reason for hiding this comment

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

Hey, thanks!

I took a quick look when you opened the PR but I forgot to comment. Sorry!

Is this documented somewhere in the HTML 5 spec? I believe it mentions a self-closing slash is only allowed in void elements and foreign elements.

We already handle an optional slash in void elements here:

if isVoidElement name then
Parser.succeed (Element name attributes [])
|. Parser.oneOf
[ Parser.chompIf ((==) '/')
, Parser.succeed ()
]
|. Parser.chompIf ((==) '>')

@berenddeboer
Copy link
Author

Regardless whether it is allowed, it's pretty common! All browsers handle it. I would say html-parser probably should not try to be a validating parser, that's an entirely different thing. And besides the parser currently accepts many forms of HTML that are technically not valid.

is not a void element, so adding it to the void element list does not work. It can have many other tags.

@berenddeboer
Copy link
Author

Secondly if the output comes via XML (XHTML 5.0), this could easily be generated. I.e. it's perfectly valid xml.

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