@elchika-inc/html-to-text
v0.1.0
Published
Convert HTML content to plain text format
Maintainers
Readme
@elchika-inc/html-to-text
Convert HTML content to plain text format using Cheerio.
Installation
npm install @elchika-inc/html-to-textUsage
import { HtmlToTextConverter } from '@elchika-inc/html-to-text';
const html = '<h1>Hello World</h1><p>This is a paragraph.</p>';
// Basic conversion
const text = HtmlToTextConverter.convert(html);
console.log(text); // "Hello World This is a paragraph."
// With options
const textWithTitle = HtmlToTextConverter.convert(html, {
includeTitle: true,
title: 'My Document',
normalizeWhitespace: true
});
// With formatting preserved
const formattedText = HtmlToTextConverter.convertWithFormatting(html, {
includeTitle: true,
title: 'My Document'
});API
HtmlToTextConverter.convert(html, options?)
Convert HTML to plain text.
Options:
normalizeWhitespace(boolean, default: true) - Normalize whitespaceincludeTitle(boolean, default: false) - Include title at the beginningtitle(string) - Title to include ifincludeTitleis true
HtmlToTextConverter.convertWithFormatting(html, options?)
Convert HTML to text with better formatting preservation.
License
MIT
