{"id":24983670,"url":"https://github.com/posthtml/posthtml-import","last_synced_at":"2025-03-29T10:12:37.951Z","repository":{"id":57328798,"uuid":"59313810","full_name":"posthtml/posthtml-import","owner":"posthtml","description":"Import HTML Plugin","archived":false,"fork":false,"pushed_at":"2016-07-09T18:21:10.000Z","size":16,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-29T21:06:05.943Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","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":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-05-20T17:35:42.000Z","updated_at":"2019-09-05T06:53:11.000Z","dependencies_parsed_at":"2022-09-07T16:30:29.266Z","dependency_job_id":null,"html_url":"https://github.com/posthtml/posthtml-import","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-import","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-import/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-import/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/posthtml%2Fposthtml-import/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/posthtml","download_url":"https://codeload.github.com/posthtml/posthtml-import/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245458719,"owners_count":20618697,"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":[],"created_at":"2025-02-04T09:20:16.281Z","updated_at":"2025-03-29T10:12:37.920Z","avatar_url":"https://github.com/posthtml.png","language":"JavaScript","readme":"[![NPM][npm]][npm-url]\n[![Deps][deps]][deps-url]\n[![Tests][travis]][travis-url]\n[![Coverage][cover]][cover-url]\n[![Standard Code Style][style]][style-url]\n\n\u003cdiv align=\"center\"\u003e\n  \u003cimg width=\"220\" height=\"150\" title=\"PostHTML\" src=\"http://posthtml.github.io/posthtml/logo.svg\"\u003e\n  \u003ch1\u003eImport Plugin\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003ch2 align=\"center\"\u003eInstall\u003c/h2\u003e\n\n```bash\nnpm i -D posthtml-import\n```\n\n\u003ch2 align=\"center\"\u003eUsage\u003c/h2\u003e\n\n### Options\n\n**root:** Set base directory, defaults to ``` process.cwd() ```\n\n**encoding:** Set file encoding, defaults to ``` utf8 ```\n\n```html\n\u003cimport src=\"file.html\"\u003e\n```\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cimport src=\"file.html\"\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cimport src=\"/path/to/file.html\"\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nNote that it's necessary to declare the import on its own line for whitespace\ndetection and there could be only one import statement per tag.\n\n\n```html\n\u003c!-- Do --\u003e\n\u003cdiv\u003e\n  \u003cimport src=\"file.html\"\u003e\n\u003c/div\u003e\n\n\u003c!-- Don't --\u003e\n\u003cdiv\u003e\u003cimport src=\"./path/to/file.html\"\u003e\u003c/div\u003e\n```\n\n```html\n\u003c!-- Do --\u003e\n\u003cheader\u003e\n  \u003cimport src=\"file.html\"\u003e\n\u003c/header\u003e\n\u003cmain\u003e\n  \u003cimport src=\"file2.html\"\u003e\n\u003c/main\u003e\n\n\u003c!-- Don't --\u003e\n\u003cdiv\u003e\n  \u003cimport src=\"file.html\"\u003e\n  \u003cimport src=\"file2.html\"\u003e\n\u003c/div\u003e\n```\n\n\u003ch2 align=\"center\"\u003eExample\u003c/h2\u003e\n\n```js\nconst { readFileSync } = require('fs')\n\nconst posthtml = require('posthtml')\nconst imports  = require('posthtml-import')\n\nconst html = readFileSync('./index.html', 'utf8')\n\nposthtml([ imports({root: './path/to/imports'}) ])\n  .process(html)\n  .then((result) =\u003e console.log(result.html))\n```\n\n**index.html**\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003ePostHTML Import\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cnav\u003e\n      \u003cimport src=\"nav.html\"\u003e\n    \u003c/nav\u003e\n    \u003cheader\u003e\n      \u003cimport src=\"header.html\"\u003e\n    \u003c/header\u003e\n    \u003cmain\u003e\n      \u003cimport src=\"main.html\"\u003e\n    \u003c/main\u003e\n    \u003cfooter\u003e\n      \u003cimport src=\"footer.html\"\u003e\n    \u003c/footer\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n**nav.html**\n```html\n\u003cul class=\"nav\"\u003e\n  \u003cli class=\"nav__link\"\u003e\n    \u003ca href=\"#\"\u003eHome\u003c/a\u003e\n  \u003c/li\u003e\n  \u003cli class=\"nav__link\"\u003e\n    \u003ca href=\"#\"\u003eAbout\u003c/a\u003e\n  \u003c/li\u003e\n  \u003cli class=\"nav__link\"\u003e\n    \u003ca href=\"#\"\u003eContact\u003c/a\u003e\n  \u003c/li\u003e\n\u003c/ul\u003e\n```\n\n**header.html**\n```html\n\u003ch1\u003eHello World\u003c/h1\u003e\n```\n\n**main.html**\n```html\n\u003csection class=\"intro\"\u003e...\u003c/section\u003e\n\u003csection class=\"about\"\u003e...\u003c/section\u003e\n\u003csection class=\"outro\"\u003e...\u003c/section\u003e\n```\n\n**footer.html**\n```html\n\u003cdiv class=\"col-md-3\"\u003e...\u003c/div\u003e\n\u003cdiv class=\"col-md-3\"\u003e...\u003c/div\u003e\n\u003cdiv class=\"col-md-3\"\u003e...\u003c/div\u003e\n```\n\n**result.html**\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003cmeta charset=\"utf-8\"\u003e\n    \u003ctitle\u003ePostHTML Import\u003c/title\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003cnav\u003e\n      \u003cul class=\"nav\"\u003e\n        \u003cli class=\"nav__link\"\u003e\n          \u003ca href=\"#\"\u003eHome\u003c/a\u003e\n        \u003c/li\u003e\n        \u003cli class=\"nav__link\"\u003e\n          \u003ca href=\"#\"\u003eAbout\u003c/a\u003e\n        \u003c/li\u003e\n        \u003cli class=\"nav__link\"\u003e\n          \u003ca href=\"#\"\u003eContact\u003c/a\u003e\n        \u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/nav\u003e\n    \u003cheader\u003e\n      \u003ch1\u003eHello World\u003c/h1\u003e\n    \u003c/header\u003e\n    \u003cmain\u003e\n      \u003csection class=\"intro\"\u003e...\u003c/section\u003e\n      \u003csection class=\"about\"\u003e...\u003c/section\u003e\n      \u003csection class=\"outro\"\u003e...\u003c/section\u003e\n    \u003c/main\u003e\n    \u003cfooter\u003e\n      \u003cdiv class=\"col-md-3\"\u003e\u003c/div\u003e\n      \u003cdiv class=\"col-md-3\"\u003e\u003c/div\u003e\n      \u003cdiv class=\"col-md-3\"\u003e\u003c/div\u003e\n    \u003c/footer\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\n\u003ch2 align=\"center\"\u003eLICENSE\u003c/h2\u003e\n\n\u003e MIT License (MIT)\n\n\u003e Copyright (c) PostHTML Michael Ciniawsky \u003cmichael.ciniawsky@gmail.com\u003e\n\n\u003e Permission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\n\u003e The above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\n\u003e THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n\n[npm]: https://img.shields.io/npm/v/posthtml-import.svg\n[npm-url]: https://npmjs.com/package/posthtml-import\n\n[deps]: https://david-dm.org/posthtml/posthtml-import.svg\n[deps-url]: https://david-dm.org/posthtml/posthtml-import\n\n[style]: https://img.shields.io/badge/code%20style-standard-yellow.svg\n[style-url]: http://standardjs.com/\n\n[travis]: http://img.shields.io/travis/posthtml/posthtml-import.svg\n[travis-url]: https://travis-ci.org/posthtml/posthtml-import\n\n[cover]: https://coveralls.io/repos/github/posthtml/posthtml-import/badge.svg?branch=master\n[cover-url]: https://coveralls.io/github/posthtml/posthtml-import?branch=master\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-import","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fposthtml%2Fposthtml-import","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fposthtml%2Fposthtml-import/lists"}