guidelinescraper 1.0.11 → 1.0.13

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 (2) hide show
  1. package/package.json +1 -1
  2. package/purge-html.mjs +31 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "guidelinescraper",
3
- "version": "1.0.11",
3
+ "version": "1.0.13",
4
4
  "type": "module",
5
5
  "description": "Scrape a Frontify brand portal and save every page as PDF and clean HTML",
6
6
  "bin": {
package/purge-html.mjs CHANGED
@@ -92,12 +92,39 @@ export function purge(html) {
92
92
  }
93
93
  }
94
94
 
95
- // Remove stray button labels left behind from copy/download widgets
96
- const strayLabels = /^(Copy|Download)\s+(markdown|code|link|text)$/i;
95
+ // Remove Frontify UI noise from text nodes
96
+ const NOISE_PATTERNS = [
97
+ /^(Copy|Download)\s+(markdown|code|link|text)$/i,
98
+ /Lorem ipsum dolor sit amet[\s\S]{0,300}commodo consequat\./,
99
+ /Your changes could not be saved\.\s*Please reload the page and try it again\./,
100
+ /^Describe this color palette here$/i,
101
+ ];
102
+ const COLOR_FORMATS = "HEX|RGB|CMYK|LESS|HSL|HSB|RAL|ORA|PMS|PMS-C|PMS-U|PMS-CP|PMS-PQ|PMS-TCX|CMYK-C|CMYK-U|CMYK-N|NCS|HKS|3M|LAB|PANTONE";
103
+ const COLOR_EMPTY_RE = new RegExp(`^(${COLOR_FORMATS})$`);
104
+ const COLOR_VALUE_RE = new RegExp(`^(${COLOR_FORMATS})(.+)$`);
105
+
97
106
  const walk = (node) => {
98
107
  for (const child of [...node.childNodes]) {
99
- if (child.nodeType === 3 && strayLabels.test(child.textContent.trim())) {
100
- child.remove();
108
+ if (child.nodeType === 3) {
109
+ let text = child.textContent;
110
+ for (const pat of NOISE_PATTERNS) {
111
+ text = text.replace(pat, "");
112
+ }
113
+ // Color palette: remove format-only lines (no value)
114
+ if (COLOR_EMPTY_RE.test(text.trim())) {
115
+ child.remove();
116
+ continue;
117
+ }
118
+ // Color palette: insert ": " between format label and value
119
+ const m = text.trim().match(COLOR_VALUE_RE);
120
+ if (m) {
121
+ text = m[1] + ": " + m[2].trim();
122
+ }
123
+ if (text.trim()) {
124
+ child.textContent = text;
125
+ } else {
126
+ child.remove();
127
+ }
101
128
  } else if (child.nodeType === 1) {
102
129
  walk(child);
103
130
  }