Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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