Re:Show HN: Single-header C++11 HTML document constructor
by Negitivefrags on Sunday December 16, 2018 @06:59PM
(#18696020)
You would implement that like this:
HTML::document d;
HTML::p p( d );
d.text( "Hello, " );
{
HTML::span s( d );
d.text( "world!" );
}
d.text( " Welcome!" );
Obviously though, if you were trying to do an HTML parser as well, then my ideas are not appropriate.
However, the helper types could be useful, and might be able to be implemented as simple aliases to a Node. Also, the reason I take the approach of appending child nodes is for representing actual HTML easier. For instance, with your .text example (at least with my limited glance on it), you can't do something such as <p>Hello, <span>world!</span> Welcome!</p>, which was actually a previous problem that I had with another version of the library.