@blac-sheep/html-to-text
v0.2.2
Published
A simple utility to convert HTML into text, keeping as much content as possible.
Downloads
24
Readme
HTML To Text
This library is based on: Luke Scott's html-to-formatted-text
A simple utility to convert HTML to nicely printed text, while trying to keep as much elements as possible.
- Links are kept in the form
Link Text (Url)
- Images are kept in the form
Image: Alt Text (Url)
- List items are kept in the form
* Item Text
- All HTML entities are correctly parsed to their respective character
Installation
This library is provided as an UMD module that can be installed by adding the files manually to your project or via a package manager.
Yarn
yarn add @blac-sheep/html-to-text
NPM
npm install @blac-sheep/html-to-text
Adding it manually
<script src="html-to-text.min.js"></script>
Usage
NodeJS
const htmlToText = require('@blac-sheep/html-to-text').default;
ES6
import htmlToText from '@blac-sheep/html-to-text';
Browser
const htmlToText = HTMLToText.default;
Examples
htmlToText('<a href="https://blac-sheep.com">Blac Sheep</a>'); // Blac Sheep (https://blac-sheep.com)
htmlToText('<ul><li>One</li><li>Two</li><li>Three</li></ul>'); // * One\n* Two\n* Three
htmlToText('<img src="https://example.com/someImage.png" alt="Image Alt Text">'); // Image: Image Alt Text (https://example.com/someImage.png)
htmlToText('<p>This is a paragraph</p><p>This is another paragraph</p>'); // This is a paragraph\nThis is another paragraph
License
This library is released under the MIT license.