html: use a state stack for tracking states

This also changes the state type so it is a pointer to a state
function, avoiding a level of indirection.