| 41 | * @param {str} string |
| 42 | */ |
| 43 | export const stripHtml = (string) => { |
| 44 | let returnString = string; |
| 45 | |
| 46 | // Remove DOM tags |
| 47 | returnString = returnString.replace(/<[^>]*>?/gm, ''); |
| 48 | |
| 49 | // Remove entities |
| 50 | const entities = [ |
| 51 | ['amp', '&'], |
| 52 | ['apos', "'"], |
| 53 | ['#x27', "'"], |
| 54 | ['#x2F', '/'], |
| 55 | ['#39', "'"], |
| 56 | ['#47', '/'], |
| 57 | ['lt', '<'], |
| 58 | ['gt', '>'], |
| 59 | ['nbsp', ' '], |
| 60 | ['quot', '"'], |
| 61 | ['hellip', '...'], |
| 62 | ['#8217', "'"], |
| 63 | ['#8230', '...'], |
| 64 | ['#8211', '-'], |
| 65 | ]; |
| 66 | |
| 67 | entities.map((item) => { // eslint-disable-line |
| 68 | returnString = returnString.replace(new RegExp(`&${item[0]};`, 'g'), item[1]); |
| 69 | }); |
| 70 | |
| 71 | return returnString; |
| 72 | }; |