posthtml-fragment

HTML fragments

Usage no npm install needed!

<script type="module">
  import posthtmlFragment from 'https://cdn.skypack.dev/posthtml-fragment';
</script>

README

NPM Deps Tests Coverage

HTML fragments

Install

npm i -D posthtml-fragment

Usage

const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const fragment = require('posthtml-fragment')

const html = readFileSync('index.html')

posthtml([ fragment() ])
    .process(html)
    .then((result) => console.log(result.html))

Options

No options.

Component options

No options.

Usage

index.html

<html>
<head>
    <title>index.html</title>
</head>
<body>
    <fragment src="components/button.html"></fragment>
</body>
</html>

components/button.html

<button class="button"><div class="button__text">text</div></button>
const { readFileSync } = require('fs')

const posthtml = require('posthtml')
const fragment = require('posthtml-fragment')

const html = readFileSync('index.html')

posthtml([ fragment() ])
    .process(html)
    .then((result) => console.log(result.html))
<html>
<head>
  <title>index.html</title>
</head>
<body>
  <button class="button">
    <div class="button__text">text</div>
  </button>
</body>
</html>

Note: Also supports multi nesting.

LICENSE

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 fragmentd 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.