Hacker News new | ask | show | jobs
by tinfoilboy 2737 days ago
While I do agree with the idea of outputting HTML quickly, I think that in the end I'd want to emulate the DOM more closely. For instance, I've been thinking about adding a simple parser to the library so that I could use it in making a web scraper. With a replication of the DOM, I could then easily find nodes that I'd like to grab from the scraper. In addition, I was also thinking of adding actual element grabbing via selectors a la CSS, which would require a DOM representation.

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.

1 comments

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.