Skip to content

Latest commit

 

History

History
55 lines (45 loc) · 1.18 KB

README.md

File metadata and controls

55 lines (45 loc) · 1.18 KB

koa-cheerio

Simple templating for koa using cheerio. You can use your jQuery knowledge for server-side templating.

Installation

npm install koa-cheerio

Example

views/index.html

<html>
<body>
Hello <span id='hello'></span>!
</body>
</html>
var app = require('koa')();
var render = require('koa-cheerio');

app.use(render({ root: 'views/', ext: '.html' }));

app.use(function *index(next) {
  var $ = yield this.render('index');
  $('#hello').text('World');
});

app.listen(3000);

You can also pass an extra object if you need to modify any of the default parsing options:

var $ = yield this.render('index', {
  normalizeWhitespace: true,
  xmlMode: true
});

Comment from the cheerio-readme: These parsing options are taken directly from htmlparser2, therefore any options that can be used in htmlparser2 are valid in cheerio as well. The default options are:

{
    normalizeWhitespace: false,
    xmlMode: false,
    decodeEntities: true
}

License

MIT