Requirements

Sorry, but it requires PHP >= 7 right now. The only real thing causing this is
the type hinting right now. I'll eventually get around to making a PHP 5.x
version. Eventually. Probably.

API

html(stringtag [,assocattributes],mixed...children) : RawString

This is your bread and butter. See the exaples for more help. Reminder:
htmlgen\RawString is an implementation detail and should be ignored. Never
write tests against this type or check $html instanceof RawString. Just know
that RawString can be coerced to a string so just treat it as such.

map(arrayxs,callableλ(mixedv,mixedk):string):array

This function is very helpful for building lists of nodes from existing data.
This exists because array_map doesn't pass in array keys by default. Also,
note the order of arguments in this function compared to native array_map.
See the code examples below for more details.

raw(stringhtml):RawString

All child strings passed to html will automatically have html entities encoded
using htmlentities($str, ENT_HTML5). If you would like to bypass encoding, you
can wrap a string using this function.

render(resourcewritableStream,mixed...children) : int

Most people will probably just use echo html(...) which is fine, but render
is a bit more flexible as it allows you to render to any writable stream. That
means render(STDOUT, html(...)) is effectively the same as echo html(...).
Use this for writing html to files render($fd, ...) or to memory
$mem = fopen('php://memory'); render($mem, ...), or skip render altogether
and just $html = html(...); doSomething($html); It's PHP, you can figure it
out.

capture(callablef[,...xs] ) : RawString

Use this when you have an unmaneuverable, unwieldy, clumsy, impure function such
as 100% of the functions found within WordPress. This will conveniently hijack
any function that otherwise writes to STDOUT and instead bottles it up in
string. capture('the_title') will return a string instead of echoing. If you
need to pass arguments, you can capture('the_title', $postId) or you can even
use a lambda, capture(function($id) { the_title($id); }, $postId) or
capture(function() use($postId) { the_title($postId); }). Remember, how I said
it's just PHP ? It's just PHP. And yes I know get_the_title exists. This is
an example.

Oh yeah, it should go without saying that capture is not a magician or a
mind-reader. It wil not automatically encode HTML entities returned from the
callable. It can (and does) promise not to double encode HTML entities, tho.

WARNINGS

htmlgen displays html entities only. A special string wrapper is required
to output raw HTML strings. Guess what that helper is called? It's called
raw. I already said that above. C'mon.