{"id":24983698,"url":"https://github.com/posthtml/posthtml-extra-attributes","last_synced_at":"2025-06-17T05:37:50.419Z","repository":{"id":38844197,"uuid":"262815916","full_name":"posthtml/posthtml-extra-attributes","owner":"posthtml","description":"Add new attributes to elements in your HTML","archived":false,"fork":false,"pushed_at":"2025-04-11T15:57:41.000Z","size":1916,"stargazers_count":5,"open_issues_count":1,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-11T20:52:13.209Z","etag":null,"topics":["attributes","html","posthtml","posthtml-plugin"],"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/posthtml.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":"posthtml","open_collective":"posthtml","ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":"mailviews.com"}},"created_at":"2020-05-10T15:22:12.000Z","updated_at":"2025-04-09T20:54:08.000Z","dependencies_parsed_at":"2024-11-05T22:33:26.483Z","dependency_job_id":"882f17f8-4c3f-434f-8e80-75b4e6b8709f","html_url":"https://github.com/posthtml/posthtml-extra-attributes","commit_stats":{"total_commits":118,"total_committers":3,"mean_commits":"39.333333333333336","dds":0.3813559322033898,"last_synced_commit":"c34d4b8073d32f42d84178f9a05e96aceb895b79"},"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-extra-attributes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-extra-attributes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-extra-attributes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-extra-attributes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-extra-attributes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248480516,"owners_count":21110936,"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":["attributes","html","posthtml","posthtml-plugin"],"created_at":"2025-02-04T09:20:21.323Z","updated_at":"2025-04-11T20:52:17.608Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"150\" height=\"150\" title=\"PostHTML\" src=\"https://posthtml.github.io/posthtml/logo.svg\"\u003e\n  \u003ch1\u003eExtra Attributes\u003c/h1\u003e\n  \u003cp\u003eAdd new attributes to elements in your HTML\u003c/p\u003e\n\n  [![Version][npm-version-shield]][npm]\n  [![Build][github-ci-shield]][github-ci]\n  [![License][license-shield]][license]\n  [![Downloads][npm-stats-shield]][npm-stats]\n\u003c/div\u003e\n\n## Introduction\n\nThis PostHTML plugin can add extra attributes to elements in your HTML.\n\nFeatures:\n\n- supports a variety of CSS-like selectors\n- appends class names to existing ones\n- does not overwrite existing attributes\n\n## Installation\n\n```\nnpm i posthtml posthtml-extra-attributes\n```\n\n## Usage\n\n```js\nimport posthtml from 'posthtml'\nimport addAttributes from 'posthtml-extra-attributes'\n\nposthtml([\n  addAttributes({\n    attributes: {\n      div: {\n        class: 'new',\n        id: 'new'\n      }\n    }\n  })\n])\n  .process('\u003cdiv class=\"test\"\u003eTest\u003c/div\u003e')\n  .then(result =\u003e console.log(result.html))\n\n// \u003cdiv class=\"test new\" id=\"new\"\u003eTest\u003c/div\u003e\n```\n\n## Options\n\n### `attributes`\n\nType: `Object`\\\nDefault: `{}`\n\nAn object defining which elements should get what attributes.\n\nElements can be any [posthtml-match-helper](https://github.com/phloe/posthtml-match-helper) selector.\n\n#### Select by tag\n\nAdd `id=\"new\"` to all `\u003cdiv\u003e` tags:\n\n```js\nconst attributes = {\n  div: {\n    id: 'new'\n  },\n}\n```\n\n#### Select by class\n\nAdd `editable=\"true\"` to all elements with a `test` class:\n\n```js\nconst attributes = {\n  '.test': {\n    'editable': true\n  },\n}\n```\n\n#### Select by id\n\nAdd `class=\"new\"` to any element with `id=\"test\"`:\n\n```js\nconst attributes = {\n  '#test': {\n    class: 'new'\n  },\n}\n```\n\nIf the element already has a `class` attribute, the value will be appended:\n\n```html\n\u003cdiv id=\"test\" class=\"test\"\u003eTest\u003c/div\u003e\n```\n\n... will result in:\n\n```html\n\u003cdiv id=\"test\" class=\"test new\"\u003eTest\u003c/div\u003e\n```\n\n#### Select by attribute\n\nAdds `aria-roledescription=\"slide\"` to all elements with a `role` attribute:\n\n```js\nconst attributes = {\n  '[role]': {\n    'aria-roledescription': 'slide'\n  },\n}\n```\n\n#### Select multiple tags\n\nAdd multiple attributes to multiple elements in one go:\n\n```js\nconst attributes = {\n  'div, p': {\n    class: 'test',\n  },\n  'div[role=alert], section.alert': {\n    class: 'alert'\n  },\n}\n```\n\n### `overwrite`\n\nType: `Boolean`\\\nDefault: `false`\n\nBy default, the plugin will not overwrite existing attribute values.\n\nSet this option to `true` to enable attribute value overwriting:\n\n```js\nposthtml([\n  addAttributes({\n    attributes: {\n      div: {\n        id: 'new'\n      }\n    },\n    overwrite: true\n  })\n])\n  .process('\u003cdiv id=\"test\"\u003eTest\u003c/div\u003e')\n  .then(result =\u003e console.log(result.html))\n\n// \u003cdiv id=\"new\"\u003eTest\u003c/div\u003e\n```\n\n[npm]: https://www.npmjs.com/package/posthtml-extra-attributes\n[npm-version-shield]: https://img.shields.io/npm/v/posthtml-extra-attributes.svg\n[npm-stats]: http://npm-stat.com/charts.html?package=posthtml-extra-attributes\n[npm-stats-shield]: https://img.shields.io/npm/dt/posthtml-extra-attributes.svg\n[github-ci]: https://github.com/posthtml/posthtml-extra-attributes/actions\n[github-ci-shield]: https://github.com/posthtml/posthtml-extra-attributes/actions/workflows/nodejs.yml/badge.svg\n[license]: ./LICENSE\n[license-shield]: https://img.shields.io/npm/l/posthtml-extra-attributes.svg\n","funding_links":["https://patreon.com/posthtml","https://opencollective.com/posthtml","mailviews.com"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-extra-attributes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-extra-attributes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-extra-attributes/lists"}