package b0

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Elements and HTML fragments.

Elements

type name = string

The type for element names.

type frag

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

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

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}".

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

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.

Output

val buffer_add : doc_type:bool -> Buffer.t -> frag -> unit

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.

Convenience

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:

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

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

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

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

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

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

Innovation. Community. Security.