siddMahen/cheerio — comment on commit 525a1dfde6f40ffa289c061e024d7e191e2dea9f
File:  line 0
By siddMahen:

I didn't think I was exposing anything new at all, because both the render and the parser are part of cheerio, as specified in the `index.js`:

```
/*
Attach objects to cheerio
*/
exports.parse = require('./lib/parse');
exports.render = require('./lib/render');
exports.utils = require('./lib/utils');
```

Exposing the render as I did, I made it easier to access the main `cheerio` object, so that global options (related to parsing or rendering etc..) were available without conflicts and everything behaved as expected when you set an option. For example, with the `xmlMode` bug:

```
var cheerio = require("cheerio"),
$ = cheerio.load('', { xmlMode: true });

// this xmlMode has to carry over into other parsing operations as well
$('root').append($('').text('foo'));
$('root').append($('').text('some text'));
console.log($.html());
```

Expected result:

```
foosome text
```

Actual result:

```
foosome text
```

Before I made the parser a part of the api, I would have had to somehow get access and check with the global variable every time I wanted to parse something, so that it is consistent with the option(s) specified in `load`. That is a huge pain for programmers and is sure to introduce bugs. So I just added the parser as part of cheerio, so that I could abstract out the access of options and so forth. That way, everything related to options is only contained in the parser, and the user sees consistent results across the board.

The same thing carries over to the renderer, where I wanted to access options to make sure I was rendering things correctly (for example `xmlMode`).

As for even providing these options in the first place, I think that they are trivially simple to implement and maintain, and they provide tons of additional functionality. I understand that the lib shouldn't stray too far from jQuery but I feel as though it has the potential to be even more useful than jQuery, and we shouldn't restrict ourselves. For example, using cheerio to manipulate xml is a great idea! And it's do-able in less than 10 lines of code! Why settle? Plus these things might improve cheerio's compatibility with stuff like XHTML (I know, that means about 4 people, but the point is the same). Plus, I don't think that adding these sorts of features and removing inconsistencies or improving performance are at all mutually exclusive.