package cascade

  1. Overview
  2. Docs
CSS generation and manipulation library for OCaml

Install

dune-project
 Dependency

Authors

Maintainers

Sources

cascade-1.2.0.tbz
sha256=3315f94068943b3655bf530c1d82b68655524ff3601efedfbaf0a7f886fbf5a1
sha512=0f187c8e17fcbddaa0ad2760930956451062e476b678e1e60daf6ad9e7414fad99a2d70534dfdf8bca0a1092e374d009051f06b0ce9da33f2742cdde0187e75c

doc/cascade.html/Cascade_html/Html/index.html

Module Cascade_html.HtmlSource

A mutable HTML tree, parsed and printed with markup.ml.

Cascade.Resolve needs a tree with parent links and settable attributes; markup.ml gives a signal stream. This is the tree in between, and it holds every node HTML has, comments included: <p>v<!-- -->4.3</p> keeps two text nodes, and a browser measures the two apart, so dropping the comment changes the render. Licence headers and conditional comments are the other reason they are content, not decoration.

Sourcetype t = node list

A parsed document: the top-level nodes, in order.

Sourceand node =
  1. | Element of element
  2. | Text of string
  3. | Comment of string
  4. | Doctype of Markup.doctype
Sourceand element = {
  1. ns : string;
    (*

    Namespace URI, so SVG and MathML print as themselves.

    *)
  2. tag : string;
    (*

    Local name, lowercased by the HTML parser.

    *)
  3. mutable attributes : (string * string) list;
  4. mutable children : node list;
  5. mutable parent : element option;
}
Sourceval parse : string -> t

parse html is the document html denotes: the top-level nodes the parser leaves, in order - a doctype, any comment outside the markup, and the elements themselves. The <html> wrapper is among them only when the source wrote that tag or a doctype, so <p>hi</p> parses to the <p> alone and a source carrying no element at all leaves roots empty.

Sourceval to_string : t -> string

to_string doc serialises doc as HTML5.

Sourceval pp : t Fmt.t

pp prints a document as HTML5.

Sourceval find_all : string -> t -> element list

find_all tag doc is every tag element in doc, in document order.

Sourceval find : string -> t -> element option

find tag doc is the first tag element in doc.

Sourceval roots : t -> element list

roots doc is the elements among doc's top-level nodes, the trees to resolve against.

Sourceval text : element -> string

text e is the data of every text node under e, concatenated.

Sourceval attribute : element -> string -> string option

attribute e name is the value of e's name attribute, or None.

Sourceval set_attribute : element -> string -> string -> unit

set_attribute e name value sets e's name attribute.

Sourceval classes : element -> string list

classes e is the class names in e's class attribute (HTML sec. 2.4.7: a set of space-separated tokens splits on ASCII whitespace).

Sourceval element_children : element -> element list

element_children e is e's child elements, in document order.

Sourceval text_children : element -> string list

text_children e is the data of e's direct child text nodes. A comment is not one: it does not stop an element being :empty.

Sourceval clear : element -> unit

clear e removes e's children, leaving the element in the tree.

Sourceval element : string -> text:string -> element

element tag ~text is a new HTML element named tag holding text.

Sourceval append_child : element -> element -> unit

append_child parent child adds child as parent's last child.

Sourceval prepend_child : element -> element -> unit

prepend_child parent child adds child as parent's first child.