Expose DOM level 1 API for Node-like objects#561
Conversation
Now that htmlparser2's default DomHandler supports the `withDomLvl1` option, enable it by default for all parsed content. Update the project documentation and tests to use this standard API to exemplify usage.
|
This is great! It warrants at least a minor version bump, of course. |
|
No objection here. Just to be clear: I think a minor version is exactly appropriate (not "at least") because this change only adds API--all previously-existing properties on the Node-like remain. |
Oh, I didn't realize this is the case. Thanks for correcting me. |
Instead of implicitly relying on other unit tests to exhaustively assert the "shape" of the Node-like object's API, define a single test to ensure that the documented properties are available and functioning as expected.
|
@davidchambers No problem--glad I didn't come off as (too) pedantic there :P Also: I just pushed up an additional commit that adds a single test for this API. As noted in the commit message, this explicltly ensures that all the documented attributes are functioning correctly (so we can be positive the documented API is available even if the other tests should change). |
|
LGTM |
|
Thanks, @davidchambers @matthewmueller @fb55 Would either of you mind looking this over an merging? |
Expose DOM level 1 API for Node-like objects
|
Thanks @jugglinmike! |
Now that Cheerio preserves parsing options, we can use the
withDomLvl1option in htmlparser2's defaultDomHandler(which we prototyped in gh-308) to expose a standard API for the Node-like objects that Cheerio builds.I've updated the tests and documentation to demonstrate this usage, but I've left the internals untouched. Because the new API is defined via ES5 "getters", it will be slightly more efficient to use the original, non-standard API internally. If anyone thinks that this could cause more confusion than its worth (probably justified via our benchmarks), I'd be happy to update the internals as well.
Commit message: