guidelinescraper 1.0.13 → 1.0.14
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.
- package/package.json +1 -1
- package/purge-html.mjs +11 -15
package/package.json
CHANGED
package/purge-html.mjs
CHANGED
|
@@ -99,10 +99,6 @@ export function purge(html) {
|
|
|
99
99
|
/Your changes could not be saved\.\s*Please reload the page and try it again\./,
|
|
100
100
|
/^Describe this color palette here$/i,
|
|
101
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
|
-
|
|
106
102
|
const walk = (node) => {
|
|
107
103
|
for (const child of [...node.childNodes]) {
|
|
108
104
|
if (child.nodeType === 3) {
|
|
@@ -110,16 +106,6 @@ export function purge(html) {
|
|
|
110
106
|
for (const pat of NOISE_PATTERNS) {
|
|
111
107
|
text = text.replace(pat, "");
|
|
112
108
|
}
|
|
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
109
|
if (text.trim()) {
|
|
124
110
|
child.textContent = text;
|
|
125
111
|
} else {
|
|
@@ -136,7 +122,17 @@ export function purge(html) {
|
|
|
136
122
|
const cleanHtml =
|
|
137
123
|
`<!DOCTYPE html>\n<html lang="${document.documentElement?.getAttribute("lang") || "en"}">\n<head>\n<meta charset="utf-8">\n<title>${title}</title>\n<style>body{max-width:72ch;margin:2rem auto;padding:0 1rem;font:1rem/1.6 monospace}img{max-width:100%;height:auto}pre{background:#f5f5f5;padding:1rem;overflow-x:auto;border-radius:4px}code{font-family:monospace}table{border-collapse:collapse;width:100%}th,td{border:1px solid #ccc;padding:.5rem;text-align:left}th{background:#f5f5f5}</style>\n</head>\n<body>\n${main.innerHTML.trim()}\n</body>\n</html>`;
|
|
138
124
|
|
|
139
|
-
|
|
125
|
+
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";
|
|
126
|
+
// Insert ": " when a format label is concatenated with its value
|
|
127
|
+
const concatRe = new RegExp(`(${COLOR_FORMATS})(#|\\d)`, "g");
|
|
128
|
+
// Remove empty format entries (element containing only a format name, no value)
|
|
129
|
+
const emptyTagRe = new RegExp(`<(p|td|li|dd|span)([^>]*)>\\s*(${COLOR_FORMATS})\\s*<\\/\\1>`, "g");
|
|
130
|
+
|
|
131
|
+
return cleanHtml
|
|
132
|
+
.replace(concatRe, "$1: $2")
|
|
133
|
+
.replace(emptyTagRe, "")
|
|
134
|
+
.replace(/\n{3,}/g, "\n\n")
|
|
135
|
+
.replace(/[ \t]+\n/g, "\n");
|
|
140
136
|
}
|
|
141
137
|
|
|
142
138
|
// CLI mode: run standalone on a directory
|