How to use the html-to-text/lib/formatter.js.text function in html-to-text

To help you get started, we’ve selected a few html-to-text examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github synzen / Discord.RSS / src / structs / Article.js View on Github external
function cleanup (source, text, imgSrcs, anchorLinks, encoding) {
  if (!text) return ''

  text = htmlDecoder({ data: text }, {}).replace(/\*/gi, '')
    .replace(/<(strong|b)>(.*?)<\/(strong|b)>/gi, '**$2**') // Bolded markdown
    .replace(/<(em|i)>(.*?)<(\/(em|i))>/gi, '*$2*') // Italicized markdown
    .replace(/<(u)>(.*?)<(\/(u))>/gi, '__$2__') // Underlined markdown

  text = htmlConvert.fromString(text, {
    tables: (source.formatTables !== undefined && typeof source.formatTables === 'boolean' ? source.formatTables : config.feeds.formatTables) === true ? true : [],
    wordwrap: null,
    ignoreHref: true,
    noLinkBrackets: true,
    format: {
      image: node => {
        const isStr = typeof node.attribs.src === 'string'
        let link = isStr ? node.attribs.src.trim().replace(/\s/g, '%20') : node.attribs.src
        if (isStr && link.startsWith('//')) link = 'http:' + link
        else if (isStr && !link.startsWith('http://') && !link.startsWith('https://')) link = 'http://' + link

html-to-text

Advanced html to plain text converter

MIT
Latest version published 2 years ago

Package Health Score

74 / 100
Full package analysis