lysande/html

There is no license information available for the latest version (0.1.0) of this package.

A small, simple HTML library, inspired by Elm.

0.1.0 2017-04-11 19:14 UTC

This package is not auto-updated.

Last update: 2025-06-27 22:41:52 UTC


README

html is a small, simple library for HTML markup creation, inspired by Elm.

Html::article(["class" => "chapter"], [
  Html::header([
    Html::h1(["class" => "chapter__heading"],
      ["Welcome!"]
    ),
  ]),
  Html::div(
    [
      "class" => "chapter__body",
      "style" => ["text-transform" => "uppercase"]
    ],
    ["Lorem ipsum dolor sit amet"]
  )
])

How does it work?

Each HTML element is available as a static method on Html, along with the arbitrary methods Html::element and Html::emptyElement.

Both Html::element and Html::emptyElement take a tag name, followed by attributes. Non-empty elements take a list of children, as well. Everything gets passed in as arrays, both attributes and children. Child elements are recursively rendered, and attributes are rendered according to a predefined ruleset.

The default ruleset is the standard HTML attribute format, attribute="value". There are also formats defined for style, sizes and srcset.

Installation

Clone repo, download and unpackage the files, or install via Composer. The package is available as lysande/html.

In the future

  • Allow elements to define children, without attributes
  • React-/JSX-like true/false for boolean attributes
  • Declare singular children without arrays