{"id":13605012,"url":"https://github.com/jonkemp/inline-css","last_synced_at":"2025-05-13T23:06:53.604Z","repository":{"id":26149121,"uuid":"29594275","full_name":"jonkemp/inline-css","owner":"jonkemp","description":"Inline css into an html file.","archived":false,"fork":false,"pushed_at":"2025-05-01T21:16:46.000Z","size":1756,"stargazers_count":433,"open_issues_count":64,"forks_count":86,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-05-04T18:02:03.484Z","etag":null,"topics":["inline-css"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonkemp.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-01-21T14:48:54.000Z","updated_at":"2025-04-24T23:22:32.000Z","dependencies_parsed_at":"2024-06-18T12:18:02.334Z","dependency_job_id":"7d6bfa0d-0fdc-47d4-96d7-bae45788b60e","html_url":"https://github.com/jonkemp/inline-css","commit_stats":{"total_commits":484,"total_committers":24,"mean_commits":"20.166666666666668","dds":0.06404958677685946,"last_synced_commit":"1f8474c6de35cea239eedaeb0716607c4592304e"},"previous_names":[],"tags_count":71,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonkemp%2Finline-css","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonkemp%2Finline-css/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonkemp%2Finline-css/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonkemp%2Finline-css/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonkemp","download_url":"https://codeload.github.com/jonkemp/inline-css/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253324483,"owners_count":21890854,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["inline-css"],"created_at":"2024-08-01T19:00:53.680Z","updated_at":"2025-05-13T23:06:48.596Z","avatar_url":"https://github.com/jonkemp.png","language":"JavaScript","readme":"# inline-css [![npm](http://img.shields.io/npm/v/inline-css.svg?style=flat)](https://badge.fury.io/js/inline-css) ![Build Status](https://github.com/jonkemp/inline-css/actions/workflows/main.yml/badge.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/jonkemp/inline-css/badge.svg?branch=master\u0026service=github)](https://coveralls.io/github/jonkemp/inline-css?branch=master)\n\n[![NPM](https://nodei.co/npm/inline-css.png?downloads=true)](https://nodei.co/npm/inline-css/)\n\n\u003e Inline your CSS properties into the `style` attribute in an html file. Useful for emails.\n\nInspired by the [juice](https://github.com/Automattic/juice) library.\n\n## Features\n- Uses [cheerio](https://github.com/cheeriojs/cheerio) instead of jsdom\n- Works on Windows\n- Preserves Doctype\n- Modular\n- Gets your CSS automatically through style and link tags\n- Functions return [A+ compliant](https://promisesaplus.com/) Promises\n\n## How It Works\n\nThis module takes html and inlines the CSS properties into the style attribute.\n\n`/path/to/file.html`:\n```html\n\u003chtml\u003e\n\u003chead\u003e\n  \u003cstyle\u003e\n    p { color: red; }\n  \u003c/style\u003e\n  \u003clink rel=\"stylesheet\" href=\"style.css\"\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cp\u003eTest\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n`style.css`\n```css\np {\n  text-decoration: underline;\n}\n```\n\nOutput:\n```html\n\u003chtml\u003e\n\u003chead\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n  \u003cp style=\"color: red; text-decoration: underline;\"\u003eTest\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\n## What is this useful for ?\n\n- HTML emails. For a comprehensive list of supported selectors see\n[here](http://www.campaignmonitor.com/css/)\n- Embedding HTML in 3rd-party websites.\n- Performance. Downloading external stylesheets delays the rendering of the page in the browser. Inlining CSS speeds up this process because the browser doesn't have to wait to download an external stylesheet to start rendering the page.\n\n\n## Install\n\nInstall with [npm](https://npmjs.org/package/inline-css)\n\n```\nnpm install --save inline-css\n```\n\n## Usage\n\n```js\nvar inlineCss = require('inline-css');\nvar html = \"\u003cstyle\u003ediv{color:red;}\u003c/style\u003e\u003cdiv/\u003e\";\n\ninlineCss(html, options)\n    .then(function(html) { console.log(html); });\n```\n\n## API\n\n### inlineCss(html, options)\n\n\n#### options.extraCss\n\nType: `String`  \nDefault: `\"\"`\n\nExtra css to apply to the file.\n\n\n#### options.applyStyleTags\n\nType: `Boolean`  \nDefault: `true`\n\nWhether to inline styles in `\u003cstyle\u003e\u003c/style\u003e`.\n\n\n#### options.applyLinkTags\n\nType: `Boolean`  \nDefault: `true`\n\nWhether to resolve `\u003clink rel=\"stylesheet\"\u003e` tags and inline the resulting styles.\n\n\n#### options.removeStyleTags\n\nType: `Boolean`  \nDefault: `true`\n\nWhether to remove the original `\u003cstyle\u003e\u003c/style\u003e` tags after (possibly) inlining the css from them.\n\n\n#### options.removeLinkTags\n\nType: `Boolean`  \nDefault: `true`\n\nWhether to remove the original `\u003clink rel=\"stylesheet\"\u003e` tags after (possibly) inlining the css from them.\n\n#### options.url\n\nType: `String`  \nDefault: `filePath`\n\nHow to resolve hrefs. **Required**.\n\n#### options.preserveMediaQueries\n\nType: `Boolean`  \nDefault: `false`\n\nPreserves all media queries (and contained styles) within `\u003cstyle\u003e\u003c/style\u003e` tags as a refinement when `removeStyleTags` is `true`. Other styles are removed.\n\n#### options.applyWidthAttributes\n\nType: `Boolean`  \nDefault: `false`\n\nWhether to use any CSS pixel widths to create `width` attributes on elements.\n\n#### options.applyTableAttributes\n\nType: `Boolean`  \nDefault: `false`\n\nWhether to apply the `border`, `cellpadding` and `cellspacing` attributes to `table` elements.\n\n#### options.removeHtmlSelectors\n\nType: `Boolean`  \nDefault: `false`\n\nWhether to remove the `class` and `id` attributes from the markup.\n\n#### options.codeBlocks\n\nType: `Object`  \nDefault: `{ EJS: { start: '\u003c%', end: '%\u003e' }, HBS: { start: '{{', end: '}}' } }`\n\nAn object where each value has a `start` and `end` to specify fenced code blocks that should be ignored during parsing and inlining. For example, Handlebars (hbs) templates are `HBS: {start: '{{', end: '}}'}`. `codeBlocks` can fix problems where otherwise inline-css might interpret code like `\u003c=` as HTML, when it is meant to be template language code. Note that `codeBlocks` is a dictionary which can contain many different code blocks, so don't do `codeBlocks: {...}` do `codeBlocks.myBlock = {...}`.\n\n### Special markup\n\n#### data-embed\n\nWhen a data-embed attribute is present on a \u003cstyle\u003e\u003c/style\u003e tag, inline-css will not inline the styles and will not remove the \u003cstyle\u003e\u003c/style\u003e tags.\n\nThis can be used to embed email client support hacks that rely on css selectors into your email templates.\n\n### cheerio options\n\nOptions to passed to [cheerio](https://github.com/cheeriojs/cheerio).\n\n## Contributing\n\nSee the [CONTRIBUTING Guidelines](https://github.com/jonkemp/inline-css/blob/master/CONTRIBUTING.md)\n\n## License\n\nMIT © [Jonathan Kemp](http://jonkemp.com)\n","funding_links":[],"categories":["JavaScript","工具库","Awesome emails"],"sub_categories":["Tools"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonkemp%2Finline-css","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonkemp%2Finline-css","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonkemp%2Finline-css/lists"}