tyxml icon indicating copy to clipboard operation
tyxml copied to clipboard

option element in datalist is wrong

Open Julow opened this issue 5 years ago • 4 comments

I get Error: option should have exactly one child for

<datalist>
	<option value="foo"></option>
</datalist>

Also, if I don't close the option tag (like here), I get a strange error, which I guess is because it put the newline inside option instead of datalist

Julow avatar Dec 17 '18 18:12 Julow

Unclosed elements like in your link are improper HTML and only work because of sloppy parsing. In general, you should avoid w3school, it's not a good source, prefer MDN.

As for datalist, I think that's a new instance of whitespaces!

Drup avatar Dec 18 '18 08:12 Drup

I don't think its a problem with whitespace. I think it's because it interprets the option tag as if it's in a select (or optgroup) which require some text. option in a datalist doesn't require a body.

I agree with you that it is not important to handle every special case in the ppx, as a user I'll understand.

MDN also do not close option tags, should markup handle this case ? It is not very important here but this case might happen in real websites.

Julow avatar Dec 19 '18 09:12 Julow

I see. We should definitely handle that. The smart constructors in the ppx are made in a way that should allow us to handle that, even if it might be a bit annoying.

The parsing aspect is handled by markup, so I'll let @aantron handle it.

Drup avatar Dec 19 '18 10:12 Drup

Markup.ml is doing the right thing. I added two tests, for unclosed <option> in <datalist> with and without whitespace: https://github.com/aantron/markup.ml/blob/c0085e432699c5a0208858850824f8e9ab7f83c6/test/test_html_parser.ml#L448-L479.

aantron avatar Jan 11 '19 22:01 aantron