html-to-formatted-text
Version:
Convert HTML to formatted text
77 lines (53 loc) • 2.26 kB
Markdown
# html-to-formatted-text
[](https://travis-ci.org/lukeaus/html-to-formatted-text)
[](https://codecov.io/gh/lukeaus/html-to-formatted-text)
[](https://github.com/lukeaus/html-to-formatted-text/blob/master/LICENSE)
[](http://npm.im/html-to-formatted-text)
[](http://npm-stat.com/charts.html?package=html-to-formatted-text&from=2018-07-24)
[](https://github.com/semantic-release/semantic-release)
## What
Converts HTML to formatted plain text.
From:
`"<p>Some text.</p><p>More text.</p><div>Even more text.</div>"`
To:
```
Some text.
More text.
Even more text.
```
## Usage
### Node
### Installation
```bash
npm install --save html-to-formatted-text
```
```javascript
const htmlToFormattedText = require("html-to-formatted-text");
htmlToFormattedText("<p>foo</p><p>bar</p>"); // Output: "foo\nbar"
```
### ES6
```javascript
// ES6
import htmlToFormattedText from "html-to-formatted-text";
htmlToFormattedText("<p>foo</p><p>bar</p>"); // Output: "foo\nbar"
```
### Vanilla JS / UMD
```html
<!-- latest version -->
<script src="https://unpkg.com/html-to-formatted-text/dist/index.umd.min.js"></script>
<!-- or for a specific version -->
<script src="https://unpkg.com/html-to-formatted-text@X.Y.Z/dist/index.umd.min.js"></script>
<script>
document.addEventListener("DOMContentLoaded", function () {
window.htmlToFormattedText('<p>foo</p><p>bar</p>') // Output: "foo\nbar"
});
</script>
```
## Why
You might have HTML that you want to display as text.
One use case might be that a user adds HTML via an online editor [TinyMCE](https://www.tiny.cloud/) and you want to display this as plain text somewhere else.
## Contributing
- Create an issue on Github
- Fork project
- Make changes then use `npm run commit` to make commits
- Create a pull request