Webs_html.El
HTML elements and parts.
The type for HTML parts. A part is either a single element or character data or a list of parts.
v ?at n cs
is an element with name n
, attributes at
(defaults to []
) and children cs
.
Except for At.class'
and At.style
the list at
must not specify an attribute more than once; this is not checked by the module. For At.class'
multiple specifications are gathered to form a single, space separated, attribute value for the class
HTML attribute. For At.style
multiple specifications are gathered to form a single, semi-colon seperated, attribute value for the style
HTML attribute.
See also (and favor) element constructors.
val txt : string -> html
txt d
is character data d
.
val txt_of : ('a -> string) -> 'a -> html
txt_of f v
is txt (f v)
. Cuts a bit on delimiter orgies.
val sp : html
sp
is El.txt " "
.
val nbsp : html
nbsp
is El.txt "\u{00A0}"
.
splice ?sep hs
when added to a list of children in v
splices HTML parts hs
into the list, separating each part by sep
(if any).
val void : html
void
is splice []
.
val is_void : html -> bool
is_void h
is true
iff h
is void. This can be either an empty splice
, an empty txt
or an empty unsafe_raw
.
val unsafe_raw : string -> html
unsafe_raw s
is the raw string s
without escaping markup delimiters. s
must be well-formed HTML otherwise invalid markup will be generated. This can be used to:
style
element.There's more than one way to generate a basic HTML page. The following provides good defaults for a quick minimal document.
val page :
?lang:string ->
?generator:string ->
?styles:string list ->
?scripts:string list ->
?more_head:html ->
title:string ->
html ->
html
page ~lang ~generator ~styles ~scripts ~more_head ~title body
is an El.html
element with an At.lang
attribute of lang
(if specified and non-empty) containing a El.head
element (see below) followed by body
which must be a El.body
element.
The other arguments are used to define the children of the page's El.head
which are in order:
El.meta
of UTF-8 (unconditional).El.meta
of generator
, if specified and non-empty.El.meta
with width=device-width, initial-scale=1
(unconditional).El.link
of type text/css
for each element of styles
, in order (defaults to []
).El.script
with At.defer
and of At.type'
text/javascript
for each element of scripts
, in order (defaults to []
).more_head
(defaults to El.void
). Be careful with style
tags.title
which is String
.trimed. If the result is empty falls back to "Untitled"
. See also title_of_filepath
.title_of_filepath f
is a non-empty page title for filepath f
. Either the basename of f
without extension or if that results in "index"
or ""
the basename of the parent directory without extension or if that results in ""
, "Untitled"
. Directory separators can be '/'
or '\\'
regardless of the platform.
val buffer_add : doc_type:bool -> Stdlib.Buffer.t -> html -> unit
buffer_add ~doc_type b h
adds HTML part h
. If doc_type
is true
an HTML doctype declaration is prepended.
val to_string : doc_type:bool -> html -> string
to_string
is like buffer_add
but returns directly a string.
module Low : sig ... end
Low level representation (unstable).
See the MDN HTML element reference.
Convention. Whenever an element name conflicts with an OCaml keyword we prime it, see for example object'
.
The type for element constructors. This is simply El.v
with a pre-applied element name.
The type for void element constructors. This is simply El.v
with a pre-applied element name and without children.
val blockquote : cons
val figcaption : cons
val style : cons
Warning. If your style element holds CSS use unsafe_raw
content, otherwise the CSS selector >
gets escaped.