client.js 986 B

123456789101112131415161718192021222324252627
  1. 'use strict';
  2. var cheerio = require('./lib/cheerio');
  3. var makeJuiceClient = require('./lib/inline');
  4. /**
  5. * Note that makeJuiceClient will take a base object (in this case a function) and enhance it
  6. * with a lot of useful properties and functions.
  7. *
  8. * This client adopts cheerio as a DOM parser and adds an "inlineContent" function that let
  9. * users to specify the CSS to be inlined instead of extracting it from the html.
  10. *
  11. * The weird "makeJuiceClient" behaviour is there in order to keep backward API compatibility.
  12. */
  13. var juiceClient = makeJuiceClient(function(html,options) {
  14. return cheerio(html, { xmlMode: options && options.xmlMode}, juiceDocument, [options]);
  15. });
  16. var juiceDocument = function(html, options) {
  17. return juiceClient.juiceDocument(html, options);
  18. }
  19. juiceClient.inlineContent = function(html, css, options) {
  20. return cheerio(html, { xmlMode: options && options.xmlMode}, juiceClient.inlineDocument, [css, options]);
  21. };
  22. module.exports = juiceClient;