Skip to content

Complete HTML elements and attributes coverage (WHATWG living standard)#366

Open
balat wants to merge 24 commits into
masterfrom
html-completeness
Open

Complete HTML elements and attributes coverage (WHATWG living standard)#366
balat wants to merge 24 commits into
masterfrom
html-completeness

Conversation

@balat

@balat balat commented Jul 16, 2026

Copy link
Copy Markdown
Member

This PR brings TyXML up to date with the WHATWG HTML living standard. All changes are backward compatible, except two additions to the Wrapped_functions module type (noted below).

New elements

  • s, bdi, search (flow grouping content), data (with a mandatory ~value argument, following the img precedent)
  • track: void element with a mandatory ~src argument, plus its attributes a_kind, a_track_srclang (scoped rename of srclang for track) and a_default. audio and video gain an optional ?tracks argument mirroring ?srcs, and the PPX assembler partitions track children accordingly.
  • slot: transparent content model, encoded like canvas/map

selectedcontent is deliberately left out: typing the customizable select content model would weaken button typing globally while the spec is still evolving; it remains reachable through Unsafe.

New attributes

  • Global: popover (a bare popover parses as auto in the PPX), inert, enterkeyhint, autocapitalize, autocorrect, writingsuggestions, nonce, slot, is, and `Auto for a_dir
  • Microdata: itemscope, itemtype, itemid, itemprop, itemref
  • CSS Shadow Parts: part, exportparts
  • Buttons: popovertarget, popovertargetaction, and the Invoker Commands command/commandfor (custom --* commands via `Other, following the linktype design)
  • loading, decoding, fetchpriority (img; also link/script where specified), srcdoc and allow (iframe), as, imagesrcset, imagesizes, blocking, nomodule (link/script/style), ping (a/area), dirname and capture (form controls), type on ol (a_ol_type, case-sensitive values with a dedicated PPX parser), abbr on th, closedby on dialog, media on meta, playsinline, disablepictureinpicture, disableremoteplayback, and the declarative shadow DOM attributes on template (shadowrootmode etc.)
  • Some membership fixes for existing attributes where the spec allows them (crossorigin/usemap/referrerpolicy on img, referrerpolicy on a/area, autocomplete on select/textarea, disabled on link)

New event handler attributes

  • Pointer events, onwheel and onauxclick, typed with the existing Xml.mouse_event_handler (PointerEvent and WheelEvent inherit from MouseEvent in the DOM; adding dedicated handler types to Xml_sigs.T would break every Xml implementation)
  • 14 missing global handlers: onbeforeinput, onbeforematch, onbeforetoggle, oncancel, oncontextlost, oncontextrestored, oncopy, oncut, onpaste, oncuechange, onscrollend, onsecuritypolicyviolation, onslotchange, ontoggle
  • Window handlers on body: onlanguagechange, onrejectionhandled, onunhandledrejection

Compatibility notes

  • The Wrapped_functions module type gains string_of_blocking and string_of_ol_type. Implementations that delegate to Html_f.Wrapped_functions (e.g. js_of_ocaml-tyxml) are unaffected; hand-written ones need two delegation lines. This is called out in CHANGES.md.
  • Thanks to the signature reflection mechanism, the PPX and JSX pick up almost everything automatically; only four custom value parsers were added (popover, command, ol_type, blocking), each tested through both the [%html] and JSX front-ends.

Each addition comes with rendering tests (test_html.ml) and PPX round-trip tests (test_ppx.ml), a CHANGES.md entry, an MDN link in the documentation, and the spec link in its commit message.

balat added 23 commits July 16, 2026 12:11
Recent compilers in the dune development profile treat warning 67
(unused functor parameter) as an error, which breaks make build and
the CI on every platform. The parameters are only used for their
side effects on behavior, not in the result signatures, so they can
be anonymous.
The s element represents contents that are no longer accurate or
relevant. It is flow and phrasing content, with phrasing content
and common attributes.

Spec: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-s-element
The bdi element represents a span of text isolated from its
surroundings for the purposes of bidirectional text formatting.
It is flow and phrasing content, with phrasing content and common
attributes (the dir attribute is already available globally).

Spec: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-bdi-element
The search element represents a part of a document whose contents
relate to performing a search or filtering operation. It is flow
content containing flow content, with common attributes. It is
grouping content, not a sectioning element.

Spec: https://html.spec.whatwg.org/multipage/grouping-content.html#the-search-element
The data element links a content with a machine-readable value.
The value attribute is required by the specification, so it is
exposed as a mandatory labeled argument, following the img and
optgroup precedents.

Spec: https://html.spec.whatwg.org/multipage/text-level-semantics.html#the-data-element
The track element specifies timed text tracks for audio and video
elements. It is a void element with a required src attribute,
exposed as a mandatory labeled argument.

New attributes: a_kind, a_track_srclang and a_default. The existing
a_srclang function stays untouched (it is deprecated and wrongly
typed as XML_lang); a_track_srclang uses the reflect.attribute
renaming so that <track srclang=...> maps to it in the PPX.

audio and video accept a new optional ?tracks argument, mirroring
?srcs, so that track children do not leak into the transparent
content type parameter. The PPX assembler for audio and video
partitions track children into that argument.

Spec: https://html.spec.whatwg.org/multipage/media.html#the-track-element
The slot element (Web Components) defines a placeholder inside a
shadow tree. Its content model is transparent, so it uses the same
phantom type encoding as canvas and map: the children type is
carried in the type parameter and checked at the usage site.
The name attribute is provided by the existing a_name function.

Spec: https://html.spec.whatwg.org/multipage/scripting.html#the-slot-element
New global attributes, available on every element:
- popover (a_popover, values auto, manual, hint; a bare popover
  attribute parses as auto in the PPX)
- inert (a_inert)
- enterkeyhint (a_enterkeyhint)
- autocapitalize (a_autocapitalize)
- autocorrect (a_autocorrect, on/off boolean)
- writingsuggestions (a_writingsuggestions, true/false boolean)
- nonce (a_nonce)
- slot (a_slot)
- is (a_is)

Also allow the auto value for the dir attribute (a_dir and the
required dir argument of bdo).

Spec: https://html.spec.whatwg.org/multipage/interaction.html
and https://html.spec.whatwg.org/multipage/popover.html
New global attributes: itemscope (a_itemscope), itemtype
(a_itemtype), itemid (a_itemid), itemprop (a_itemprop) and
itemref (a_itemref).

Spec: https://html.spec.whatwg.org/multipage/microdata.html
These attributes expose shadow-tree parts to outside styling. They
are defined by the W3C CSS Shadow Parts specification (not by the
WHATWG HTML standard) but are global attributes implemented by all
browsers.

Spec: https://drafts.csswg.org/css-shadow-parts/
New attributes on button (and, for the popover ones, input):
- popovertarget (a_popovertarget) and popovertargetaction
  (a_popovertargetaction) to control popovers from a button
- command (a_command) and commandfor (a_commandfor), the Invoker
  Commands API; custom commands are expressed with the
  Other constructor of the new command_value type, following the
  linktype precedent

Spec: https://html.spec.whatwg.org/multipage/popover.html and
https://html.spec.whatwg.org/multipage/form-elements.html#attr-button-command
- loading (a_loading, lazy/eager) on img and iframe
- decoding (a_decoding, sync/async/auto) on img
- fetchpriority (a_fetchpriority, high/low/auto) on img (also used
  by link and script in a following commit)
- srcdoc (a_srcdoc) and allow (a_allow) on iframe
- also allow the existing crossorigin, usemap and referrerpolicy
  attributes on img, as specified

Spec: https://html.spec.whatwg.org/multipage/embedded-content.html
and https://html.spec.whatwg.org/multipage/urls-and-fetching.html
- as (a_as) on link, for preload destinations (the common subset
  documented by MDN; other destinations remain reachable with
  Unsafe.string_attrib)
- imagesrcset (a_imagesrcset) and imagesizes (a_imagesizes) on link
- blocking (a_blocking) on link, script and style, with a new
  blocking_token type and a new string_of_blocking function in the
  Wrapped_functions module type
- nomodule (a_nomodule) on script
- also allow disabled, referrerpolicy and fetchpriority on link and
  script where specified

Spec: https://html.spec.whatwg.org/multipage/semantics.html and
https://html.spec.whatwg.org/multipage/urls-and-fetching.html
Also allow the existing referrerpolicy attribute on a and area, as
specified.

Spec: https://html.spec.whatwg.org/multipage/links.html#ping
- dirname (a_dirname) on input and textarea
- capture (a_capture, user/environment) on input; this attribute is
  defined by the W3C HTML Media Capture specification
- also allow the existing autocomplete attribute on select and
  textarea, as specified

Spec: https://html.spec.whatwg.org/multipage/form-control-infrastructure.html
and https://www.w3.org/TR/html-media-capture/
- type (a_ol_type) on ordered lists, with a new ol_type value type
  and a new string_of_ol_type function in the Wrapped_functions
  module type; the values are case-sensitive so the PPX uses a
  dedicated parser
- abbr (a_abbr) on th cells
- closedby (a_closedby) on dialogs
- allow the existing media attribute on meta (theme-color)

Spec: https://html.spec.whatwg.org/multipage/grouping-content.html#attr-ol-type
- playsinline (a_playsinline) on video (WHATWG)
- disablepictureinpicture (a_disablepictureinpicture) on video
  (W3C Picture-in-Picture specification)
- disableremoteplayback (a_disableremoteplayback) on audio and video
  (W3C Remote Playback specification)

Spec: https://html.spec.whatwg.org/multipage/media.html
New attributes on template elements: shadowrootmode
(a_shadowrootmode, open/closed), shadowrootdelegatesfocus,
shadowrootclonable and shadowrootserializable.

Spec: https://html.spec.whatwg.org/multipage/scripting.html#the-template-element
New global event handler attributes: onauxclick, onwheel,
onpointercancel, onpointerdown, onpointerenter, onpointerleave,
onpointermove, onpointerout, onpointerover, onpointerup,
ongotpointercapture and onlostpointercapture.

In the DOM, PointerEvent and WheelEvent inherit from MouseEvent,
so these handlers use the existing Xml.mouse_event_handler type;
adding dedicated handler types to Xml_sigs.T would break every Xml
implementation and is left to a future breaking release.

Spec: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
and https://www.w3.org/TR/pointerevents/
New global event handler attributes: onbeforeinput, onbeforematch,
onbeforetoggle, oncancel, oncontextlost, oncontextrestored, oncopy,
oncut, onpaste, oncuechange, onscrollend,
onsecuritypolicyviolation, onslotchange and ontoggle.

They all use the generic Xml.event_handler type, following the
existing oninput and onchange precedents.

Spec: https://html.spec.whatwg.org/multipage/webappapis.html#globaleventhandlers
New attributes on body, following the onstorage and onpopstate
precedents: onlanguagechange, onrejectionhandled and
onunhandledrejection.

Spec: https://html.spec.whatwg.org/multipage/webappapis.html#windoweventhandlers
Exercise the popover, command, ol type and blocking parsers through
the JSX front-end, following the autocomplete precedent.
The purpose of bdo is to force an explicit text direction, and the
rendering of bdo is only defined for the ltr and rtl states, so keep
the required dir argument restricted to those two values. The global
a_dir function keeps accepting auto.
@balat

balat commented Jul 16, 2026

Copy link
Copy Markdown
Member Author

Note on CI: master's CI has been red for a while because recent compilers turn warning 67 (unused functor parameter) into an error in the dune development profile; the failures initially reported on this PR were exactly those pre-existing errors, not caused by these changes. The fix is in #366's sibling PR #367; this branch has been rebased on top of it so its CI can run green. Once #367 is merged, this branch can be rebased onto master and the extra commit will disappear from the diff.

The remaining (ubuntu-latest, 4.08) failure is unrelated infrastructure: the opam switch initialisation itself fails to solve ocaml-base-compiler for 4.08 with opam 2.5.2 (it fails on master too, before any tyxml code is built).

@balat
balat force-pushed the html-completeness branch from cc83c17 to b98df43 Compare July 16, 2026 10:14
- method and formmethod accept the dialog value
- the sandbox attribute gains the tokens added to the standard since
  the original set: allow-downloads, allow-modals,
  allow-orientation-lock, allow-popups-to-escape-sandbox,
  allow-presentation, allow-top-navigation-by-user-activation and
  allow-top-navigation-to-custom-protocols

Spec: https://html.spec.whatwg.org/multipage/form-submission.html#attr-fs-method
and https://html.spec.whatwg.org/multipage/iframe-embed-object.html#attr-iframe-sandbox
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant