Created
November 9, 2016 19:38
-
-
Save tonysherbondy/d05a0794dc4398e8ae6285dbd9f011d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const convertHtmlToPlainText = html => { | |
const dict = { | |
gt: '>', | |
hellip: '...', | |
ldquo: '"', | |
rdquo: '"', | |
lsquo: "'", | |
rsquo: "'", | |
ndash: '-', | |
} | |
const text = html | |
.replace(/<[^>]*>/g, '') | |
.replace(/½/g, '1/2') | |
.replace(/¼/g, '1/4') | |
.replace(/¾/g, '3/4') | |
.replace(/&(#(?:x[0-9a-f]+|\d+)|[a-z]+);?/gi, (first, sec) => { | |
return dict.hasOwnProperty(sec) ? dict[sec] : first | |
}) | |
.trim() | |
return text | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment