B00_htmlg.El
Elements and HTML fragments.
The type for HTML fragments. A fragment is either character data or a single element or a sequence of elements.
v ?at n cs
is an element with name n
, attributes at
(defaults to []
) and children cs
.
Except for At.class'
the list at
must not define an attribute more than once; this is not checked by the module. The At.class'
is treated specially: multiple specifications are gathered to form a single, space separated, attribute value for the class
HTML attribute.
val txt : string -> frag
txt d
is character data d
.
val sp : frag
sp
is El.txt " "
.
val nbsp : frag
nbsp
is El.txt "\u{00A0}"
.
splice ?sep fs
when added to a list of children in v
splices fragments fs
into the list, separating each fragment by sep
(if any).
val void : frag
void
is splice []
.
val raw : string -> frag
raw s
is the raw string s
without escaping markup delimiters. This can be used to include foreign markup. s
must be well-formed HTML otherwise invalid markup will be generated.
buffer_add ~doc_type b frag
adds fragment frag
. If doc_type
is true
an HTML doctype declaration is prepended.
val to_string : doc_type:bool -> frag -> string
to_string
is like buffer_add
but returns directly a string.
val title_of_fpath : B00_std.Fpath.t -> string
title_of_fpath p
is a page title for p
guaranteed to be non empty. Either the basename of file
without extension or if that results in "index"
or ""
the basename of the parent directory without extension or if that results in ""
, "Untitled"
.
val basic_page : ?lang:string -> ?generator:string -> ?styles:string list ->
?scripts:string list -> ?more_head:frag -> title:string -> frag -> frag
basic_page ~lang ~generator ~styles ~scripts ~more_head ~title body
is an El.html
element with a 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 an 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
).title
, which must be non-white and and non-empty (falls back to "Untitled"
in any of these cases).val write_page : ?lang:string -> ?generator:string -> ?styles:string list ->
?scripts:string list -> ?more_head:frag -> ?title:string -> B00.Memo.t -> frag:B00_std.Fpath.t -> o:B00_std.Fpath.t -> unit
write_page m ~frag ~o
reads frag
and inserts it in an El.body
using raw
and writes a full HTML document to o
using basic_page
(see doc of the corresponding arguments). If title
is ""
or unspecified page_title
o
is used.
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 v
with a pre-applied element name.
The type for void element constructors. This is simply el
with a pre-applied element name and without children.
val blockquote : cons