-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmodify-htmlcs.js
More file actions
66 lines (49 loc) · 1.67 KB
/
modify-htmlcs.js
File metadata and controls
66 lines (49 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
modify-htmlcs.js
This script modifies a tic-old.js file to add prefixes to the htmlcs rule IDs.
The script is run from the command line as:
node modify-htmlcs.js
This script is no longer needed, but may serve as a template for future code modifications.
*/
const fs = require('fs');
const filePath = '/Users/pool/Documents/Topics/repos/a11yTesting/testilo/procs/score/tic-old.js';
let content = fs.readFileSync(filePath, 'utf8');
const lines = content.split('\n');
let currentWeight = null;
let inHtmlcs = false;
let htmlcsIndent = 0;
for (let i = 0; i < lines.length; i++) {
const line = lines[i];
const weightMatch = line.match(/^\s+weight:\s*(\d+),?\s*$/);
if (weightMatch) {
currentWeight = parseInt(weightMatch[1]);
}
if (line.match(/^\s+htmlcs:\s*\{/)) {
inHtmlcs = true;
htmlcsIndent = line.search(/\S/);
continue;
}
if (inHtmlcs) {
const currentIndent = line.search(/\S/);
if (currentIndent !== -1 && currentIndent <= htmlcsIndent) {
inHtmlcs = false;
currentWeight = null;
continue;
}
const propertyMatch = line.match(/^(\s+)'([^']+)':\s*\{/);
if (propertyMatch && currentWeight !== null) {
const indent = propertyMatch[1];
let propName = propertyMatch[2];
// Remove existing prefix if present
if (propName.startsWith('W-') || propName.startsWith('E-')) {
propName = propName.substring(2);
}
// Apply correct prefix based on weight
const prefix = currentWeight === 1 ? 'W-' : 'E-';
lines[i] = `${indent}'${prefix}${propName}': {`;
}
}
}
content = lines.join('\n');
fs.writeFileSync(filePath, content, 'utf8');
console.log('Modifications complete!');