Skip to content

Commit

Permalink
Replace he with entities (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
sibiraj-s authored Dec 4, 2021
1 parent 7a9fc1c commit 7cd2145
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 38 deletions.
53 changes: 39 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@
"camel-case": "^4.1.2",
"clean-css": "^5.2.2",
"commander": "^8.3.0",
"he": "^1.2.0",
"entities": "^3.0.1",
"param-case": "^3.0.4",
"relateurl": "^0.2.7",
"terser": "^5.10.0"
},
"devDependencies": {
"@jest/globals": "^27.3.1",
"@rollup/plugin-commonjs": "^21.0.1",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^13.0.6",
"alpinejs": "^3.5.2",
"eslint": "^7.32.0",
Expand Down
34 changes: 14 additions & 20 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@ import { defineConfig } from 'rollup';
import commonjs from '@rollup/plugin-commonjs';
import nodeResolve from '@rollup/plugin-node-resolve';
import nodePolyfills from 'rollup-plugin-polyfill-node';
import json from '@rollup/plugin-json';
import { terser } from 'rollup-plugin-terser';

const bunldePlugins = [
commonjs(),
nodePolyfills(),
nodeResolve({
preferBuiltins: false
}),
json()
];

const config = defineConfig([
{
input: 'src/htmlminifier.js',
Expand All @@ -13,13 +23,7 @@ const config = defineConfig([
exports: 'named',
name: 'HTMLMinifier'
}],
plugins: [
commonjs(),
nodePolyfills(),
nodeResolve({
preferBuiltins: false
})
]
plugins: bunldePlugins
},
{
input: 'src/htmlminifier.js',
Expand All @@ -30,11 +34,7 @@ const config = defineConfig([
name: 'HTMLMinifier'
}],
plugins: [
commonjs(),
nodePolyfills(),
nodeResolve({
preferBuiltins: false
}),
...bunldePlugins,
terser()
]
},
Expand All @@ -44,13 +44,7 @@ const config = defineConfig([
file: 'dist/htmlminifier.esm.bundle.js',
format: 'es'
},
plugins: [
commonjs(),
nodePolyfills(),
nodeResolve({
preferBuiltins: false
})
]
plugins: bunldePlugins
},
{
input: 'src/htmlminifier.js',
Expand All @@ -61,7 +55,7 @@ const config = defineConfig([
plugins: [
commonjs()
],
external: ['clean-css', 'terser', 'he', 'relateurl']
external: ['clean-css', 'terser', 'entities', 'relateurl']
}
]);

Expand Down
6 changes: 3 additions & 3 deletions src/htmlminifier.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const CleanCSS = require('clean-css');
const { decode } = require('he');
const { decodeHTMLStrict, decodeHTML } = require('entities');
const RelateUrl = require('relateurl');
const Terser = require('terser');

Expand Down Expand Up @@ -549,7 +549,7 @@ async function normalizeAttr(attr, attrs, tag, options) {
let attrValue = attr.value;

if (options.decodeEntities && attrValue) {
attrValue = decode(attrValue, { isAttributeValue: true });
attrValue = decodeHTMLStrict(attrValue);
}

if ((options.removeRedundantAttributes &&
Expand Down Expand Up @@ -1128,7 +1128,7 @@ async function minify(value, options, partialMarkup) {
prevTag = prevTag === '' ? 'comment' : prevTag;
nextTag = nextTag === '' ? 'comment' : nextTag;
if (options.decodeEntities && text && !specialContentTags(currentTag)) {
text = decode(text);
text = decodeHTML(text);
}
if (options.collapseWhitespace) {
if (!stackNoTrimWhitespace.length) {
Expand Down

0 comments on commit 7cd2145

Please sign in to comment.