yew-macro: Make self-closing slash optional for void elements

Created on 2 Mar 2020  路  4Comments  路  Source: yewstack/yew

Problem
Void Elements

From https://html.spec.whatwg.org/multipage/syntax.html#start-tags:

Then, if the element is one of the void elements, or if the element is a foreign element, then there may be a single U+002F SOLIDUS character (/). This character has no effect on void elements, but on foreign elements it marks the start tag as self-closing.

The "/" of <br/> is optional per the spec however Yew's html! macro requires it.

Questionnaire

  • [ ] I'm interested in fixing this myself but don't know where to start
  • [ ] I would like to fix and I have a solution
  • [x] I don't have time to fix this right now, but maybe later
feature

Most helpful comment

From the specification you're linking, the void elements are the following:

Void elements
area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr

Personally, I'm not a big fan of allowing this, because it looks to me that it's pure laziness that became standard. IMO implementing this would complicate the html! macro implementation. But I think that printing helpful error in the case of unclosed void elements could be a pragmatic and easy solution. What do you think @kellytk?

All 4 comments

From the specification you're linking, the void elements are the following:

Void elements
area, base, br, col, embed, hr, img, input, link, meta, param, source, track, wbr

Personally, I'm not a big fan of allowing this, because it looks to me that it's pure laziness that became standard. IMO implementing this would complicate the html! macro implementation. But I think that printing helpful error in the case of unclosed void elements could be a pragmatic and easy solution. What do you think @kellytk?

@totorigolo

Personally, I'm not a big fan of allowing this, because it looks to me that it's pure laziness that became standard.

As I understand it, XHTML was oriented toward XML and HTML5(tm) is oriented toward SGML, wherein subtle differences in void and element closing exist. https://stackoverflow.com/a/3558200 is a primer. Irrespective, questioning the spec is out of scope here at least for myself.

I don't know if the intent of the html! macro is to completely conform to the HTML spec. I would defer to documentation or a comment by @jstarry. If complete conformance is the intent, a fix should be implemented, otherwise whatever the intent of the macro is should guide how the issue is addressed.

A more helpful error message would be appreciated.

We can revisit the trailing slash issue later I think.

For now, we should not allow void elements to have children. We can compile time check this with the proc macro.

Related: #1217

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DenisKolodin picture DenisKolodin  路  5Comments

sackery picture sackery  路  3Comments

thienpow picture thienpow  路  5Comments

Boscop picture Boscop  路  4Comments

agausmann picture agausmann  路  3Comments