{"id":24983683,"url":"https://github.com/posthtml/posthtml-insert-at","last_synced_at":"2025-08-06T11:10:54.981Z","repository":{"id":36047362,"uuid":"193389743","full_name":"posthtml/posthtml-insert-at","owner":"posthtml","description":"PostHTML plugin to append or prepend HTML to a selector","archived":false,"fork":false,"pushed_at":"2024-04-24T13:53:54.000Z","size":442,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-29T21:06:06.256Z","etag":null,"topics":["append","posthtml","posthtml-plugin","prepend"],"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/posthtml.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}},"created_at":"2019-06-23T19:55:54.000Z","updated_at":"2024-08-06T23:39:54.000Z","dependencies_parsed_at":"2024-05-01T17:20:54.347Z","dependency_job_id":"f695a6b9-0c70-4a6e-82b7-a3e9655f19c2","html_url":"https://github.com/posthtml/posthtml-insert-at","commit_stats":{"total_commits":137,"total_committers":3,"mean_commits":"45.666666666666664","dds":"0.35036496350364965","last_synced_commit":"69f739fe1c1f445c5db583e528cb03831a72be6c"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-insert-at","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-insert-at/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-insert-at/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-insert-at/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-insert-at/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247928590,"owners_count":21019737,"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":["append","posthtml","posthtml-plugin","prepend"],"created_at":"2025-02-04T09:20:16.586Z","updated_at":"2025-04-11T20:51:36.571Z","avatar_url":"https://github.com/posthtml.png","language":"TypeScript","readme":"# posthtml-insert-at \u003cimg align=\"right\" width=\"220\" height=\"200\" title=\"PostHTML logo\" src=\"http://posthtml.github.io/posthtml/logo.svg\"\u003e\n\n[![NPM][npm]][npm-url]\n\n`posthtml-insert-at` is a [PostHTML](https://github.com/posthtml/posthtml) plugin to append or prepend HTML to a selector.\n\n## [Examples](examples/)\n\n**Before:**\n\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cmain\u003e\u003c/main\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n**After:**\n\n```html\n\u003chtml\u003e\n  \u003cbody\u003e\n    \u003cheader\u003e\u003c/header\u003e\n    \u003cmain\u003e\u003c/main\u003e\n    \u003cfooter\u003e\u003c/footer\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n## Install\n\n```bash\nyarn add -D posthtml-insert-at\n# OR\nnpm i posthtml-insert-at\n```\n\n## Usage\n\n```js\nconst fs = require(\"fs\");\nconst posthtml = require(\"posthtml\");\nconst { insertAt } = require(\"posthtml-insert-at\");\n\nconst html = fs.readFileSync(\"./index.html\");\n\nposthtml()\n  .use(\n    insertAt({\n      /**\n       * Specify the selector to append/prepend content to.\n       * Example selectors: `main`, `#id`, `.class`, `main.foo`.\n       */\n      selector: \"main\",\n\n      /**\n       * Prepend HTML markup at the selector.\n       */\n      prepend: `\n        \u003cheader\u003e\n          \u003ca href=\"/\"\u003eHome\u003c/a\u003e\n        \u003c/header\u003e\n      `,\n\n      /**\n       * Append HTML markup at the selector.\n       */\n      append: `\n        \u003cfooter\u003e\n          \u0026copy; ${new Date().getFullYear()}\n        \u003c/footer\u003e\n      `,\n\n      /**\n       * Specify whether to append/prepend content inside or outside (i.e. adjacent to) of the selector.\n       *\n       * The default behavior is `inside`.\n       */\n      behavior: \"outside\",\n    })\n  )\n  .process(html)\n  .then((result) =\u003e fs.writeFileSync(\"./after.html\", result.html));\n```\n\n## Options\n\n| Name       | Kind                                                         | Description                                                         |\n| ---------- | ------------------------------------------------------------ | ------------------------------------------------------------------- |\n| `selector` | **required** `string`                                        | Selector to insert markup at (e.g. `.classname`, `#id` or `tag`)    |\n| `prepend`  | optional `string`                                            | Markup to prepend to the selector                                   |\n| `append`   | optional `string`                                            | Markup to append to the selector                                    |\n| `behavior` | optional (`\"inside\"` or `\"outside\"`) - default is `\"inside\"` | Whether to append/prepend content inside or outside of the selector |\n\nThe plugin accepts an object or an an array of objects.\n\n```js\nconst option = {\n  selector: \"body\",\n  prepend: \"\u003cheader\u003e\u003c/header\u003e\",\n  append: \"\u003cfooter\u003e\u003c/footer\u003e\",\n  behavior: \"inside\",\n};\n\ninsertAt(option);\n// OR\ninsertAt([option /*, ...more options */]);\n```\n\n## Limitations\n\nCurrently, this plugin does not supported nested selectors.\n\n## Contributing\n\nSee the [PostHTML Guidelines](https://github.com/posthtml/posthtml/tree/master/docs).\n\n## [Changelog](CHANGELOG.md)\n\n## License\n\n[MIT](LICENSE)\n\n[npm]: https://img.shields.io/npm/v/posthtml-insert-at.svg?color=blue\n[npm-url]: https://npmjs.com/package/posthtml-insert-at\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-insert-at","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-insert-at","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-insert-at/lists"}