aredridel / html5

Event-driven HTML5 Parser in Javascript
http://dinhe.net/~aredridel/projects/js/html5/
MIT License
590 stars 168 forks source link

The combination of contentHandler and lexicalHandler #112

Open eGavr opened 10 years ago

eGavr commented 10 years ago

You have written this:

"No. There is a lexicalHandler, that can handle comments, doctype, cdata sections. But this feature is not implemented yet (but it is very easy to do)."

Are you going to do this?)

I mean, it would be great if you could combine contentHandler and lexicalHandler into one Handler!

This way, everybody will be able to create the DOM tree of HTML code in manner as they want!

danyaPostfactum commented 10 years ago

You can combine both handlers, there are no limitations.

parser.contentHandler = parser.lexicalHandler = {
    /* implement both interfaces */
};

These interfaces are described by SAX project: http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html http://www.saxproject.org/apidoc/org/xml/sax/ext/LexicalHandler.html

By the way, I was wrong about CDATA sections: HTML5 tokenizer does not produce these. CDATA is illegal in HTML(treated as comment), but allowed in foreign content, such as SVG or MathML.