jsx-html-converter
v2.0.3
Published
converts html to valid jsx
Downloads
19
Readme
jsx-html-converter
This npm package provides a function that can be used to convert an HTML string to valid JSX by closing any optional tags that are valid in HTML. This can be useful when working with HTML content in a React application.
Installation
You can install this package using npm:
npm i jsx-html-converter
Usage
To use the closeOptionalTags function, import it into your JavaScript file:
const closeOptionalTags = require("jsx-html-converter"); You can then call the function with an HTML string as the argument:
const html = <p>Hello, world!</p>
const jsx = closeOptionalTags(html);
console.log(jsx);
// Output:
<p>Hello, world!</p>
The function will return the HTML string converted to valid JSX, with any optional tags closed:
const html = <img src='example.jpg'>
;
const jsx = closeOptionalTags(html);
console.log(jsx);
// Output:
<img src='example.jpg'/>
License
This package is licensed under the MIT license.
Repo
https://github.com/tungolra/html-jsx-converter