2021-02-17 23:00:26 +00:00
|
|
|
module.exports = function htmlToPlaintext(html) {
|
2022-05-13 11:16:01 +01:00
|
|
|
const {convert} = require('html-to-text');
|
2021-10-21 10:27:56 +02:00
|
|
|
|
2022-05-13 11:16:01 +01:00
|
|
|
return convert(html, {
|
2022-05-13 08:56:13 +01:00
|
|
|
wordwrap: false,
|
2021-02-17 23:00:26 +00:00
|
|
|
preserveNewlines: true,
|
2022-05-13 11:16:01 +01:00
|
|
|
|
|
|
|
// equiv returnDomByDefault: true,
|
|
|
|
baseElements: {returnDomByDefault: true},
|
|
|
|
selectors: [
|
|
|
|
// Ignore images, equiv ignoreImage: true
|
|
|
|
{selector: 'img', format: 'skip'} ,
|
|
|
|
// disable uppercase headings, equiv uppercaseHeadings: false
|
|
|
|
{selector: 'h1', options: {uppercase: false}},
|
|
|
|
{selector: 'h2', options: {uppercase: false}},
|
|
|
|
{selector: 'h3', options: {uppercase: false}},
|
|
|
|
{selector: 'h4', options: {uppercase: false}},
|
|
|
|
{selector: 'h5', options: {uppercase: false}},
|
|
|
|
{selector: 'h6', options: {uppercase: false}},
|
|
|
|
{selector: 'table', options: {uppercaseHeaderCells: false}},
|
|
|
|
// equiv hideLinkHrefIfSameAsText: true
|
|
|
|
{selector: 'a', options: {hideLinkHrefIfSameAsText: true}},
|
|
|
|
|
|
|
|
// Backwards compatibility with html-to-text 5.1.1
|
|
|
|
{selector: 'div', format: 'inline'}
|
|
|
|
]
|
2021-02-17 23:00:26 +00:00
|
|
|
});
|
|
|
|
};
|