-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Lack of documentation. #110
Comments
Yes indeed! Needs some TLC. Any aspects you want to see first? |
Since the project is used widely used with JSDOM, an annotated (JSDOM) example should always be up to date. |
Can you give a real work example of using your tool in |
The v1.0.1 README now has an example. |
Thank you, but it seems, that it is not simple example. Why is ti so difficult? Lots of code for such a simple example... Can I do something like this: var parser = require('parse5');
var html = '<p>blah</p>';
console.log(parser.parse(html)); and after |
HTML5 does not contain any DOM implementation. So, you have to provide it. var HTML5 = require('html5');
var jsdom = require('jsdom');
var DOMImplementation = jsdom.level(3).DOMImplementation;
var parser = new HTML5.DOMParser(new DOMImplementation());
var document = parser.parse('<p>I am a very small HTML document</p>');
console.log(document.getElementsByTagName("p")[0].textContent); Also, take a look at SAXParser: var HTML5 = require('html5');
var parser = new HTML5.SAXParser();
parser.contentHandler = {
startDocument: function() {},
endDocument: function() {},
startElement: function(uri, localName, qName, atts) {
console.log('Start of <' + localName + '> element');
},
endElement: function(uri, localName, qName) {
console.log('End of <' + localName + '> element');
},
characters: function(ch, start, length) {
console.log('Characters: ' + ch);
}
};
parser.parse('<p>I am a very small HTML document</p>');
|
Great! I think that SAXParser is that what I need! BUT! <p>I am a very small HTML document</p> Where is the Can I receive the info exactly about the input? |
Parser creates all these elements according to HTML spec (browsers do the same). parser.parseFragment('<p>I am a very small HTML document</p>', 'body'); Fragment parsing was broken. I fixed it right now, so you need to pull latest change (still not sure i fixed the bug properly).
No, you receive repaired, well-formed output. This parser may create, forbid, reparent elements etc according to the HTML5 parsing specification. |
var HTML5 = require('html5');
var parser = new HTML5.SAXParser();
parser.contentHandler = {
startDocument: function() {console.log('!!!!')},
endDocument: function() {console.log('????')},
startElement: function(uri, localName, qName, atts) {
console.log("qNAme == ", qName)
console.log(atts)
console.log('Start of <' + localName + '> element');
},
endElement: function(uri, localName, qName) {
console.log('End of <' + localName + '> element');
},
characters: function(ch, start, length) {
console.log('Characters: ' + ch);
}
};
parser.parseFragment('<p>I am a very small HTML document</p>', 'body'); This code doesn't work! I'm sorry ) Probably there is a silly mistake I haven't noticed! Can you help me? |
Can you give the information about Are there anything else? |
This code works. You should pull this fix: 4ff67be
No. There is a |
Are you going to do this?) I mean, it would be great if you could combine This way, everybody will be able to create the DOM tree of |
Start an issue for 'em -- this one's about docs! -- and we'll go from there. |
And that fix is shipped in v1.0.3 |
Lexical handler now can be defined: parser.lexicalHandler = {
comment: function(data) {
console.log('Comment: ' + data);
},
startDTD: function(name, publicIdentifier, systemIdentifier) {
console.log('Doctype: ' + name);
},
endDTD: function() {}
}; contentHandler is required, while lexicalHandler is optional. http://www.saxproject.org/apidoc/org/xml/sax/ContentHandler.html
Right. With SAXParser they are able. |
Is it in v1.0.3? |
Yep. |
There's a lack of documentation, even the example of the README is outdated or isn't explained correctly.
The text was updated successfully, but these errors were encountered: