
Product
Reachability for Ruby Now in Beta
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.
posthtml-insert-at
Advanced tools
posthtml-insert-at is a PostHTML plugin to append or prepend HTML to a selector.
Before:
<html>
<body>
<main></main>
</body>
</html>
After:
<html>
<body>
<header></header>
<main></main>
<footer></footer>
</body>
</html>
yarn add -D posthtml-insert-at
# OR
npm i posthtml-insert-at
const fs = require('fs');
const posthtml = require('posthtml');
const { insertAt } = require('posthtml-insert-at');
const html = fs.readFileSync('./index.html');
posthtml()
.use(
insertAt({
/**
* Specify the selector to append/prepend content to.
* Selectors include tag name (e.g. `main`), class (e.g. `.main`) or id (e.g. `#main`).
*/
selector: 'main',
/**
* Prepend HTML markup at the selector.
*/
prepend: `
<header>
<a href="/">Home</a>
</header>
`,
/**
* Append HTML markup at the selector.
*/
append: `
<footer>
© ${new Date().getFullYear()}
</footer>
`,
/**
* Specify whether to append/prepend content inside or outside (i.e. adjacent to) of the selector.
*
* The default behavior is `inside`.
*/
behavior: 'outside'
})
)
.process(html)
.then(result => fs.writeFileSync('./after.html', result.html));
| Name | Kind | Description |
|---|---|---|
selector | required string | Selector to insert markup at (e.g. .classname, #id or tag) |
prepend | optional string | Markup to prepend to the selector |
append | optional string | Markup to append to the selector |
behavior | optional ("inside" or "outside") - default is "inside" | Whether to append/prepend content inside or outside of the selector |
The plugin accepts an object or an an array of objects.
const option = {
selector: 'body',
prepend: '<header></header>',
append: '<footer></footer>',
behavior: 'inside'
};
insertAt(option);
// OR
insertAt([option /*, ...more options */]);
Currently, this plugin does not supported nested selectors.
See the PostHTML Guidelines.
0.2.7 - 2020-06-30
FAQs
PostHTML plugin to append or prepend HTML to a selector
The npm package posthtml-insert-at receives a total of 1,668 weekly downloads. As such, posthtml-insert-at popularity was classified as popular.
We found that posthtml-insert-at demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Reachability analysis for Ruby is now in beta, helping teams identify which vulnerabilities are truly exploitable in their applications.

Research
/Security News
Malicious npm packages use Adspect cloaking and fake CAPTCHAs to fingerprint visitors and redirect victims to crypto-themed scam sites.

Security News
Recent coverage mislabels the latest TEA protocol spam as a worm. Here’s what’s actually happening.