package tw
All checked builds passInstall
dune-project
Dependency
Authors
Maintainers
Sources
sha256=c6f2f55bdbafd557e7716e4ab2daa012beb2ab2548090fae4a6e53c8016a3b10
sha512=13c066b3b233227d620a28abb724c8aea13c08f8f4b4657f7462d5806aa227568b921523e2675f3cd8ec8597fbe23a0f512e98f143adcf49b64a80ac95e6b740
doc/tw.html/Tw_html/index.html
Module Tw_htmlSource
A library for building HTML documents programmatically.
This module provides a type-safe and declarative API for creating HTML elements and attributes. It is designed to be used for generating static HTML pages.
The abstract type for an HTML node.
The abstract type for an HTML attribute.
Text helpers
Conversion functions
to_string ?doctype element converts HTML element to string representation. If doctype is true (default: false), includes the HTML5 doctype declaration.
unknown_classes t lists, in document order, every name in the tree's class attributes that Tw.of_classes did not recognise as a utility.
Such a name is rendered as given - a framework hook or a JS selector belongs in a class attribute - so this is how a typo among them is found.
has_forms t returns true if the HTML tree contains form elements (input, select, textarea) that benefit from the forms plugin base styles.
Attributes over a tree
map_attrs f t is t with the attributes of each element replaced by f name attrs, name and attrs as fold_attrs gives them. A class attribute f changes is read as one given through ~at is: to_tw and unknown_classes report the names it carries. Markup given to raw is left as it is.
Page generation
Complete HTML page with integrated CSS.
A page value represents a complete, self-contained HTML document with all required CSS automatically generated from the Tailwind utilities used in the HTML structure. This ensures consistency between your markup and styles without manual CSS management.
Design rationale: The type is abstract to enforce the invariant that the CSS contains exactly the styles needed for the HTML content. Direct construction would break this guarantee.
val page :
?lang:string ->
?meta:(string * string) list ->
?title:string ->
?charset:string ->
?tw_css:tw_css ->
?forms:bool ->
?prelude:t list ->
?theme:Tw.Scheme.t ->
t list ->
t list ->
pagepage ?lang ?meta ?title ?charset ?tw_css ?forms ?prelude ?theme head body generates a complete HTML page and its corresponding CSS.
langdefaults to"en"charsetdefaults to"utf-8"metais a list of(name, content)pairs for meta tagstitleis the page titletw_csscontrols how the CSS is delivered (seetw_css). Defaults toLink "tw.css", which references the CSS through a cache-busted<link>tag in the HTML head. UseInlineto embed the CSS in the document and avoid an extra HTTP request.formsexplicitly enables the\@tailwindcss/formsplugin base layer, mirroring Tailwind's\@pluginopt-in. When omitted, the forms base is auto-detected from forms utility usage (like prose styling).prelude(default[]) goes first in the head, right after the character set and before themetatags, the title and the stylesheet: where a content security policy has to stand to cover them, and where a script that sets the theme runs before the stylesheet applies.theme(defaultTw.Scheme.default) is the theme the CSS is generated with, asTw.to_csstakes it: itsTw.Scheme.t.dark, for one, decides whatTw.darkwrites.headis additional content for the head sectionbodyis the body content
Use html to get the HTML string and css to get the CSS filename and stylesheet.
versioned path ~contents is path?v=h, where h is the first eight hex digits of the MD5 digest of contents. A <link> or <script> that names a file this way is fetched again whenever the file changes, as a page names its stylesheet.
css page extracts the CSS filename and stylesheet from a page result. The filename is Some file when the page links to an external stylesheet (Link file) and None when the CSS is inlined (Inline).
HTML Elements
el name ?at ?tw children is the element name, built as the named constructors below build theirs, for a tag they do not cover. It always has an end tag: a void element such as br has its own constructor.
span ?at ?tw children is a span element.
a ?at ?tw children is an anchor/link element.
ul ?at ?tw children is an unordered list element.
li ?at ?tw children is a list item element.
nav ?at ?tw children is a navigation element.
section ?at ?tw children is a section element.
article ?at ?tw children is an article element.
header ?at ?tw children is a header element.
footer ?at ?tw children is a footer element.
h1 ?at ?tw children is an h1 heading element.
h2 ?at ?tw children is an h2 heading element.
h3 ?at ?tw children is an h3 heading element.
h4 ?at ?tw children is an h4 heading element.
h5 ?at ?tw children is an h5 heading element.
h6 ?at ?tw children is an h6 heading element.
script ?at ?tw children is a script element.
style ?at ?tw css is a style element holding css. <style> is a raw-text element, so css is written as given, unescaped.
title ?at ?tw children is a title element.
head ?at ?tw children is a head element.
body ?at ?tw children is a body element.
root ?at ?tw children is the root <html> element of a document.
option ?at ?tw children is an option element.
select ?at ?tw children is a select element.
main ?at ?tw children is a main element.
aside ?at ?tw children is an aside element.
time ?at ?tw children is a time element.
dialog ?at ?tw children is a dialog element.
data ?at ?tw children is a data element.
picture ?at ?tw children is a picture element.
slot ?at ?tw children is a slot element.
template ?at ?tw children is a template element.
form ?at ?tw children is a form element.
textarea ?at ?tw children is a textarea element.
button ?at ?tw children is a button element.
label ?at ?tw children is a label element.
fieldset ?at ?tw children is a fieldset element.
legend ?at ?tw children is a legend element.
details ?at ?tw children is a details element.
summary ?at ?tw children is a summary element.
code ?at ?tw children is a code element.
kbd ?at ?tw children is a keyboard input element.
em ?at ?tw children is an emphasis element.
strong ?at ?tw children is a strong element.
small ?at ?tw children is a small element.
mark ?at ?tw children is a mark element.
hr ?at ?tw () is a hr (horizontal rule) element.
table ?at ?tw children is a table element.
thead ?at ?tw children is a table head element.
tbody ?at ?tw children is a table body element.
tfoot ?at ?tw children is a table footer element.
tr ?at ?tw children is a table row element.
th ?at ?tw children is a table header cell element.
td ?at ?tw children is a table data cell element.
caption ?at ?tw children is a table caption element.
ol ?at ?tw children is an ordered list element.
dl ?at ?tw children is a description list element.
dt ?at ?tw children is a description term element.
dd ?at ?tw children is a description definition element.
blockquote ?at ?tw children is a blockquote element.
figure ?at ?tw children is a figure element.
figcaption ?at ?tw children is a figure caption element.
video ?at ?tw children is a video element.
audio ?at ?tw children is an audio element.
canvas ?at ?tw children is a canvas element.
iframe ?at ?tw children is an iframe element.
SVG Support
SVG Elements
svg ?at ?tw children creates an SVG root element.
g ?at ?tw children creates a group element.
circle ?at ?tw children creates a circle element.
rect ?at ?tw children creates a rectangle element.
path ?at ?tw children creates a path element.
line ?at ?tw children creates a line element.
text ?at ?tw children creates a text element.
tspan ?at ?tw children creates a tspan element, a run of text inside text.
desc ?at ?tw children creates a desc element, the text description of its parent.
defs ?at ?tw children creates a defs element, holding elements drawn only where they are referenced.
pattern ?at ?tw children creates a pattern element, a tile a fill or a stroke can repeat.