tyxml icon indicating copy to clipboard operation
tyxml copied to clipboard

Maps are not supported.

Open shepard8 opened this issue 7 years ago • 5 comments

Trying to implement the following example from the W3C HTML5 specification: https://www.w3.org/TR/2011/WD-html5-20110525/the-map-element.html#authoring, I stumbled upon several problems.

First, as I discovered it by accident, map [map []] won't compile while the map (TyXML HTML) element is a transparent element.

Second, the alt attribute of the area (TyXML HTML) element is mandatory in HTML5, while it must be omitted when there is no Href attribute.

Third, in TyXML href is not a valid attribute of the area element (As I am the first to report it, I guess no one ever used a map using TyXML 🦉)

Fourth, in TyXML, area is not a valid element within a map element.

Fifth, in TyXML, usemap is not a valid attribute of the img (TyXML HTML) element.

In the following, uncommenting any of the commented regions breaks compilability (does this word exist? 😛)

open Tyxml.Html

let mypage =
  html
    (head (title (pcdata "hey")) [])
    (body [
      img
        ~src:(uri_of_string "shapes.png")
        ~alt:"Four shapes are available: a red hollow box, a green circle, a blue triangle, and a yellow four-pointed star."
        ~a:[(* a_usemap "shapes" *)] ();
      map ~a:[a_name "shapes"] [
        (* map []; *)
        (* area (); *)
        (* area ~a:[a_shape `Rect; a_coords [50; 50; 100; 100]] (); *)
        (* area ~alt:"" ~a:[a_shape `Rect; a_coords [25; 25; 125; 125]; a_href (uri_of_string "red.html")] (); *)
      ];
    ])

shepard8 avatar Jul 26 '17 06:07 shepard8

I have a "maps" branch in which almost all of the above is fixed, except for the following strange thing in the HTML specification:

  • map element is transparent;
  • area elements are allowed as descendants of map only.

That is, area elements are allowed nowhere, because the document should be correct without the <map> and </map> tags.

So map has a special state of "semi-transparent" element. I don't really know what to do ^^

I guess that the good way of handling that would be to consider `Map as a special type of transparent element (thus adding a new type of transparent elements, which do not really enforce HTML correctness as stated in the comments of Html_sigs.T). This seems much of a hassle.

The quick and dirty way would be to allow area anywhere where phrasing is legal and not only as descendants of map elements.

I like neither of these solutions. Any thoughts? ^^

shepard8 avatar Jul 26 '17 08:07 shepard8

Nice work! Unless we find a good way to encode the property "area is only allowed in map" that does not make typing of other elements more complex, I think it's not worth the effort. Map is almost never used in modern web programming anyway.

Area are allowed as indirect descendants of map, right ? Not only children ?

Drup avatar Jul 26 '17 08:07 Drup

Yes that's right.

So you suggest adding `Area in the phrasing type?

I agree that maps are almost not used, but I guess it is not our role to decide what to allow developers to use and what to forbid ^^

shepard8 avatar Jul 26 '17 08:07 shepard8

Oh sure, we need to fix this. The question is how faithful to the spec we make the typing constraints. I will take a look at the spec in details later, but yes, area in phrasing sounds right given what you said.

Drup avatar Jul 26 '17 08:07 Drup

@shepard8 Sorry for the very long delay. Could you make a PR with all your changes ?

Drup avatar Nov 17 '17 13:11 Drup