You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # style-data [![Build Status](https://travis-ci.org/jonkemp/style-data.svg?branch=master)](https://travis-ci.org/jonkemp/style-data) [![Coverage Status](https://coveralls.io/repos/jonkemp/style-data/badge.svg?branch=master&service=github)](https://coveralls.io/github/jonkemp/style-data?branch=master)
  2. [![NPM](https://nodei.co/npm/style-data.png?downloads=true)](https://nodei.co/npm/style-data/)
  3. > Get the content of style tags.
  4. ## Install
  5. Install with [npm](https://npmjs.org/package/style-data)
  6. ```
  7. npm install --save style-data
  8. ```
  9. ## Usage
  10. ```js
  11. var getStylesData = require('style-data');
  12. getStylesData(html, options, function (err, results) {
  13. console.log(results.html); // resulting html
  14. console.log(results.css); // array of css rules
  15. });
  16. ```
  17. ## API
  18. ### getStylesData(html, options, callback)
  19. #### options.applyStyleTags
  20. Type: `Boolean`
  21. Default: `true`
  22. Whether to inline styles in `<style></style>`.
  23. #### options.removeStyleTags
  24. Type: `Boolean`
  25. Default: `true`
  26. Whether to remove the original `<style></style>` tags after (possibly) inlining the css from them.
  27. #### options.preserveMediaQueries
  28. Type: `Boolean`
  29. Default: `false`
  30. Preserves all media queries (and contained styles) within `<style></style>` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed.
  31. #### options.codeBlocks
  32. Type: `Object`
  33. Default: `{ EJS: { start: '<%', end: '%>' }, HBS: { start: '{{', end: '}}' } }`
  34. An object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing. For example, Handlebars (hbs) templates are `HBS: {start: '{{', end: '}}'}`. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `codeBlocks: {...}` do `codeBlocks.myBlock = {...}`.
  35. ### Special markup
  36. #### data-embed
  37. When a data-embed attribute is present on a <style></style> tag, style-data will not inline the styles and will not remove the <style></style> tags.
  38. This can be used to embed email client support hacks that rely on css selectors into your email templates.
  39. ### cheerio options
  40. Options to passed to [cheerio](https://github.com/cheeriojs/cheerio).
  41. ## Credit
  42. The code for this module was originally taken from the [Juice](https://github.com/Automattic/juice) library.
  43. ## License
  44. MIT © [Jonathan Kemp](http://jonkemp.com)