{"id":30680649,"url":"https://github.com/knowledgecode/postcss-inline-extract","last_synced_at":"2025-09-01T16:51:13.732Z","repository":{"id":310760440,"uuid":"1041148209","full_name":"knowledgecode/postcss-inline-extract","owner":"knowledgecode","description":"PostCSS plugin to extract inline styles from HTML and convert them to CSS rules","archived":false,"fork":false,"pushed_at":"2025-08-20T04:10:13.000Z","size":0,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-08-20T04:40:59.907Z","etag":null,"topics":["css","extract","html","inline-styles","postcss-plugin","style-attributes"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/knowledgecode.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"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":"2025-08-20T04:00:53.000Z","updated_at":"2025-08-20T04:10:50.000Z","dependencies_parsed_at":"2025-08-20T04:41:04.712Z","dependency_job_id":"1e506eb8-eed9-41b5-942c-307deaabb445","html_url":"https://github.com/knowledgecode/postcss-inline-extract","commit_stats":null,"previous_names":["knowledgecode/postcss-inline-extract"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/knowledgecode/postcss-inline-extract","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fpostcss-inline-extract","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fpostcss-inline-extract/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fpostcss-inline-extract/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fpostcss-inline-extract/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/knowledgecode","download_url":"https://codeload.github.com/knowledgecode/postcss-inline-extract/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/knowledgecode%2Fpostcss-inline-extract/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273158948,"owners_count":25055859,"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","status":"online","status_checked_at":"2025-09-01T02:00:09.058Z","response_time":120,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","extract","html","inline-styles","postcss-plugin","style-attributes"],"created_at":"2025-09-01T16:51:09.415Z","updated_at":"2025-09-01T16:51:13.718Z","avatar_url":"https://github.com/knowledgecode.png","language":"TypeScript","readme":"# PostCSS Inline Extract\n\n[\u003cimg src=\"https://postcss.org/logo.svg\" alt=\"PostCSS Logo\" width=\"90\" height=\"90\" align=\"right\"\u003e][PostCSS]\n\n[![CI](https://github.com/knowledgecode/postcss-inline-extract/actions/workflows/ci.yml/badge.svg)](https://github.com/knowledgecode/postcss-inline-extract/actions/workflows/ci.yml)\n[![npm](https://img.shields.io/npm/v/postcss-inline-extract)](https://www.npmjs.com/package/postcss-inline-extract)\n\n[PostCSS] plugin to extract inline styles from HTML and convert them to CSS rules.\n\nThis plugin helps you extract `style` attributes from HTML elements and convert them into structured CSS rules with customizable selectors.\n\n```css\n/* Input CSS (empty or existing styles) */\n\n/* HTML input with inline styles */\n\u003cdiv style=\"color: red; margin: 10px;\" class=\"button\"\u003eClick me\u003c/div\u003e\n\u003cspan style=\"font-size: 14px;\" id=\"text\"\u003eHello\u003c/span\u003e\n```\n\n```css\n/* Output CSS */\n.button {\n  color: red;\n  margin: 10px;\n}\n\n#text {\n  font-size: 14px;\n}\n```\n\n## Features\n\n- Extract inline styles from HTML `style` attributes\n- Multiple selector generation strategies (class, id, hash)\n- Optional extraction from `\u003cstyle\u003e` tags\n- Automatic property merging for duplicate selectors\n- TypeScript support with full type definitions\n- Fast and lightweight with minimal dependencies\n\n## Installation\n\n```bash\nnpm install --save-dev postcss postcss-inline-extract\n```\n\n## Usage\n\n### Basic Usage\n\n```javascript\nconst postcss = require('postcss');\nconst inlineExtract = require('postcss-inline-extract');\n\nconst html = `\n  \u003cdiv style=\"color: red; margin: 10px;\" class=\"button\"\u003eClick me\u003c/div\u003e\n  \u003cspan style=\"font-size: 14px;\" class=\"text\"\u003eHello\u003c/span\u003e\n`;\n\npostcss([\n  inlineExtract({ html })\n])\n  .process('', { from: undefined })\n  .then(result =\u003e {\n    console.log(result.css);\n    /*\n    .button {\n      color: red;\n      margin: 10px;\n    }\n    .text {\n      font-size: 14px;\n    }\n    */\n  });\n```\n\n### With PostCSS Configuration\n\n```javascript\n// postcss.config.js\nmodule.exports = {\n  plugins: [\n    require('postcss-inline-extract')({\n      html: require('fs').readFileSync('src/index.html', 'utf8')\n    })\n  ]\n};\n```\n\n## Options\n\n### `html` (required)\n\nType: `string`\n\nThe HTML content to extract inline styles from.\n\n```javascript\ninlineExtract({\n  html: '\u003cdiv style=\"color: red;\" class=\"button\"\u003eClick me\u003c/div\u003e'\n})\n```\n\n### `selector`\n\nType: `'class' | 'id' | 'hash' | Array\u003c'class' | 'id' | 'hash'\u003e`  \nDefault: `'class'`\n\nStrategy for generating CSS selectors:\n\n- `'class'`: Use existing `class` attribute (`.className`). Elements without a `class` attribute will be ignored.\n- `'id'`: Use existing `id` attribute (`#idName`). Elements without an `id` attribute will be ignored.\n- `'hash'`: Generate random hash selectors (`.abc123`) for all elements with inline styles.\n\n```javascript\n// Use class attributes\ninlineExtract({\n  html: htmlContent,\n  selector: 'class'\n})\n\n// Use ID attributes\ninlineExtract({\n  html: htmlContent,\n  selector: 'id'\n})\n\n// Priority order: try class first, then id\ninlineExtract({\n  html: htmlContent,\n  selector: ['class', 'id']\n})\n```\n\n### `styleTags`\n\nType: `boolean`  \nDefault: `false`\n\nWhether to also extract CSS from `\u003cstyle\u003e` tags in the HTML.\n\n```javascript\ninlineExtract({\n  html: `\n    \u003cstyle\u003e\n      .existing { margin: 20px; }\n    \u003c/style\u003e\n    \u003cdiv style=\"color: red;\" class=\"button\"\u003eClick me\u003c/div\u003e\n  `,\n  styleTags: true\n})\n```\n\n### `indent`\n\nType: `number`  \nDefault: `2`\n\nNumber of spaces for CSS indentation.\n\n```javascript\ninlineExtract({\n  html: htmlContent,\n  indent: 4\n})\n```\n\n## Examples\n\n### Multiple Classes (Compound Selectors)\n\n```html\n\u003cdiv style=\"color: blue; padding: 15px;\" class=\"button primary large\"\u003e\n  Submit Button\n\u003c/div\u003e\n```\n\n```css\n/* Output: Creates compound selector from multiple classes */\n.button.primary.large {\n  color: blue;\n  padding: 15px;\n}\n```\n\n### Multiple Elements with Same Class\n\n```html\n\u003cdiv style=\"color: red;\" class=\"button\"\u003eButton 1\u003c/div\u003e\n\u003cdiv style=\"margin: 10px;\" class=\"button\"\u003eButton 2\u003c/div\u003e\n```\n\n```css\n/* Output: Properties are automatically merged */\n.button {\n  color: red;\n  margin: 10px;\n}\n```\n\n### Hash Selector Generation\n\n```html\n\u003cdiv style=\"color: blue;\"\u003eNo class or ID\u003c/div\u003e\n```\n\n```javascript\ninlineExtract({\n  html: htmlContent,\n  selector: 'hash'\n})\n```\n\n```css\n/* Output: Random hash selector */\n.a1b2c3 {\n  color: blue;\n}\n```\n\n## TypeScript Support\n\nThis plugin includes full TypeScript definitions:\n\n```typescript\nimport postcss from 'postcss';\nimport inlineExtract, { PluginOptions, SelectorType } from 'postcss-inline-extract';\n\nconst options: PluginOptions = {\n  html: '\u003cdiv style=\"color: red;\" class=\"button\"\u003eClick me\u003c/div\u003e',\n  selector: 'class' as SelectorType,\n  styleTags: false,\n  indent: 2\n};\n\nconst processor = postcss([inlineExtract(options)]);\n```\n\n## License\n\n[MIT License](LICENSE)\n\n[PostCSS]: https://github.com/postcss/postcss\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fpostcss-inline-extract","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fknowledgecode%2Fpostcss-inline-extract","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fknowledgecode%2Fpostcss-inline-extract/lists"}