
Product
Introducing Module Reachability: Focus on the Vulnerabilities That Matter
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
posthtml-include
Advanced tools
npm i -D posthtml-include
const { readFileSync } = require('fs')
const posthtml = require('posthtml')
const include = require('posthtml-include')
const html = readFileSync('index.html')
posthtml([ include({ encoding: 'utf8' }) ])
.process(html)
.then((result) => console.log(result.html))
root: Root directory for include. Default process.cwd()
cwd: Current working directory for include. Default process.cwd()
encoding: Default utf-8
posthtmlExpressionsOptions: Array to pass options posthtml-expression
locals: Object containing any local variables that you want to be accessible inside the include component
index.html
<html>
<head>
<title>index.html</title>
</head>
<body>
<include src="components/button.html" locals='{
"text": "Button"
}'></include>
</body>
</html>
components/button.html
<button class="button"><div class="button__text">{{ text }}</div></button>
const { readFileSync } = require('fs')
const posthtml = require('posthtml')
const include = require('posthtml-include')
const html = readFileSync('index.html')
posthtml([ include({ encoding: 'utf8' }) ])
.process(html)
.then((result) => console.log(result.html))
<html>
<head>
<title>index.html</title>
</head>
<body>
<button class="button">
<div class="button__text">Button</div>
</button>
</body>
</html>
You can also pass your locals directly on the <include> content, just drop a JSON there. When doing it, all the "\n" chars will be removed from your data. If you need "\n" chars on your data, you can still use the "locals" attribute.
<include src="components/button.html">
{
"text": "Button"
}
</include>
Note: Also supports multi nesting.
MIT License (MIT)
Copyright (c) PostHTML Ivan Voischev
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Include files in HTML
The npm package posthtml-include receives a total of 5,124 weekly downloads. As such, posthtml-include popularity was classified as popular.
We found that posthtml-include demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Module Reachability filters out unreachable CVEs so you can focus on vulnerabilities that actually matter to your application.
Product
Socket is introducing a new way to organize repositories and apply repository-specific security policies.
Research
Security News
Socket researchers uncovered malicious npm and PyPI packages that steal crypto wallet credentials using Google Analytics and Telegram for exfiltration.