const fs = require('fs');

let html = fs.readFileSync('index.html', 'utf8');

const regex = /class="([^"]+)"/g;

let extractedRules = new Set();

const updatedHtml = html.replace(regex, (match, classStr) => {
    let classes = classStr.split(/\s+/);
    let newClasses = [];
    let hasRemoved = false;
    
    for (let c of classes) {
        if (c.startsWith('fw-') || c.startsWith('fs-') || c.startsWith('display-') || c.startsWith('lh-')) {
            // we remove these typography utilities
            hasRemoved = true;
        } else {
            newClasses.push(c);
        }
    }
    
    if (hasRemoved) {
        return `class="${newClasses.join(' ')}"`;
    }
    return match;
});

fs.writeFileSync('index_cleaned.html', updatedHtml);
console.log('Done stripping utility classes.');
