tagged-hypertext
v1.0.1
Published
A template tag to safely generate HTML code with 100% code coverage.
Downloads
11
Readme
tagged-hypertext
The tagged-hypertext
package provides the html
function that can be used as a template tag to safely generate HTML code.
Example
import { html, renderHtml } from 'tagged-hypertext'
const div = html`
<div class="container">
<h1>Hello, world!</h1>
<p>Here is a list of items:</p>
<ul>
${['<foo>', 'bar&', '"baz"', html`<b>whee</b>`].map(
(item) => html`<li>${item}</li>`,
)}
</ul>
</div>
`
console.log(renderHtml(div))
/*
<div class="container">
<h1>Hello, world!</h1>
<p>Here is a list of items:</p>
<ul>
<li><foo></li><li>bar&</li><li>"baz"</li><li><b>whee</b></li>
</ul>
</div>
*/
See the tests for more examples.