Module B00_htmlg.El

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 : name -> ?⁠at:At.t list -> frag list -> frag

v n ~at 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 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 -> 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 : 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 deferred El.script of 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

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