diff --git a/src/entify.js b/src/entify.js index fa5b6da..ab9fdfe 100644 --- a/src/entify.js +++ b/src/entify.js @@ -1,7 +1,6 @@ /** * Enforce entity characters for textarea content. - * By default, this also does basic minification before setting entities. - * For full minification, pass `minify_content` as `true`. + * To also minifiy, pass `minify` as `true`. * * @param {string} html The HTML string to evaluate. * @param {boolean} [minify] Fully minifies the content of textarea elements. @@ -11,31 +10,20 @@ * @example => */ export const entify = (html, minify = false) => { - /* Trim any combination of leading line returns and/or spaces. */ - html = html - .replace(/(]*>)\n+/g, '$1') - .replace(/(]*>)\n\s+/g, '$1') - .replace(/(]*>)\s+\n/g, '$1') - - /* Trim trailing spaces */ - html = html.replace(/\s+<\/textarea>/g, '') - /** - * Protect entities, inside the textarea content, - * from general minification. + * Use entities inside textarea content. */ html = html.replace(/]*>((.|\n)*?)<\/textarea>/g, (match, capture) => { return match.replace(capture, (match) => { return match + .replace(/&/g, '&') .replace(//g, '>') - .replace(/\//g, '/') - .replace(/"/g, '"') - .replace(/'/g, ''') - .replace(/\n/g, ' ') - .replace(/%/g, '%') - .replace(/\{/g, '{') - .replace(/\}/g, '}') + .replace(/"/g, '"') + .replace(/'/g, ''') + .replace(/\n/g, ' ') + .replace(/\r/g, ' ') + .replace(/\s/g, ' ') }) })