Module B0_htmlg.El

Elements.

Elements

type name = string

The type for element names.

type frag

The type for HTML fragments. Either textual data or an element or a sequence thereof.

val v : name -> ?⁠a:Att.t list -> frag list -> frag

v n ~a cs is an element with name n, attributes a (defaults to []) and children cs. It is illegal to specify an attribute name more than once in a except for Att.class' which is treated specially: multiple specifications are gathered to form a single space seperated attribute value for the class attribute.

val txt : string -> frag

txt d is character data d.

val splice : frag list -> frag

splice cs when added to the list of children in v splices cs into the list.

val raw : string -> frag

raw s is the raw string s without escaping markup delimiters. This can be used to include foreign markup.

val void : frag

void is splice [].

Output

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

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

to_string is like buffer_add but returns directly a string.

Convenience

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

val basic_page : ?⁠generator:string -> ?⁠lang:string -> ?⁠scripts:string list -> ?⁠styles:string list -> ?⁠more_head:frag -> ?⁠title:string -> frag -> frag

basic_page ~generator ~lang ~scripts ~styles ~more_head ~title body is an El.html element containing a El.head element followed by body. The parameters are used to define a head as follows.

  • The page has a charset of UTF-8 (unconditional).
  • The page has a viewport with width=device-width, initial-scale=1 (unconditional).
  • The page has a generator El.meta tag of generator, if specified and non-empty.
  • The page has language lang, if specified and non-empty.
  • The page has a defered script of type text/javascript for each element of scripts, in order (defaults to []).
  • The page has a stylesheet link of type text/css for each element of styles, in order (defaults to []).
  • The page has more_head in the El.head element (defaults to void).
  • The page has a title title, if specified and non-empty.
val write_page : ?⁠generator:string -> ?⁠lang:string -> ?⁠scripts:string list -> ?⁠styles:string list -> ?⁠title:string -> ?⁠more_head:frag -> B00.Memo.t -> frag:B0_std.Fpath.t -> o:B0_std.Fpath.t -> unit

write_page m ~title ~frag ~o writes to o a full HTML document whose body contains the contents of file frag (inserted using raw). If title is "" or unspecified it is page_title o, for the other arguments and more information see basic_page.

Predefined element constructors

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

type cons = ?⁠a:Att.t list -> frag list -> frag

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

type void_cons = a:Att.t list -> frag

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

val a : cons

a

val abbr : cons

abbr

val address : cons

address

val area : void_cons

area

val article : cons

article

val aside : cons

aside

val audio : cons

audio

val b : cons

b

val base : void_cons

base

val bdi : cons

bdi

val bdo : cons

bdo

val blockquote : cons

blockquote

val body : cons

body

val br : void_cons

br

val button : cons

button

val canvas : cons

canvas

val caption : cons

caption

val cite : cons

cite

val code : cons

code

val col : void_cons

col

val colgroup : cons

colgroup

val command : cons

command

val datalist : cons

datalist

val dd : cons

dd

val del : cons

del

val details : cons

details

val dfn : cons

dfn

val div : cons

div

val dl : cons

dl

val dt : cons

dt

val em : cons

em

val embed : void_cons

embed

val fieldset : cons

fieldset

val figcaption : cons

figcaption

val figure : cons

figure

footer

val form : cons

form

val h1 : cons

h1

val h2 : cons

h2

val h3 : cons

h3

val h4 : cons

h4

val h5 : cons

h5

val h6 : cons

h6

val head : cons

head

val header : cons

header

val hgroup : cons

hgroup

val hr : void_cons

hr

val html : cons

html

val i : cons

i

val iframe : cons

iframe

val img : void_cons

img

val input : void_cons

input

val ins : cons

ins

val kbd : cons

kbd

val keygen : cons

keygen

val label : cons

label

val legend : cons

legend

val li : cons

li

link

val map : cons

map

val mark : cons

mark

val menu : cons

menu

val meta : void_cons

meta

val meter : cons

meter

val nav : cons

nav

val noscript : cons

noscript

val object' : cons

object

val ol : cons

ol

val optgroup : cons

optgroup

val option : cons

option

val output : cons

output

val p : cons

p

val param : void_cons

param

val pre : cons

pre

val progress : cons

progress

val q : cons

q

val rp : cons

rp

val rt : cons

rt

val ruby : cons

ruby

val s : cons

s

val samp : cons

samp

val script : cons

script

val section : cons

section

val select : cons

select

val small : cons

small

val source : void_cons

source

val span : cons

span

val strong : cons

strong

val style : cons

style

val sub : cons

sub

val summary : cons

summary

val sup : cons

sup

val table : cons

table

val tbody : cons

tbody

val td : cons

td

val textarea : cons

textarea

val tfoot : cons

tfoot

val th : cons

th

val thead : cons

thead

val time : cons

time

val title : cons

title

val tr : cons

tr

val track : void_cons

track

val u : cons

u

val ul : cons

ul

val var : cons

var

val video : cons

video

val wbr : void_cons

wbr