htmlnano 2.1.1 → 2.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/README.md +53 -12
  2. package/dist/_modules/collapseAttributeWhitespace.d.mts +57 -0
  3. package/dist/_modules/collapseAttributeWhitespace.d.ts +57 -0
  4. package/dist/_modules/collapseAttributeWhitespace.js +296 -0
  5. package/dist/_modules/collapseAttributeWhitespace.mjs +293 -0
  6. package/dist/_modules/collapseBooleanAttributes.d.mts +60 -0
  7. package/dist/_modules/collapseBooleanAttributes.d.ts +60 -0
  8. package/dist/_modules/collapseBooleanAttributes.js +159 -0
  9. package/{lib/modules → dist/_modules}/collapseBooleanAttributes.mjs +39 -57
  10. package/dist/_modules/collapseWhitespace.d.mts +57 -0
  11. package/dist/_modules/collapseWhitespace.d.ts +57 -0
  12. package/dist/_modules/collapseWhitespace.js +172 -0
  13. package/dist/_modules/collapseWhitespace.mjs +170 -0
  14. package/dist/_modules/custom.d.mts +57 -0
  15. package/dist/_modules/custom.d.ts +57 -0
  16. package/dist/_modules/custom.js +22 -0
  17. package/dist/_modules/custom.mjs +20 -0
  18. package/dist/_modules/deduplicateAttributeValues.d.mts +56 -0
  19. package/dist/_modules/deduplicateAttributeValues.d.ts +56 -0
  20. package/dist/_modules/deduplicateAttributeValues.js +38 -0
  21. package/dist/_modules/deduplicateAttributeValues.mjs +36 -0
  22. package/dist/_modules/example.d.mts +59 -0
  23. package/dist/_modules/example.d.ts +59 -0
  24. package/dist/_modules/example.js +67 -0
  25. package/dist/_modules/example.mjs +65 -0
  26. package/dist/_modules/mergeScripts.d.mts +56 -0
  27. package/dist/_modules/mergeScripts.d.ts +56 -0
  28. package/dist/_modules/mergeScripts.js +53 -0
  29. package/dist/_modules/mergeScripts.mjs +51 -0
  30. package/dist/_modules/mergeStyles.d.mts +56 -0
  31. package/dist/_modules/mergeStyles.d.ts +56 -0
  32. package/dist/_modules/mergeStyles.js +42 -0
  33. package/dist/_modules/mergeStyles.mjs +40 -0
  34. package/dist/_modules/minifyConditionalComments.d.mts +56 -0
  35. package/dist/_modules/minifyConditionalComments.d.ts +56 -0
  36. package/dist/_modules/minifyConditionalComments.js +54 -0
  37. package/{lib/modules → dist/_modules}/minifyConditionalComments.mjs +21 -22
  38. package/dist/_modules/minifyCss.d.mts +56 -0
  39. package/dist/_modules/minifyCss.d.ts +56 -0
  40. package/dist/_modules/minifyCss.js +84 -0
  41. package/dist/_modules/minifyCss.mjs +82 -0
  42. package/dist/_modules/minifyJs.d.mts +56 -0
  43. package/dist/_modules/minifyJs.d.ts +56 -0
  44. package/dist/_modules/minifyJs.js +108 -0
  45. package/dist/_modules/minifyJs.mjs +106 -0
  46. package/dist/_modules/minifyJson.d.mts +56 -0
  47. package/dist/_modules/minifyJson.d.ts +56 -0
  48. package/dist/_modules/minifyJson.js +35 -0
  49. package/dist/_modules/minifyJson.mjs +33 -0
  50. package/dist/_modules/minifySvg.d.mts +56 -0
  51. package/dist/_modules/minifySvg.d.ts +56 -0
  52. package/dist/_modules/minifySvg.js +40 -0
  53. package/dist/_modules/minifySvg.mjs +38 -0
  54. package/dist/_modules/minifyUrls.d.mts +56 -0
  55. package/dist/_modules/minifyUrls.d.ts +56 -0
  56. package/dist/_modules/minifyUrls.js +180 -0
  57. package/dist/_modules/minifyUrls.mjs +178 -0
  58. package/dist/_modules/normalizeAttributeValues.d.mts +56 -0
  59. package/dist/_modules/normalizeAttributeValues.d.ts +56 -0
  60. package/dist/_modules/normalizeAttributeValues.js +234 -0
  61. package/dist/_modules/normalizeAttributeValues.mjs +232 -0
  62. package/dist/_modules/removeAttributeQuotes.d.mts +56 -0
  63. package/dist/_modules/removeAttributeQuotes.d.ts +56 -0
  64. package/dist/_modules/removeAttributeQuotes.js +15 -0
  65. package/dist/_modules/removeAttributeQuotes.mjs +13 -0
  66. package/dist/_modules/removeComments.d.mts +58 -0
  67. package/dist/_modules/removeComments.d.ts +58 -0
  68. package/dist/_modules/removeComments.js +83 -0
  69. package/{lib/modules → dist/_modules}/removeComments.mjs +24 -35
  70. package/dist/_modules/removeEmptyAttributes.d.mts +56 -0
  71. package/dist/_modules/removeEmptyAttributes.d.ts +56 -0
  72. package/dist/_modules/removeEmptyAttributes.js +197 -0
  73. package/dist/_modules/removeEmptyAttributes.mjs +195 -0
  74. package/dist/_modules/removeOptionalTags.d.mts +56 -0
  75. package/dist/_modules/removeOptionalTags.d.ts +56 -0
  76. package/dist/_modules/removeOptionalTags.js +190 -0
  77. package/{lib/modules → dist/_modules}/removeOptionalTags.mjs +54 -91
  78. package/dist/_modules/removeRedundantAttributes.d.mts +57 -0
  79. package/dist/_modules/removeRedundantAttributes.d.ts +57 -0
  80. package/dist/_modules/removeRedundantAttributes.js +128 -0
  81. package/{lib/modules → dist/_modules}/removeRedundantAttributes.mjs +43 -59
  82. package/dist/_modules/removeUnusedCss.d.mts +60 -0
  83. package/dist/_modules/removeUnusedCss.d.ts +60 -0
  84. package/dist/_modules/removeUnusedCss.js +134 -0
  85. package/dist/_modules/removeUnusedCss.mjs +132 -0
  86. package/dist/_modules/sortAttributes.d.mts +57 -0
  87. package/dist/_modules/sortAttributes.d.ts +57 -0
  88. package/dist/_modules/sortAttributes.js +102 -0
  89. package/{lib/modules → dist/_modules}/sortAttributes.mjs +39 -60
  90. package/dist/_modules/sortAttributesWithLists.d.mts +56 -0
  91. package/dist/_modules/sortAttributesWithLists.d.ts +56 -0
  92. package/dist/_modules/sortAttributesWithLists.js +118 -0
  93. package/{lib/modules → dist/_modules}/sortAttributesWithLists.mjs +41 -60
  94. package/dist/helpers.js +72 -0
  95. package/dist/helpers.mjs +63 -0
  96. package/dist/index.js +223 -0
  97. package/dist/index.mjs +209 -0
  98. package/dist/presets/ampSafe.js +19 -0
  99. package/{lib → dist}/presets/ampSafe.mjs +6 -4
  100. package/dist/presets/max.js +28 -0
  101. package/{lib → dist}/presets/max.mjs +6 -4
  102. package/dist/presets/safe.js +60 -0
  103. package/{lib → dist}/presets/safe.mjs +13 -20
  104. package/package.json +53 -59
  105. package/.eslintignore +0 -3
  106. package/CHANGELOG.md +0 -398
  107. package/docs/README.md +0 -33
  108. package/docs/babel.config.js +0 -3
  109. package/docs/docs/010-introduction.md +0 -22
  110. package/docs/docs/020-usage.md +0 -117
  111. package/docs/docs/030-config.md +0 -21
  112. package/docs/docs/040-presets.md +0 -75
  113. package/docs/docs/050-modules.md +0 -855
  114. package/docs/docs/060-contribute.md +0 -16
  115. package/docs/docusaurus.config.js +0 -65
  116. package/docs/netlify.toml +0 -4
  117. package/docs/package-lock.json +0 -21796
  118. package/docs/package.json +0 -40
  119. package/docs/sidebars.js +0 -26
  120. package/docs/versioned_docs/version-1.1.1/010-introduction.md +0 -22
  121. package/docs/versioned_docs/version-1.1.1/020-usage.md +0 -77
  122. package/docs/versioned_docs/version-1.1.1/030-config.md +0 -21
  123. package/docs/versioned_docs/version-1.1.1/040-presets.md +0 -75
  124. package/docs/versioned_docs/version-1.1.1/050-modules.md +0 -785
  125. package/docs/versioned_docs/version-1.1.1/060-contribute.md +0 -16
  126. package/docs/versioned_docs/version-2.0.0/010-introduction.md +0 -22
  127. package/docs/versioned_docs/version-2.0.0/020-usage.md +0 -77
  128. package/docs/versioned_docs/version-2.0.0/030-config.md +0 -21
  129. package/docs/versioned_docs/version-2.0.0/040-presets.md +0 -75
  130. package/docs/versioned_docs/version-2.0.0/050-modules.md +0 -838
  131. package/docs/versioned_docs/version-2.0.0/060-contribute.md +0 -16
  132. package/docs/versioned_sidebars/version-1.1.1-sidebars.json +0 -8
  133. package/docs/versioned_sidebars/version-2.0.0-sidebars.json +0 -8
  134. package/docs/versions.json +0 -4
  135. package/index.cjs +0 -11
  136. package/index.d.cts +0 -3
  137. package/index.d.mts +0 -3
  138. package/index.d.ts +0 -93
  139. package/index.mjs +0 -2
  140. package/lib/helpers.cjs +0 -79
  141. package/lib/helpers.mjs +0 -53
  142. package/lib/htmlnano.cjs +0 -200
  143. package/lib/htmlnano.mjs +0 -196
  144. package/lib/modules/collapseAttributeWhitespace.cjs +0 -86
  145. package/lib/modules/collapseAttributeWhitespace.mjs +0 -104
  146. package/lib/modules/collapseBooleanAttributes.cjs +0 -62
  147. package/lib/modules/collapseWhitespace.cjs +0 -100
  148. package/lib/modules/collapseWhitespace.mjs +0 -132
  149. package/lib/modules/custom.cjs +0 -19
  150. package/lib/modules/custom.mjs +0 -16
  151. package/lib/modules/deduplicateAttributeValues.cjs +0 -38
  152. package/lib/modules/deduplicateAttributeValues.mjs +0 -40
  153. package/lib/modules/example.cjs +0 -85
  154. package/lib/modules/example.mjs +0 -75
  155. package/lib/modules/mergeScripts.cjs +0 -54
  156. package/lib/modules/mergeScripts.mjs +0 -56
  157. package/lib/modules/mergeStyles.cjs +0 -38
  158. package/lib/modules/mergeStyles.mjs +0 -36
  159. package/lib/modules/minifyConditionalComments.cjs +0 -47
  160. package/lib/modules/minifyCss.cjs +0 -73
  161. package/lib/modules/minifyCss.mjs +0 -88
  162. package/lib/modules/minifyJs.cjs +0 -103
  163. package/lib/modules/minifyJs.mjs +0 -121
  164. package/lib/modules/minifyJson.cjs +0 -24
  165. package/lib/modules/minifyJson.mjs +0 -21
  166. package/lib/modules/minifySvg.cjs +0 -37
  167. package/lib/modules/minifySvg.mjs +0 -30
  168. package/lib/modules/minifyUrls.cjs +0 -141
  169. package/lib/modules/minifyUrls.mjs +0 -229
  170. package/lib/modules/normalizeAttributeValues.cjs +0 -120
  171. package/lib/modules/normalizeAttributeValues.mjs +0 -140
  172. package/lib/modules/removeAttributeQuotes.cjs +0 -17
  173. package/lib/modules/removeAttributeQuotes.mjs +0 -12
  174. package/lib/modules/removeComments.cjs +0 -86
  175. package/lib/modules/removeEmptyAttributes.cjs +0 -72
  176. package/lib/modules/removeEmptyAttributes.mjs +0 -121
  177. package/lib/modules/removeOptionalTags.cjs +0 -183
  178. package/lib/modules/removeRedundantAttributes.cjs +0 -112
  179. package/lib/modules/removeUnusedCss.cjs +0 -113
  180. package/lib/modules/removeUnusedCss.mjs +0 -122
  181. package/lib/modules/sortAttributes.cjs +0 -99
  182. package/lib/modules/sortAttributesWithLists.cjs +0 -115
  183. package/lib/presets/ampSafe.cjs +0 -18
  184. package/lib/presets/max.cjs +0 -27
  185. package/lib/presets/safe.cjs +0 -65
  186. package/test.js +0 -48
@@ -1,99 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = sortAttributes;
7
- var _timsort = require("timsort");
8
- const validOptions = new Set(['frequency', 'alphabetical']);
9
- const processModuleOptions = options => {
10
- if (options === true) return 'alphabetical';
11
- return validOptions.has(options) ? options : false;
12
- };
13
- class AttributeTokenChain {
14
- constructor() {
15
- this.freqData = new Map(); // <attr, frequency>[]
16
- }
17
- addFromNodeAttrs(nodeAttrs) {
18
- Object.keys(nodeAttrs).forEach(attrName => {
19
- const attrNameLower = attrName.toLowerCase();
20
- if (this.freqData.has(attrNameLower)) {
21
- this.freqData.set(attrNameLower, this.freqData.get(attrNameLower) + 1);
22
- } else {
23
- this.freqData.set(attrNameLower, 1);
24
- }
25
- });
26
- }
27
- createSortOrder() {
28
- let _sortOrder = [...this.freqData.entries()];
29
- (0, _timsort.sort)(_sortOrder, (a, b) => b[1] - a[1]);
30
- this.sortOrder = _sortOrder.map(i => i[0]);
31
- }
32
- sortFromNodeAttrs(nodeAttrs) {
33
- const newAttrs = {};
34
-
35
- // Convert node.attrs attrName into lower case.
36
- const loweredNodeAttrs = {};
37
- Object.entries(nodeAttrs).forEach(([attrName, attrValue]) => {
38
- loweredNodeAttrs[attrName.toLowerCase()] = attrValue;
39
- });
40
- if (!this.sortOrder) {
41
- this.createSortOrder();
42
- }
43
- this.sortOrder.forEach(attrNameLower => {
44
- // The attrName inside "sortOrder" has been lowered
45
- if (loweredNodeAttrs[attrNameLower] != null) {
46
- newAttrs[attrNameLower] = loweredNodeAttrs[attrNameLower];
47
- }
48
- });
49
- return newAttrs;
50
- }
51
- }
52
-
53
- /** Sort attibutes */
54
- function sortAttributes(tree, options, moduleOptions) {
55
- const sortType = processModuleOptions(moduleOptions);
56
- if (sortType === 'alphabetical') {
57
- return sortAttributesInAlphabeticalOrder(tree);
58
- }
59
- if (sortType === 'frequency') {
60
- return sortAttributesByFrequency(tree);
61
- }
62
-
63
- // Invalid configuration
64
- return tree;
65
- }
66
- function sortAttributesInAlphabeticalOrder(tree) {
67
- tree.walk(node => {
68
- if (!node.attrs) {
69
- return node;
70
- }
71
- const newAttrs = {};
72
- Object.keys(node.attrs).sort((a, b) => typeof a.localeCompare === 'function' ? a.localeCompare(b) : a - b).forEach(attr => newAttrs[attr] = node.attrs[attr]);
73
- node.attrs = newAttrs;
74
- return node;
75
- });
76
- return tree;
77
- }
78
- function sortAttributesByFrequency(tree) {
79
- const tokenchain = new AttributeTokenChain();
80
-
81
- // Traverse through tree to get frequency
82
- tree.walk(node => {
83
- if (!node.attrs) {
84
- return node;
85
- }
86
- tokenchain.addFromNodeAttrs(node.attrs);
87
- return node;
88
- });
89
-
90
- // Traverse through tree again, this time sort the attributes
91
- tree.walk(node => {
92
- if (!node.attrs) {
93
- return node;
94
- }
95
- node.attrs = tokenchain.sortFromNodeAttrs(node.attrs);
96
- return node;
97
- });
98
- return tree;
99
- }
@@ -1,115 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = collapseAttributeWhitespace;
7
- var _timsort = require("timsort");
8
- var _collapseAttributeWhitespace = require("./collapseAttributeWhitespace.cjs");
9
- // class, rel, ping
10
-
11
- const validOptions = new Set(['frequency', 'alphabetical']);
12
- const processModuleOptions = options => {
13
- if (options === true) return 'alphabetical';
14
- return validOptions.has(options) ? options : false;
15
- };
16
- class AttributeTokenChain {
17
- constructor() {
18
- this.freqData = new Map(); // <attrValue, frequency>[]
19
- }
20
- addFromNodeAttrsArray(attrValuesArray) {
21
- attrValuesArray.forEach(attrValue => {
22
- if (this.freqData.has(attrValue)) {
23
- this.freqData.set(attrValue, this.freqData.get(attrValue) + 1);
24
- } else {
25
- this.freqData.set(attrValue, 1);
26
- }
27
- });
28
- }
29
- createSortOrder() {
30
- let _sortOrder = [...this.freqData.entries()];
31
- (0, _timsort.sort)(_sortOrder, (a, b) => b[1] - a[1]);
32
- this.sortOrder = _sortOrder.map(i => i[0]);
33
- }
34
- sortFromNodeAttrsArray(attrValuesArray) {
35
- const resultArray = [];
36
- if (!this.sortOrder) {
37
- this.createSortOrder();
38
- }
39
- this.sortOrder.forEach(k => {
40
- if (attrValuesArray.includes(k)) {
41
- resultArray.push(k);
42
- }
43
- });
44
- return resultArray;
45
- }
46
- }
47
-
48
- /** Sort values inside list-like attributes (e.g. class, rel) */
49
- function collapseAttributeWhitespace(tree, options, moduleOptions) {
50
- const sortType = processModuleOptions(moduleOptions);
51
- if (sortType === 'alphabetical') {
52
- return sortAttributesWithListsInAlphabeticalOrder(tree);
53
- }
54
- if (sortType === 'frequency') {
55
- return sortAttributesWithListsByFrequency(tree);
56
- }
57
-
58
- // Invalid configuration
59
- return tree;
60
- }
61
- function sortAttributesWithListsInAlphabeticalOrder(tree) {
62
- tree.walk(node => {
63
- if (!node.attrs) {
64
- return node;
65
- }
66
- Object.keys(node.attrs).forEach(attrName => {
67
- const attrNameLower = attrName.toLowerCase();
68
- if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
69
- return;
70
- }
71
- const attrValues = node.attrs[attrName].split(/\s/);
72
- node.attrs[attrName] = attrValues.sort((a, b) => {
73
- return typeof a.localeCompare === 'function' ? a.localeCompare(b) : a - b;
74
- }).join(' ');
75
- });
76
- return node;
77
- });
78
- return tree;
79
- }
80
- function sortAttributesWithListsByFrequency(tree) {
81
- const tokenChainObj = {}; // <attrNameLower: AttributeTokenChain>[]
82
-
83
- // Traverse through tree to get frequency
84
- tree.walk(node => {
85
- if (!node.attrs) {
86
- return node;
87
- }
88
- Object.entries(node.attrs).forEach(([attrName, attrValues]) => {
89
- const attrNameLower = attrName.toLowerCase();
90
- if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
91
- return;
92
- }
93
- tokenChainObj[attrNameLower] = tokenChainObj[attrNameLower] || new AttributeTokenChain();
94
- tokenChainObj[attrNameLower].addFromNodeAttrsArray(attrValues.split(/\s/));
95
- });
96
- return node;
97
- });
98
-
99
- // Traverse through tree again, this time sort the attribute values
100
- tree.walk(node => {
101
- if (!node.attrs) {
102
- return node;
103
- }
104
- Object.entries(node.attrs).forEach(([attrName, attrValues]) => {
105
- const attrNameLower = attrName.toLowerCase();
106
- if (!_collapseAttributeWhitespace.attributesWithLists.has(attrNameLower)) {
107
- return;
108
- }
109
- if (tokenChainObj[attrNameLower]) {
110
- node.attrs[attrName] = tokenChainObj[attrNameLower].sortFromNodeAttrsArray(attrValues.split(/\s/)).join(' ');
111
- }
112
- });
113
- return node;
114
- });
115
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _safe = _interopRequireDefault(require("./safe.cjs"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * A safe preset for AMP pages (https://www.ampproject.org)
11
- */
12
- var _default = exports.default = {
13
- ..._safe.default,
14
- collapseBooleanAttributes: {
15
- amphtml: true
16
- },
17
- minifyJs: false
18
- };
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _safe = _interopRequireDefault(require("./safe.cjs"));
8
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
- /**
10
- * Maximal minification (might break some pages)
11
- */
12
- var _default = exports.default = {
13
- ..._safe.default,
14
- collapseWhitespace: 'all',
15
- removeComments: 'all',
16
- removeAttributeQuotes: true,
17
- removeRedundantAttributes: true,
18
- mergeScripts: true,
19
- mergeStyles: true,
20
- removeUnusedCss: {},
21
- minifyCss: {
22
- preset: 'default'
23
- },
24
- minifySvg: {},
25
- minifyConditionalComments: true,
26
- removeOptionalTags: true
27
- };
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- /**
8
- * Minify HTML in a safe way without breaking anything.
9
- */
10
- var _default = exports.default = {
11
- /* ----------------------------------------
12
- * Attributes
13
- * ---------------------------------------- */
14
- // normalize the case of attribute names and values
15
- // normalizeAttributeValues will also normalize property value with invalid value default
16
- // See https://html.spec.whatwg.org/#invalid-value-default
17
- normalizeAttributeValues: true,
18
- removeEmptyAttributes: true,
19
- collapseAttributeWhitespace: true,
20
- // removeRedundantAttributes will remove attributes when missing value default matches the attribute's value
21
- // See https://html.spec.whatwg.org/#missing-value-default
22
- removeRedundantAttributes: false,
23
- // collapseBooleanAttributes will also collapse those default state can be omitted
24
- collapseBooleanAttributes: {
25
- amphtml: false
26
- },
27
- deduplicateAttributeValues: true,
28
- minifyUrls: false,
29
- sortAttributes: false,
30
- sortAttributesWithLists: 'alphabetical',
31
- /* ----------------------------------------
32
- * Minify HTML content
33
- * ---------------------------------------- */
34
- collapseWhitespace: 'conservative',
35
- removeComments: 'safe',
36
- minifyConditionalComments: false,
37
- removeOptionalTags: false,
38
- removeAttributeQuotes: false,
39
- /* ----------------------------------------
40
- * Minify inline <style>, <script> and <svg> tag
41
- * ---------------------------------------- */
42
- mergeStyles: false,
43
- mergeScripts: false,
44
- minifyCss: {
45
- preset: 'default'
46
- },
47
- minifyJs: {},
48
- minifyJson: {},
49
- minifySvg: {
50
- plugins: [{
51
- name: 'preset-default',
52
- params: {
53
- overrides: {
54
- collapseGroups: false,
55
- convertShapeToPath: false
56
- }
57
- }
58
- }]
59
- },
60
- removeUnusedCss: false,
61
- /* ----------------------------------------
62
- * Miscellaneous
63
- * ---------------------------------------- */
64
- custom: []
65
- };
package/test.js DELETED
@@ -1,48 +0,0 @@
1
- const htmlnano = require('.');
2
- // const posthtml = require('posthtml');
3
- const safePreset = require('./lib/presets/safe');
4
- // const options = {
5
- // minifySvg: false,
6
- // minifyJs: false,
7
- // };
8
- // // posthtml, posthtml-render, and posthtml-parse options
9
- // const postHtmlOptions = {
10
- // sync: true, // https://github.com/posthtml/posthtml#usage
11
- // lowerCaseTags: true, // https://github.com/posthtml/posthtml-parser#options
12
- // quoteAllAttributes: false, // https://github.com/posthtml/posthtml-render#options
13
- // };
14
-
15
- // const html = `
16
- // <!doctype html>
17
- // <html lang="en">
18
- // <head>
19
- // <meta charset="utf-8">
20
- // <title></title>
21
- // <script class="fob">alert(1)</script>
22
- // <script>alert(2)</script>
23
- // </head>
24
- // <body>
25
- // <script>alert(3)</script>
26
- // <script>alert(4)</script>
27
- // </body>
28
- // </html>
29
- // `;
30
-
31
- const options = {
32
- minifySvg: safePreset.minifySvg,
33
- };
34
- const html = `
35
- <input type="text" class="form-control" name="testInput" autofocus="" autocomplete="off" id="testId"><a id="testId" href="#" class="testClass"></a><img width="20" src="../images/image.png" height="40" alt="image" class="cls" id="id2">
36
- `;
37
-
38
- htmlnano
39
- // "preset" arg might be skipped (see "Presets" section below for more info)
40
- // "postHtmlOptions" arg might be skipped
41
- .process(html)
42
- .then(function (result) {
43
- // result.html is minified
44
- console.log(result.html);
45
- })
46
- .catch(function (err) {
47
- console.error(err);
48
- });