UNPKG

magister.js

Version:

A JavaScript implementation of the Magister 6 API

23 lines (20 loc) 472 B
import _ from 'lodash' /** * Strips HTML tags and entities from the given `str` * If `str` is `undefined` or `null` an empty string will be returned. * * @param {string} [str] * @returns {string} */ export function cleanHtmlContent (str) { if (str == null) { return '' } return _.unescape(str) .replace(/<br\s*\/?>/g, '\n') .replace(/<\/\s*p\s*>/g, '\n') .replace(/&nbsp;/g, ' ') .replace(/(<[^>]*>)|(&#x200b;)/g, '') .replace(/\r?\n/g, '\n') .trim() }