Skip to content

Add support for Microdata #343

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

* Add support for the clip-path presentation attribute
(#333 by Martin @MBodin Bodin)
* Add support for Microdata attributes
(#343 by toastal)

# 4.6.0

Expand Down
16 changes: 16 additions & 0 deletions lib/html_f.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ struct

let uri_attrib a s = Xml.uri_attrib a s

let uris_attrib a ss = Xml.uris_attrib a ss

let space_sep_attrib = Xml.space_sep_attrib

let comma_sep_attrib = Xml.comma_sep_attrib
Expand Down Expand Up @@ -500,6 +502,18 @@ struct

let a_aria name = space_sep_attrib ("aria-" ^ name)

(* Microdata *)

let a_itemid = uri_attrib "itemid"

let a_itemprop = string_attrib "itemprop"

let a_itemref = space_sep_attrib "itemref"

let a_itemscope = constant_attrib "itemscope"

let a_itemtype = uris_attrib "itemtype"

type 'a elt = Xml.elt

type ('a, 'b) nullary = ?a: (('a attrib) list) -> unit -> 'b elt
Expand Down Expand Up @@ -858,6 +872,8 @@ struct

let uri_attrib a s = Xml.uri_attrib a s

let uris_attrib a ss = Xml.uris_attrib a ss

let space_sep_attrib = Xml.space_sep_attrib

let comma_sep_attrib = Xml.comma_sep_attrib
Expand Down
25 changes: 23 additions & 2 deletions lib/html_sigs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,24 @@ module type T = sig
@see <https://www.w3.org/TR/wai-aria-1.1/#state_prop_def> List of WAI-ARIA attributes
*)

(** {3 Microdata support} *)

(** {{: https://html.spec.whatwg.org/multipage/microdata.html} Microdata} is
a specification written by the W3C, defining a set of additional HTML
attributes that can be applied to elements to annotate content with
specific machine-readable labels using schemas.
*)

val a_itemid : Xml.uri wrap -> [> | `ItemID ] attrib

val a_itemprop : string wrap -> [> | `ItemProp ] attrib

val a_itemref : idrefs wrap -> [> | `ItemRef ] attrib

val a_itemscope : unit -> [> | `ItemScope ] attrib

val a_itemtype : Xml.uri list wrap -> [> | `ItemType ] attrib

(** {2:elements Elements} *)

val txt : string wrap -> [> | txt] elt
Expand Down Expand Up @@ -1169,10 +1187,13 @@ module type T = sig
(** Same, for URI attribute *)
val uri_attrib : string -> uri wrap -> 'a attrib

(** Same, for a space separated list of values *)
(** Same, for a space-separated list of URI attributes *)
val uris_attrib : string -> uri list wrap -> 'a attrib

(** Same, for a space-separated list of values *)
val space_sep_attrib : string -> string list wrap -> 'a attrib

(** Same, for a comma separated list of values *)
(** Same, for a comma-separated list of values *)
val comma_sep_attrib : string -> string list wrap -> 'a attrib

end
Expand Down
15 changes: 13 additions & 2 deletions lib/html_types.mli
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ type nmtoken = string
@see <http://www.w3.org/TR/2000/REC-xml-20001006> XML 1.0 *)

type nmtokens = nmtoken list
(** One or more white space separated NMTOKEN values *)
(** One or more whitespace-separated NMTOKEN values *)

(** {2 Data Types} *)

Expand Down Expand Up @@ -380,8 +380,19 @@ type aria =
| `Aria
]

(** {2 Microdata} *)

type microdata =
[
| `ItemID
| `ItemProp
| `ItemRef
| `ItemScope
| `ItemType
]

(** Common attributes *)
type common = [ | core | i18n | events | aria ]
type common = [ | core | i18n | events | aria | microdata ]

(** {1 Categories of HTML elements}

Expand Down
4 changes: 2 additions & 2 deletions lib/svg_sigs.mli
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,10 @@ module type T = sig
(** Same, for URI attribute *)
val uri_attrib : string -> uri wrap -> 'a attrib

(** Same, for a space separated list of values *)
(** Same, for a space-separated list of values *)
val space_sep_attrib : string -> string list wrap -> 'a attrib

(** Same, for a comma separated list of values *)
(** Same, for a comma-separated list of values *)
val comma_sep_attrib : string -> string list wrap -> 'a attrib

end
Expand Down
1 change: 1 addition & 0 deletions syntax/reflect/reflect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ let rec to_attribute_parser lang name ~loc = function
| [[%type: shape]] ->
[%expr variant]

| [[%type: Xml.uri list]]
| [[%type: nmtokens]]
| [[%type: idrefs]]
| [[%type: charsets]]
Expand Down
10 changes: 10 additions & 0 deletions test/test_ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,16 @@ let attribs = "ppx attribs", HtmlTests.make Html.[
[[%html "<div aria-hidden=true></div>"]],
[div ~a:[a_aria "hidden" ["true"]] []] ;

"microdata attributes",
[[%html "<dl itemscope itemtype='https://md.example.com/track https://md.example.com/lighting'><dt>Name</dt><dd itemprop='name'>Turnout Lantern Kit</dd></dl>"]],
[dl
~a:[a_itemscope (); a_itemtype ["https://md.example.com/track"; "https://md.example.com/lighting"]]
[
dt [ txt "Name" ];
dd ~a:[a_itemprop "name"] [ txt "Turnout Lantern Kit" ];
]] ;


"touch events",
[[%html "<div ontouchstart='alert()'></div>"]],
[div ~a:[a_ontouchstart "alert()"] []] ;
Expand Down