pugjs/void-elements

menuitem is NOT self-closing

quangdaon opened this issue · 6 comments

This issue was originally brought up in the core Pug Repo

The menuitem tag (in reference to HTML5 context menus, in case this is used elsewhere), is not self-closing. Despite the inline content having no effect, needs a closing tag, and not having one messes up the HTML, causing menuitems, and possible other elements, to appear incorrectly.

https://w3c.github.io/html/syntax.html#void-elements seems to suggest that <menuitem> is a void element. https://developer.mozilla.org/en/docs/Web/HTML/Element/menuitem also states:

Permitted content None, it is an empty element.

However, their example:

<!-- A <div> element with a context menu -->
<div contextmenu="popup-menu">
  Right-click to see the adjusted context menu
</div>

<menu type="context" id="popup-menu">
  <menuitem type="checkbox" onclick="toggleOption()"
    checked="true">Checkbox</menuitem>
  <menuitem type="command" label="Command" icon="icon.png"
    onclick="doSomething()">Checkbox</menuitem>
  <menuitem type="radio" name="group1" onclick="option()"
    checked="true">Radio button 1</menuitem>
  <menuitem type="radio" name="group1"
    onclick="option()">Radio button 2</menuitem>
</menu>

Does clearly show content inside the <menuitem>.

Ultimately, the spec shows menuitem as void, and w3c/html#274 suggests that they are implemented as void in browsers. If you think this is incorrect, you should comment on w3c/html#274 to request that they update the spec. Alternatively, if the example is wrong, you should fix the example on https://developer.mozilla.org/en/docs/Web/HTML/Element/menuitem

Thank you for your efforts to get this issue resolved.

Actually, in the latest HTML Standard from WHATWG (https://html.spec.whatwg.org/multipage/syntax.html#void-elements), menuitem is not considered a void element, while the Editor's Draft from W3C (http://w3c.github.io/html/syntax.html#void-elements) does consider it such. Ultimately, this decision hinges on whether we want to use WHATWG's living standard, or published versions of W3C's, or the latest draft from W3C. I feel WHATWG's should be preferred.

or we could stick to a non-draft standard which would avoid discussion on the best draft source, and allow people to send their own void-element list as a config option - https://www.w3.org/TR/html51/syntax.html#void-elements. In this spec both keygen and menuitem are considered void-elements.

I distinctly remember one organisation as being the true source, and the other as essentially plagiarising an out of date and erroneous version of the HTML spec. It's important that we use the correct source. I have a feeling whatwg might be the correct source, but I think we'd better check. I've asked @domenic if he can tell me which one we should trust: https://twitter.com/ForbesLindesay/status/821670165158957059

Right, I've checked and https://html.spec.whatwg.org/multipage/syntax.html#void-elements is the correct spec. We should update void-elements to use that spec.

So, uh, we actually just made menuitem parse like span again: whatwg/html@0ca0377 sorry about that :-/