Module B00_htmlg.ElSource

Elements and HTML fragments.

Elements

Sourcetype name = string

The type for element names.

Sourcetype frag

The type for HTML fragments. A fragment is either character data or a single element or a sequence of elements.

Sourceval v : ?at:At.t list -> name -> frag list -> frag

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.

Sourceval txt : string -> frag

txt d is character data d.

Sourceval sp : frag

sp is El.txt " ".

Sourceval nbsp : frag

nbsp is El.txt "\u{00A0}".

Sourceval splice : ?sep:frag -> frag list -> frag

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).

Sourceval void : frag

void is splice [].

Sourceval 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.

Output

Sourceval buffer_add : doc_type:bool -> Stdlib.Buffer.t -> frag -> unit

buffer_add ~doc_type b frag adds fragment frag. If doc_type is true an HTML doctype declaration is prepended.

Sourceval to_string : doc_type:bool -> frag -> string

to_string is like buffer_add but returns directly a string.

Convenience

Sourceval title_of_fpath : B0_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".

Sourceval 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:

  1. A charset El.meta of UTF-8 (unconditional).
  2. A generator El.meta of generator, if specified an non-empty.
  3. A viewport El.meta with width=device-width, initial-scale=1 (unconditional).
  4. A stylesheet El.link of type text/css for each element of styles, in order (defaults to []).
  5. A El.script with At.defer and of At.type' text/javascript for each element of scripts, in order (defaults to []).
  6. more_head (defaults to El.void).
  7. The page has a title title, which must be non-white and and non-empty (falls back to "Untitled" in any of these cases).
Sourceval write_page : ?lang:string -> ?generator:string -> ?styles:string list -> ?scripts:string list -> ?more_head:frag -> ?title:string -> B00.Memo.t -> frag:B0_std.Fpath.t -> o:B0_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.

Predefined element constructors

See the MDN HTML element reference.

Convention. Whenever an element name conflicts with an OCaml keyword we prime it, see for example object'.

Sourcetype cons = ?at:At.t list -> frag list -> frag

The type for element constructors. This is simply v with a pre-applied element name.

Sourcetype void_cons = ?at:At.t list -> unit -> frag

The type for void element constructors. This is simply el with a pre-applied element name and without children.

Sourceval a : cons
Sourceval abbr : cons
Sourceval address : cons
Sourceval area : void_cons
Sourceval article : cons
Sourceval aside : cons
Sourceval audio : cons
Sourceval b : cons
Sourceval base : void_cons
Sourceval bdi : cons
Sourceval bdo : cons
Sourceval blockquote : cons
Sourceval body : cons
Sourceval button : cons
Sourceval canvas : cons
Sourceval caption : cons
Sourceval cite : cons
Sourceval code : cons
Sourceval col : void_cons
Sourceval colgroup : cons
Sourceval command : cons
Sourceval datalist : cons
Sourceval dd : cons
Sourceval del : cons
Sourceval details : cons
Sourceval dfn : cons
Sourceval div : cons
Sourceval dl : cons
Sourceval dt : cons
Sourceval em : cons
Sourceval embed : void_cons
Sourceval fieldset : cons
Sourceval figcaption : cons
Sourceval figure : cons
Sourceval form : cons
Sourceval h1 : cons
Sourceval h2 : cons
Sourceval h3 : cons
Sourceval h4 : cons
Sourceval h5 : cons
Sourceval h6 : cons
Sourceval head : cons
Sourceval header : cons
Sourceval hgroup : cons
Sourceval html : cons
Sourceval i : cons
Sourceval iframe : cons
Sourceval img : void_cons
Sourceval input : void_cons
Sourceval ins : cons
Sourceval kbd : cons
Sourceval keygen : cons
Sourceval label : cons
Sourceval legend : cons
Sourceval li : cons
Sourceval map : cons
Sourceval mark : cons
Sourceval menu : cons
Sourceval meta : void_cons
Sourceval meter : cons
Sourceval nav : cons
Sourceval noscript : cons
Sourceval object' : cons
Sourceval ol : cons
Sourceval optgroup : cons
Sourceval option : cons
Sourceval output : cons
Sourceval p : cons
Sourceval param : void_cons
Sourceval pre : cons
Sourceval progress : cons
Sourceval q : cons
Sourceval rp : cons
Sourceval rt : cons
Sourceval ruby : cons
Sourceval s : cons
Sourceval samp : cons
Sourceval script : cons
Sourceval section : cons
Sourceval select : cons
Sourceval small : cons
Sourceval source : void_cons
Sourceval span : cons
Sourceval strong : cons
Sourceval style : cons
Sourceval sub : cons
Sourceval summary : cons
Sourceval sup : cons
Sourceval table : cons
Sourceval tbody : cons
Sourceval td : cons
Sourceval textarea : cons
Sourceval tfoot : cons
Sourceval th : cons
Sourceval thead : cons
Sourceval time : cons
Sourceval title : cons
Sourceval tr : cons
Sourceval track : void_cons
Sourceval u : cons
Sourceval ul : cons
Sourceval var : cons
Sourceval video : cons
Sourceval wbr : void_cons