append-snippet
v1.0.0
Published
Synchronously append a snippet of markup to an HTML document.
Downloads
3
Readme
append-snippet
A function that synchronously injects a snippet of markup into an HTML document, immediately before the closing </body>
tag.
var appendSnippet = require('append-snippet');
var html = '<body>\n<h1>hello!</h1>\ndemo\n</body>';
var result = appendSnippet('<script>alert("cods")</script>', html);
// <body>\n<h1>hello!</h1>\ndemo\n<script>alert("cods")</script></body>
If there's no closing body tag, it goes just before the </html>
, or failing that, the end of the string.