package cascade

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

Install

dune-project
 Dependency

Authors

Maintainers

Sources

cascade-1.2.1.tbz
sha256=1cf5079b3797cd6e70fbced8dc2631074f357d36fcdea8597c7ba17ac2903f6e
sha512=43f5e6a3986f8f43ce948b8f1d59f6f00e1047f5707c5449b6323b683d2ecd51a0fb34793aad9c48904a67b0f7268d7379ab9baf29917c25a962064bfa3ab694

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.