ocsigen / tyxml

Build valid HTML and SVG documents
https://ocsigen.org/tyxml/
Other
166 stars 62 forks source link

`div` should be allowed within `th` #252

Closed thizanne closed 4 years ago

thizanne commented 4 years ago

This is reported by IRC user "Nikkel".

# let foo = Tyxml_html.(td [div []]);;
val foo : [> Html_types.td ] Html.elt = <abstr>

# let fail = Tyxml_html.(th [div []]);;
Line 1, characters 26-32:
Error: This expression has type ([> Html_types.div ] as 'a) elt
       but an expression was expected of type
         ([< Html_types.th_content_fun ] as 'b) elt
       Type 'a = [> `Div ] is not compatible with type
         'b =
           [< `A of Html_types.phrasing_without_interactive
            | `Abbr
            (* SNIP *)
            | `Wbr ] 
       The second variant type does not allow tag(s) `Div

Minimal document for testing with https://validator.w3.org/ :

<!doctype html>
<html lang="fr">
  <head><title> foo </title></head>
  <body>
    <table>
      <tr>
        <th>
          <div> foo </div>
        </th>
        <td>
          <div> foo </div>
         </td>
      </tr>
    </table>
  </body>
</html>
thizanne commented 4 years ago

Relevant standard link: https://html.spec.whatwg.org/multipage/tables.html#the-th-element

div is in "Flow content" (and not in any exception listed). Note that I didn't check any other element or the code, so this bug might very well be broader than just div.