How can there be discussion on HTML generation that doesn't even mention DOM, the standard API for HTML manipulation. Using createElement etc are perfectly valid method of producing HTML.
One big issue is that this API is not available on sever side(node) or in workers.
Sounds more like nodejs problem, other server side languages do have DOM available, for example both Python and Java have it in standard libraries (admittedly as a xml-focused feature)