Last active
September 30, 2018 21:17
-
-
Save AoiYamada/f7a22f637ce9be57efc30b1f7aead45c to your computer and use it in GitHub Desktop.
Remove html tag, css, js of html string to extract the contents
This file contains 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
/** | |
* Remove html tag, css, js of html string to extract the contents | |
* @param {String} html | |
* @return {String} contents of the html | |
*/ | |
function extractContents(html) { | |
return html | |
.replace(/(\n|\r|\t)/gm, '') // remove linebreaks | |
.replace(/<(style|script|link|noscript).*?>.*?<\/(style|script|link|noscript)>/g, '') // remove css, js blocks | |
.replace(/<!--.*?-->/g, '') // remove comments | |
.replace(/<.*?>/g, '') // remove tags | |
.replace(/[\s\!\@\#\$\%\^\&\*\(\)\_\+\-\=\{\}\[\]\:\"\;\'\<\>\?\,\.\/\|\\\`\~]+/g, ' ') // remove symbols | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment