{"id":13558273,"url":"https://github.com/premailer/premailer","last_synced_at":"2025-05-13T17:04:07.482Z","repository":{"id":837708,"uuid":"386126","full_name":"premailer/premailer","owner":"premailer","description":"Preflight for HTML email","archived":false,"fork":false,"pushed_at":"2025-04-01T16:27:23.000Z","size":1054,"stargazers_count":2364,"open_issues_count":97,"forks_count":365,"subscribers_count":57,"default_branch":"master","last_synced_at":"2025-05-06T16:12:09.530Z","etag":null,"topics":["css","inline","mail","nokogiri","premailer","ruby"],"latest_commit_sha":null,"homepage":"https://premailer.github.io/premailer","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/premailer.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2009-11-26T05:31:46.000Z","updated_at":"2025-05-06T07:25:52.000Z","dependencies_parsed_at":"2023-07-06T08:33:45.641Z","dependency_job_id":"5baab621-a53b-4aae-8e7b-d8b4d7a09ce6","html_url":"https://github.com/premailer/premailer","commit_stats":{"total_commits":636,"total_committers":125,"mean_commits":5.088,"dds":0.7232704402515724,"last_synced_commit":"276073f76b1cd61925309476a87d8a3afbe27ea7"},"previous_names":[],"tags_count":52,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fpremailer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fpremailer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fpremailer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/premailer%2Fpremailer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/premailer","download_url":"https://codeload.github.com/premailer/premailer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252851255,"owners_count":21814103,"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":["css","inline","mail","nokogiri","premailer","ruby"],"created_at":"2024-08-01T12:04:51.239Z","updated_at":"2025-05-13T17:04:07.417Z","avatar_url":"https://github.com/premailer.png","language":"Ruby","readme":"# Premailer README [![CI](https://github.com/premailer/premailer/actions/workflows/actions.yml/badge.svg)](https://github.com/premailer/premailer/actions/workflows/actions.yml) [![Gem Version](https://badge.fury.io/rb/premailer.svg)](https://badge.fury.io/rb/premailer)\n\n## What is this?\n\nFor the best HTML e-mail delivery results, CSS should be inline. This is a\nhuge pain and a simple newsletter becomes un-managable very quickly. This\ngem is a solution.\n\n* CSS styles are converted to inline style attributes\n  - Checks `style` and `link[rel=stylesheet]` tags and preserves existing inline attributes\n* Relative paths are converted to absolute paths\n  - Checks links in `href`, `src` and CSS `url('')`\n* CSS properties are checked against e-mail client capabilities\n  - Based on the Email Standards Project's guides\n* A [plain text version](#plain-text-version) is created (optional)\n\n## Installation\n\n```bash\ngem install premailer\n```\n\n## Example\n\n```ruby\nrequire 'premailer'\n\npremailer = Premailer.new('http://example.com/myfile.html', warn_level: Premailer::Warnings::SAFE)\n\n# Write the plain-text output (must come before to_inline_css)\nFile.write \"output.txt\", premailer.to_plain_text\n\n# Write the HTML output\nFile.write \"output.html\", premailer.to_inline_css\n\n# Output any CSS warnings\npremailer.warnings.each do |w|\n  puts \"#{w[:message]} (#{w[:level]}) may not render properly in #{w[:clients]}\"\nend\n```\n\n## Adapters\n\n1. nokogiri (default)\n2. nokogiri_fast (20x speed, more memory)\n3. nokogumbo\n\n(hpricot adapter removed, use `~\u003e1.9.0` version if you need it)\n\nPicking an adapter:\n\n```ruby\nPremailer::Adapter.use = :nokogiri_fast\n```\n\n## Ruby Compatibility\n\nSee .github/workflows/actions.yml for which ruby versions are tested. JRuby support is close, contributors are welcome.\n\n## Premailer-specific CSS\n\nPremailer looks for a few CSS attributes that make working with tables a bit easier.\n\n| CSS Attribute | Availability |\n| ------------- | ------------ |\n| -premailer-width | Available on `table`, `th` and `td` elements |\n| -premailer-height | Available on `table`, `tr`, `th` and `td` elements |\n| -premailer-cellpadding | Available on `table` elements |\n| -premailer-cellspacing | Available on `table` elements |\n| -premailer-align | Available on `table` elements |\n| data-premailer=\"ignore\" | Available on `link` and `style` elements. Premailer will ignore these elements entirely. |\n\nEach of these CSS declarations will be copied to appropriate element's attribute.\n\nFor example\n\n```css\ntable { -premailer-cellspacing: 5; -premailer-width: 500; }\n```\n\nwill result in\n\n```html\n\u003ctable cellspacing='5' width='500'\u003e\n```\n\n## Plain text version\n\nPremailer can generate a plain text version of your HTML. Links and images will be inlined.\n\nFor example\n\n```html\n\u003ca href=\"https://example.com\" \u003e\n  \u003cimg src=\"https://github.com/premailer.png\" alt=\"Premailer Logo\" /\u003e\n\u003c/a\u003e\n```\n\nwill become\n\n```text\nPremailer Logo ( https://example.com )\n```\n\nTo ignore/omit a section of HTML content from the plain text version, wrap it with the following comments.\n\n```html\n\u003c!-- start text/html --\u003e\n\u003cp\u003eThis will be omitted from the plain text version.\u003c/p\u003e\n\u003cp\u003e\n  This is extremely helpful for \u003cstrong\u003eremoving email headers and footers\u003c/strong\u003e\n  that aren't needed in the text version.\n\u003c/p\u003e\n\u003c!-- end text/html --\u003e\n```\n\n## Configuration options\n\nFor example:\n```ruby\nPremailer.new(\n  html, # html as string\n  with_html_string: true,\n  drop_unmergeable_css_rules: true\n)\n```\n\n[available options](https://premailer.github.io/premailer/Premailer.html#initialize-instance_method)\n\n## Support for CSS variables\n\nThe gem does not automatically replace CSS variables with their static values.\n\nFor example, if a variable is used to set the `font-weight` of an `h1` element, the result will be\n```html\n\u003ch1 style=\"\n  font-size:3rem;\n  font-weight:var(--bulma-content-heading-weight);\"\u003e\n  Title\u003c/h1\u003e\n```\n\nThis causes the `font-weight` value to be the CSS variable call `var(--bulma-content-heading-weight);` instead of its static value.\n\n### Replace CSS variable calls with their static values\n\nThe following section instructs how to replace CSS variables with their static value in the context of a Ruby on Rails application.\n\nInstall the `postcss-css-variables` plugin for PostCSS to process the CSS variables.\n\n```shell\nyarn add postcss postcss-cli postcss-css-variables\n```\n\nTo configure the plugin, create the file `postcss.config.js` in the root directory with the content:\n\n```javascript\nmodule.exports = {\n    plugins: [\n        // https://github.com/MadLittleMods/postcss-css-variables to transform the css\n      require(\"postcss-css-variables\")({\n        preserve: false, // Set to false to replace variables with static values\n      }),\n    ],\n  };\n```\n\nIn the `package.json` file, add the new \"build:emails\" to the scripts.\u003cbr\u003eReplace `./app/assets/stylesheets/emails.css` with your file path:\n```json\n\"scripts\": {\n  \"build:emails\": \"postcss ./app/assets/stylesheets/emails.css -o ./app/assets/builds/emails.css\"\n}\n```\n\nThe previous script processes and overwrites the file at `./app/assets/stylesheets/emails.css` with PostCSS using its `postcss-css-variables` plugin, replacing the CSS variables with their static value.\n\nIf the file to be processed is not `.css`, but `.scss`, it needs to be converted first to `.css`, then have its variables replaced. The script would then be\n\n```json\n\"scripts\": {\n  \"build:emails\": \"sass ./app/assets/stylesheets/emails.scss:./app/assets/builds/emails.css --no-source-map --load-path=node_modules \u0026\u0026 postcss ./app/assets/builds/emails.css -o ./app/assets/builds/emails.css\"\n}\n```\n\nNext, to execute the script when running `bin/dev`, add the following line in the file `Procfile.dev`\n\n```\nemails_css: yarn build:emails --watch\n```\n\nThe srcipt can also be executed separately with the command\n\n```shell\nyarn build:emails\n```\n\n### Caveat\n\nThe variables must be declared before use. Otherwise, their values when called will be set to `undefined`.\n\n## Contributions\n\nContributions are most welcome.\nPremailer was rotting away in a private SVN repository for too long and could use some TLC.\nFork and patch to your heart's content.\nPlease don't increment the version numbers.\n\nA few areas that are particularly in need of love:\n\n* Improved test coverage\n* Move un-repeated background images defined in CSS for Outlook\n\n## Credits and code\n\nThanks to [all the wonderful contributors](https://github.com/premailer/premailer/contributors) for their updates.\n\nThanks to [Greenhood + Company](http://www.greenhood.com/) for sponsoring some of the 1.5.6 updates,\nand to [Campaign Monitor](https://www.campaignmonitor.com/) for supporting the web interface.\n\nThe source code can be found on [GitHub](https://github.com/premailer/premailer).\n\nCopyright by Alex Dunae (dunae.ca, e-mail 'code' at the same domain), 2007-2017.  See [LICENSE.md](https://github.com/premailer/premailer/blob/master/LICENSE.md) for license details.\n","funding_links":[],"categories":["Ruby","Github Repositories","css"],"sub_categories":["Cool projects to take a look"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpremailer%2Fpremailer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpremailer%2Fpremailer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpremailer%2Fpremailer/lists"}