Hello, World!
-``` - -Webs: - -```ocaml -open Webs_html -open El -open At - -let greeting = p ~at:[class' "text-lg"; id "hello"] [txt "Hello, World!"] -``` - -Dream-html: - -```ocaml -open Dream_html -open Tag -open Attr - -let greeting = p[class_ "text-lg"; id "hello"][txt "Hello, World!"] -``` - -Note, this is not meant to be a demonstration of how many characters you're -saving. It's just a different style which I have found we can take advantage of -thanks to OCaml being whitespace-insensitive. Normally you wouldn't format OCaml -code like this, but I feel that the domain justifies it. - -## Details - -Attribute and text values are escaped using -[`Dream.html_escape`](https://aantron.github.io/dream/#val-html_escape): - -``` -utop # open Dream_html;; -utop # let user_input = "";; -utop # open Tag;; -utop # let safe = p[][txt "%s" user_input];; -utop # to_string safe;; -- : string = -"<script>alert('You have been pwned')</script>
" -``` - -## Usage - -A convenience is provided to respond with an HTML node from a handler: - -```ocaml -Dream_html.respond greeting -``` - -You can compose multiple HTML nodes together into a single node without an extra -DOM node, like [React fragments](https://react.dev/reference/react/Fragment): - -```ocaml -let view = Tag.null[ - p[][txt "Hello"]; - p[][txt "World"]] -``` - -You can do string interpolation using the `txt` node constructor and of any -attribute which takes a string value: - -```ocaml -let greet name = p[id "greet-%s" name][txt "Hello, %s!" name] -``` - -You can conditionally render an attribute, and -[void elements](https://developer.mozilla.org/en-US/docs/Glossary/Void_element) -are statically enforced as childless: - -```ocaml -let entry = input[ - if should_focus then autofocus else null; - id "email"; - name "email"; - value "Email address"] -``` - -You can also embed HTML comments in the generated document: - -```ocaml -div[][ - comment "TODO: xyz."; - p[][txt "Hello!"]] -``` - -## Explore in the REPL - -``` -$ utop -utop # #require "dream_html";; -utop # open Dream_html;; -utop # open Tag;; -utop # open Attr;; -utop # #install_printer pp;; -utop # p[class_ "hello"][txt "world"];; -- : node =world
-``` - -## Test - -Run the test and print out diff if it fails: - - dune runtest # Will also exit 1 on failure - -Set the new version of the output as correct: - - dune promote - -## Prior art/design notes - -Surface design obviously lifted straight from -[elm-html](https://package.elm-lang.org/packages/elm/html/latest/). - -Similar to [Webs](https://erratique.ch/software/webs/doc/Webs_html/index.html) as -mentioned earlier (it turns out there are only a limited number of ways to do -this kind of library). - -Implementation inspired by both elm-html and -[Scalatags](https://com-lihaoyi.github.io/scalatags/). diff --git a/dream-html/Dream_html/.dummy b/dream-html/Dream_html/.dummy deleted file mode 100644 index e69de29..0000000 diff --git a/dream-html/Dream_html/Aria/index.html b/dream-html/Dream_html/Aria/index.html index 7c76acf..70099a0 100644 --- a/dream-html/Dream_html/Aria/index.html +++ b/dream-html/Dream_html/Aria/index.html @@ -1,2 +1,2 @@ -Dream_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `polite ] to_attr
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
Dream_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `polite ] to_attr
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
Dream_html.Form
Typed, extensible HTML form decoder with error reporting for all form field validation failures.
See the bottom of the page for complete examples.
The type of a decoder for a single form field value of type 'a
which can successfully decode the field value or fail with an error message key.
In the following type decoders, the minimum and maximum values are all inclusive.
val bool : bool ty
val char : ?min:char -> ?max:char -> char ty
val float : ?min:float -> ?max:float -> float ty
val int : ?min:int -> ?max:int -> int ty
val int32 : ?min:int32 -> ?max:int32 -> int32 ty
val int64 : ?min:int64 -> ?max:int64 -> int64 ty
val string : ?min_length:int -> ?max_length:int -> string ty
The type of a form (a form field by itself is also considered a form) which can decode values of type 'a
or fail with a list of error message keys.
list ?min_length ?max_length ty name
is a form field which can decode a list of values which can each be decoded by ty
. The list must have at least min_length
and at most max_length
(inclusive).
optional ty name
is a form field which can decode an optional value from the form.
required ?default ty name
is a form field which can decode a required value from the form. If at least one value corresponding to the given name
does not appear in the form, and if a default
value is not specified, the decoding fails with an error.
val ensure :
+ string ->
+ ('b -> bool) ->
+ ('a ty -> string -> 'b t) ->
+ 'a ty ->
+ string ->
+ 'b t
ensure message condition field ty name
is a form field which imposes an additional condition
on top of the existing field
. If the condition fails, the result is an error message
. It is suggested that the message
be a translation key so that the application can be localized to different languages.
let+ email = required string "email"
decodes a form field named email
as a string
.
and+ password = required string "password"
continues decoding in an existing form declaration and decodes a form field password
as a string
.
val validate :
+ 'a t ->
+ (string * string) list ->
+ ('a, (string * string) list) Stdlib.result
validate form values
is a result of validating the given form
's values
. It may be either some value of type 'a
or a list of form field names and the corresponding error message keys.
pp_error
is a helper pretty-printer for debugging/troubleshooting form validation errors.
When errors are reported, the following keys are used instead of English strings. These keys can be used for localizing the error messages. The suggested default English translations are given below.
These keys are modelled after Play Framework.
Basic complete example:
type user = { name : string; age : int option}
+
+open Dream_html.Form
+
+let user_form =
+ let+ name = required string "name"
+ and+ age = optional (int ~min:16) "age" in (* Thanks, Australia! *)
+ { name; age }
+
+let dream_form = ["age", "42"; "name", "Bob"]
+let user_result = validate user_form dream_form
Result: Ok { name = "Bob"; age = Some 42 }
Sad path:
validate user_form ["age", "none"]
Result: Error [("age", "error.expected.int"); ("name", "error.required")]
Notice that validation errors for all fields are reported. This is a critical design decision that differentiates this module from others available in OCaml.
Decode list of values from form:
type plan = { id : string; features : string list }
+
+let plan_form =
+ let+ id = required string "id"
+ and+ features = list string "features" in
+ { id; features }
+
+validate plan_form ["id", "foo"]
Result: Ok {id = "foo"; features = []}
validate plan_form ["id", "foo"; "features", "f1"; "features", "f2"]
Result: Ok {id = "foo"; features = ["f1"; "f2"]}
Note that the names can be anything, eg "features[]"
if you prefer.
Add further requirements to field values:
let plan_form =
+ let+ id = ensure "error.expected.nonempty" (( <> ) "") required string "id"
+ and+ features = list string "features" in
+ { id; features }
+
+validate plan_form ["id", ""]
Result: Error [("id", "error.expected.nonempty")]
Dream_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
+HTML (dream-html.Dream_html.HTML) Module Dream_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
p [] [txt "Edit me!"];
p [contenteditable false] [txt "Can't edit me!"];
]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p [if should_show then null_ else style_ "display:none"] [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val async : attr
val autocapitalize :
diff --git a/dream-html/Dream_html/Hx/index.html b/dream-html/Dream_html/Hx/index.html
index 15e01db..d0e2442 100644
--- a/dream-html/Dream_html/Hx/index.html
+++ b/dream-html/Dream_html/Hx/index.html
@@ -1,2 +1,2 @@
-Hx (dream-html.Dream_html.Hx) Module Dream_html.Hx
htmx support https://htmx.org/reference/
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val on : _ string_attr
Note that the value of this attribute is not escaped.
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sync : _ string_attr
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
+Hx (dream-html.Dream_html.Hx) Module Dream_html.Hx
htmx support https://htmx.org/reference/
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val on : _ string_attr
Note that the value of this attribute is not escaped.
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sync : _ string_attr
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
diff --git a/dream-html/Dream_html/Livereload/index.html b/dream-html/Dream_html/Livereload/index.html
index b24b4d2..900539e 100644
--- a/dream-html/Dream_html/Livereload/index.html
+++ b/dream-html/Dream_html/Livereload/index.html
@@ -1,5 +1,5 @@
-Livereload (dream-html.Dream_html.Livereload) Module Dream_html.Livereload
Live reload script injection and handling. Adapted from Dream.livereload
middleware. This version is not a middleware so it's not as plug-and-play as that, but on the other hand it's much simpler to implement because it uses type-safe dream-html nodes rather than parsing and printing raw HTML. See below for the 3-step process to use it.
This module is adapted from Dream, released under the MIT license. For details, visit https://github.com/aantron/dream.
Copyright 2021-2023 Thibaut Mattio, Anton Bachin.
(1) Put this in your top-level router:
let () = Dream.run
+Livereload (dream-html.Dream_html.Livereload) Module Dream_html.Livereload
Live reload script injection and handling. Adapted from Dream.livereload
middleware. This version is not a middleware so it's not as plug-and-play as that, but on the other hand it's much simpler to implement because it uses type-safe dream-html nodes rather than parsing and printing raw HTML. See below for the 3-step process to use it.
This module is adapted from Dream, released under the MIT license. For details, visit https://github.com/aantron/dream.
Copyright 2021-2023 Thibaut Mattio, Anton Bachin.
(1) Put this in your top-level router:
let () = Dream.run
@@ Dream.logger
@@ Dream.router [
Dream_html.Livereload.route;
diff --git a/dream-html/Dream_html/MathML/index.html b/dream-html/Dream_html/MathML/index.html
index 4e13382..d4da082 100644
--- a/dream-html/Dream_html/MathML/index.html
+++ b/dream-html/Dream_html/MathML/index.html
@@ -1,2 +1,2 @@
-MathML (dream-html.Dream_html.MathML) Module Dream_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
+MathML (dream-html.Dream_html.MathML) Module Dream_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
diff --git a/dream-html/Dream_html/SVG/index.html b/dream-html/Dream_html/SVG/index.html
index d6f0f61..4c422e5 100644
--- a/dream-html/Dream_html/SVG/index.html
+++ b/dream-html/Dream_html/SVG/index.html
@@ -1,3 +1,3 @@
-SVG (dream-html.Dream_html.SVG) Module Dream_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
+SVG (dream-html.Dream_html.SVG) Module Dream_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
[< `arcs | `bevel | `miter | `miter_clip | `round ] to_attr
val stroke_width : _ string_attr
val viewbox : min_x:int -> min_y:int -> width:int -> height:int -> attr
val xmlns : attr
val path : std_tag
val svg : std_tag
diff --git a/dream-html/Dream_html/index.html b/dream-html/Dream_html/index.html
index 12b3162..bb5c1e4 100644
--- a/dream-html/Dream_html/index.html
+++ b/dream-html/Dream_html/index.html
@@ -1,5 +1,24 @@
-Dream_html (dream-html.Dream_html) Module Dream_html
include module type of Pure_html
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
+Dream_html (dream-html.Dream_html) Module Dream_html
Input
module Form : sig ... end
Typed, extensible HTML form decoder with error reporting for all form field validation failures.
val form :
+ 'a Form.t ->
+ ?csrf:bool ->
+ Dream.request ->
+ [> 'a Dream.form_result | `Invalid of (string * string) list ] Dream.promise
Type-safe wrapper for Dream.form
. Similarly to that, you can match on the result:
type new_user = { name : string; email : string }
+let new_user =
+ let open Dream_html.Form in
+ let+ name = required string "name"
+ and+ email = required string "email" in
+ { name; email }
+
+(* POST /users *)
+let post_users req =
+ match%lwt Dream_html.form new_user req with
+ | `Ok { name; email } -> (* ... *)
+ | `Invalid errors -> Dream.json ~code:422 ( (* ...render errors... *) )
+ | _ -> Dream.empty `Bad_Request
val query :
+ 'a Form.t ->
+ Dream.request ->
+ [> `Ok of 'a | `Invalid of (string * string) list ]
Type-safe wrapper for Dream.all_queries
. Can be used to decode the query parameters into a typed value.
Output
include module type of Pure_html
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : ?header:bool -> node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> ?header:bool -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
==>
<a href="/blog?tags=iamsafe%22%3E%3C/a%3E%3Cscript%3Ealert('Pwned')%3C/script%3E">Tags: tag1 | tag2</a>
@@ -8,7 +27,7 @@
<a href="/foo?a=1&b=2%203&c=4%3C5&d=6%3E5">Test</a>
val bool_attr : string -> bool to_attr
val float_attr : string -> float to_attr
val int_attr : string -> int to_attr
val std_tag : string -> std_tag
val void_tag : string -> void_tag
val text_tag : string -> ?raw:bool -> _ text_tag
Build a tag which can contain only text.
val txt : ?raw:bool -> ('a, unit, string, node) Stdlib.format4 -> 'a
A text node inside the DOM e.g. the 'hi' in <b>hi</b>
. Allows string interpolation using the same formatting features as Printf.sprintf
:
b [] [txt "Hello, %s!" name]
Or without interpolation:
b [] [txt "Bold of you."]
HTML-escapes the text value. You can use the ~raw
param to bypass escaping:
let user_input = "<script>alert('I like HTML injection')</script>" in
txt ~raw:true "%s" user_input
val comment : string -> node
A comment that will be embedded in the rendered HTML, i.e. <!-- comment -->
. The text is HTML-escaped.
Accessors for tags
Add an attribute to a tag.
let toast msg = p [id "toast"] [txt "%s" msg]
let toast_oob = toast "ok." +@ Hx.swap_oob "true"
val (.@[]) : node -> string -> string
Get the value of an existing attribute.
let toast = p [id "toast"] [txt "OK."]
-let toast_id = toast.@["id"]
val is_null : node -> bool
Get whether a node is null (empty) or not. Useful for conditional rendering of UIs when you are passed in a node and you don't know if it's empty or not.
val is_null_ : attr -> bool
Get whether an attribute is null (empty) or not.
Standard attributes and tags
module HTML : sig ... end
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
module SVG : sig ... end
module MathML : sig ... end
ARIA support
module Aria : sig ... end
htmx support
module Hx : sig ... end
htmx support https://htmx.org/reference/
Output
val is_null : node -> bool
Get whether a node is null (empty) or not. Useful for conditional rendering of UIs when you are passed in a node and you don't know if it's empty or not.
val is_null_ : attr -> bool
Get whether an attribute is null (empty) or not.
Standard attributes and tags
module HTML : sig ... end
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
module SVG : sig ... end
module MathML : sig ... end
ARIA support
module Aria : sig ... end
htmx support
module Hx : sig ... end
htmx support https://htmx.org/reference/
val respond :
?status:[< Dream.status ] ->
?code:int ->
?headers:(string * string) list ->
diff --git a/dream-html/index.html b/dream-html/index.html
index b4ff5c1..4791a13 100644
--- a/dream-html/index.html
+++ b/dream-html/index.html
@@ -1,2 +1,2 @@
-index (dream-html.index) dream-html index
Library dream-html
The entry point of this library is the module: Dream_html
.
+index (dream-html.index) dream-html index
Library dream-html
The entry point of this library is the module: Dream_html
.
diff --git a/odoc.support/odoc.css b/odoc.support/odoc.css
index 71148de..15240b5 100644
--- a/odoc.support/odoc.css
+++ b/odoc.support/odoc.css
@@ -1,7 +1,7 @@
@charset "UTF-8";
/* Copyright (c) 2016 The odoc contributors. All rights reserved.
Distributed under the ISC license, see terms at the end of the file.
- odoc 2.4.2 */
+ odoc 2.4.3 */
/* Fonts */
/* noticia-text-regular - latin */
diff --git a/pure-html/Pure_html/Aria/index.html b/pure-html/Pure_html/Aria/index.html
index 54ebf1c..9e48cae 100644
--- a/pure-html/Pure_html/Aria/index.html
+++ b/pure-html/Pure_html/Aria/index.html
@@ -1,2 +1,2 @@
-Aria (pure-html.Pure_html.Aria) Module Pure_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `polite ] to_attr
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
+Aria (pure-html.Pure_html.Aria) Module Pure_html.Aria
https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/
val activedescendant : _ string_attr
val atomic : attr
val autocomplete : [ `inline | `list | `both ] to_attr
val braillelabel : _ string_attr
val brailleroledescription : _ string_attr
val busy : attr
val checked : [ `false_ | `true_ | `mixed ] to_attr
val colcount : int to_attr
val colindextext : _ string_attr
val colspan : int to_attr
val controls : _ string_attr
val current : [ `page | `step | `location | `date | `time | `true_ ] to_attr
val describedby : _ string_attr
val description : _ string_attr
val details : _ string_attr
val disabled : attr
val errormessage : _ string_attr
val expanded : bool to_attr
val flowto : _ string_attr
val haspopup : [ `true_ | `menu | `listbox | `tree | `grid | `dialog ] to_attr
val invalid : [ `grammar | `spelling | `true_ ] to_attr
val keyshortcuts : _ string_attr
val label : _ string_attr
val labelledby : _ string_attr
val level : int to_attr
val live : [ `assertive | `polite ] to_attr
val modal : attr
val multiline : attr
val multiselectable : attr
val orientation : [ `horizontal | `vertical ] to_attr
val owns : _ string_attr
val placeholder : _ string_attr
val posinset : int to_attr
val pressed : [ `false_ | `mixed | `true_ ] to_attr
val readonly : attr
val relevant : [ `additions | `all | `removals | `text ] to_attr
val required : attr
val roledescription : _ string_attr
val rowcount : int to_attr
val rowindex : int to_attr
val rowindextext : _ string_attr
val rowspan : int to_attr
val selected : bool to_attr
val setsize : int to_attr
val sort : [ `ascending | `descending | `other ] to_attr
val valuemax : float to_attr
val valuemin : float to_attr
val valuenow : float to_attr
val valuetext : _ string_attr
diff --git a/pure-html/Pure_html/HTML/index.html b/pure-html/Pure_html/HTML/index.html
index 998fede..abddb8f 100644
--- a/pure-html/Pure_html/HTML/index.html
+++ b/pure-html/Pure_html/HTML/index.html
@@ -1,5 +1,5 @@
-HTML (pure-html.Pure_html.HTML) Module Pure_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
+HTML (pure-html.Pure_html.HTML) Module Pure_html.HTML
All standard HTML attributes and tags. Some attributes and tags have the same name, e.g. style
. To disambiguate them, attributes have a _
(underscore) suffix.
Attributes
Standard, most non-deprecated attributes from https://developer.mozilla.org/en-US/docs/Web/HTML/Attributes. Where an attribute name conflicts with an OCaml keyword, the name is suffixed with _
. Most attributes are constructed by passing in a value of some type.
All string-valued attributes allow formatting (interpolation):
div [id "section-%d" section_id] []
Or plain strings:
p [id "toast"] []
Most boolean attributes are plain values and don't need to be constructed with function calls:
input [required]
However, boolean attributes which may be inherited and toggled on/off in children, are constructed by passing in a value:
div [contenteditable true] [
p [] [txt "Edit me!"];
p [contenteditable false] [txt "Can't edit me!"];
]
Enumerated attributes accept specific values:
input [inputmode `tel]
val null_ : attr
An attribute that will not be rendered in the markup. Useful for conditional logic where you sometimes want to render an attribute and sometimes not.
p [if should_show then null_ else style_ "display:none"] [txt "Show and tell"]
val accept : _ string_attr
val accept_charset : _ string_attr
val accesskey : _ string_attr
val action : _ string_attr
val align : _ string_attr
val allow : _ string_attr
val alt : _ string_attr
val async : attr
val autocapitalize :
diff --git a/pure-html/Pure_html/Hx/index.html b/pure-html/Pure_html/Hx/index.html
index c4638a0..9a38edb 100644
--- a/pure-html/Pure_html/Hx/index.html
+++ b/pure-html/Pure_html/Hx/index.html
@@ -1,2 +1,2 @@
-Hx (pure-html.Pure_html.Hx) Module Pure_html.Hx
htmx support https://htmx.org/reference/
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val on : _ string_attr
Note that the value of this attribute is not escaped.
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sync : _ string_attr
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
+Hx (pure-html.Pure_html.Hx) Module Pure_html.Hx
htmx support https://htmx.org/reference/
val __ : _ string_attr
This attribute serves as the _ attribute, which is used by Hyperscript. Note that the value of this attribute is not escaped.
val boost : bool to_attr
val confirm : _ string_attr
val delete : _ string_attr
val disable : attr
val disabled_elt : _ string_attr
val disinherit : _ string_attr
val encoding_formdata : attr
Hardcoding of the hx-encoding
attribute to multipart/form-data
.
val ext : _ string_attr
val get : _ string_attr
val headers : _ string_attr
val history_false : attr
Hardcoding of the hx-history
attribute to false
.
val history_elt : attr
val include_ : _ string_attr
val indicator : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val inherit_ : _ string_attr
val on : _ string_attr
Note that the value of this attribute is not escaped.
val on_ : event:string -> _ string_attr
The hx-on:*
set of attributes, where *
represents DOM events: https://htmx.org/attributes/hx-on/.
Note that the value of this attribute is not escaped.
val params : _ string_attr
val patch : _ string_attr
val post : _ string_attr
val preload : attr
The preload extension: https://htmx.org/extensions/preload/
val preserve : attr
val prompt : _ string_attr
val push_url : _ string_attr
val put : _ string_attr
val replace_url : _ string_attr
val request : _ string_attr
val select : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val select_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sse_close : _ string_attr
val sse_connect : _ string_attr
val sse_swap : _ string_attr
val swap : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val swap_oob : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val sync : _ string_attr
val target : _ string_attr
Note that the value of this attribute is not escaped as it may include a CSS selector.
val trigger : _ string_attr
Note that the value of this attribute is not escaped.
val validate : attr
val vals : _ string_attr
val ws_connect : _ string_attr
val ws_send : attr
diff --git a/pure-html/Pure_html/MathML/index.html b/pure-html/Pure_html/MathML/index.html
index 7dafdb2..53664e0 100644
--- a/pure-html/Pure_html/MathML/index.html
+++ b/pure-html/Pure_html/MathML/index.html
@@ -1,2 +1,2 @@
-MathML (pure-html.Pure_html.MathML) Module Pure_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
+MathML (pure-html.Pure_html.MathML) Module Pure_html.MathML
val accent : bool to_attr
val accentunder : bool to_attr
val columnspan : int to_attr
val depth : _ string_attr
val dir : [ `ltr | `rtl ] to_attr
val display_block : attr
See https://developer.mozilla.org/en-US/docs/Web/MathML/Element/math#display. display=inline
is the default, so there is no need to bind its value.
val displaystyle : bool to_attr
val fence : bool to_attr
val height : _ string_attr
val largeop : bool to_attr
val linethickness : _ string_attr
val lspace : _ string_attr
val mathvariant : _ string_attr
val maxsize : _ string_attr
val minsize : _ string_attr
val movablelimits : bool to_attr
val rowspan : int to_attr
val rspace : _ string_attr
val scriptlevel : _ string_attr
val separator : bool to_attr
val stretchy : bool to_attr
val symmetric : bool to_attr
val voffset : _ string_attr
val xmlns : attr
val annotation : std_tag
val annotation_xml : std_tag
val math : std_tag
val merror : std_tag
val mfrac : std_tag
val mi : std_tag
val mmultiscripts : std_tag
val mn : std_tag
val mo : std_tag
val mover : std_tag
val mpadded : std_tag
val mphantom : std_tag
val mroot : std_tag
val mrow : std_tag
val ms : std_tag
val mspace : std_tag
val msqrt : std_tag
val mstyle : std_tag
val msub : std_tag
val msubsup : std_tag
val msup : std_tag
val mtable : std_tag
val mtd : std_tag
val mtext : std_tag
val mtr : std_tag
val munder : std_tag
val munderover : std_tag
val semantics : std_tag
diff --git a/pure-html/Pure_html/SVG/index.html b/pure-html/Pure_html/SVG/index.html
index b632bf1..ecc69b2 100644
--- a/pure-html/Pure_html/SVG/index.html
+++ b/pure-html/Pure_html/SVG/index.html
@@ -1,3 +1,3 @@
-SVG (pure-html.Pure_html.SVG) Module Pure_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
+SVG (pure-html.Pure_html.SVG) Module Pure_html.SVG
val d : _ string_attr
val fill : _ string_attr
val stroke : _ string_attr
val stroke_linecap : [< `butt | `round | `square ] to_attr
val stroke_linejoin :
[< `arcs | `bevel | `miter | `miter_clip | `round ] to_attr
val stroke_width : _ string_attr
val viewbox : min_x:int -> min_y:int -> width:int -> height:int -> attr
val xmlns : attr
val path : std_tag
val svg : std_tag
diff --git a/pure-html/Pure_html/index.html b/pure-html/Pure_html/index.html
index b3be775..20777fe 100644
--- a/pure-html/Pure_html/index.html
+++ b/pure-html/Pure_html/index.html
@@ -1,5 +1,5 @@
-Pure_html (pure-html.Pure_html) Module Pure_html
Use this module for constructing HTML without any dependency on the Dream web framework.
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
+Pure_html (pure-html.Pure_html) Module Pure_html
Use this module for constructing HTML without any dependency on the Dream web framework.
Core types
These are the types of the final values which get rendered.
Output
val to_string : node -> string
val to_xml : ?header:bool -> node -> string
Same as to_string
but render void tags as XML-style self-closing tags.
val pp : Stdlib.Format.formatter -> node -> unit
val pp_xml : Stdlib.Format.formatter -> ?header:bool -> node -> unit
Same as pp
but render void tags as XML-style self-closing tags.
Constructing nodes and attributes
type 'a to_attr = 'a -> attr
Attributes can be created from typed values.
type 'a string_attr = ('a, unit, string, attr) Stdlib.format4 -> 'a
Special handling for string-value attributes so they can use format strings i.e. string interpolation.
A 'void element': https://developer.mozilla.org/en-US/docs/Glossary/Void_element with no children.
Tags which can have attributes but can contain only text. The text can be formatted.
val attr : string -> attr
attr name
is a new attribute which does not carry any payload. E.g.
let required = attr "required"
val string_attr : string -> ?raw:bool -> _ string_attr
string_attr name fmt
is a new string-valued attribute which allows formatting i.e. string interpolation of the value. Note, the fmt
argument is required due to the value restriction.
val uri_attr : string -> _ string_attr
Convenience for attributes whose values should be URIs. Takes care of both URI-encoding and attribute escaping, as recommended in https://cheatsheetseries.owasp.org/cheatsheets/Cross_Site_Scripting_Prevention_Cheat_Sheet.html#common-mistake.
Examples
a [href "/blog?tags=iamsafe\"></a><script>alert('Pwned')</script>"] [txt "Tags: tag1 | tag2"]
==>
<a href="/blog?tags=iamsafe%22%3E%3C/a%3E%3Cscript%3Ealert('Pwned')%3C/script%3E">Tags: tag1 | tag2</a>
diff --git a/pure-html/index.html b/pure-html/index.html
index a4dbecd..940eb24 100644
--- a/pure-html/index.html
+++ b/pure-html/index.html
@@ -1,2 +1,2 @@
-index (pure-html.index) pure-html index
Library pure-html
The entry point of this library is the module: Pure_html
.
+index (pure-html.index) pure-html index
Library pure-html
The entry point of this library is the module: Pure_html
.