rtc_prd/cleanup_css.py
2026-02-04 15:33:02 +08:00

29 lines
817 B
Python

import re
# Read the file
with open('d:/Airhub/styles.css', 'r', encoding='utf-8') as f:
content = f.read()
original_size = len(content)
# 1. Replace multiple \r with single \r
content = re.sub(r'\r+', '\r', content)
# 2. Remove consecutive blank lines (keep at most 1 blank line)
content = re.sub(r'(\r?\n){3,}', '\n\n', content)
# 3. Remove trailing whitespace on each line
content = re.sub(r'[ \t]+(\r?\n)', r'\1', content)
# 4. Ensure file ends with single newline
content = content.rstrip() + '\n'
# Write back
with open('d:/Airhub/styles.css', 'w', encoding='utf-8') as f:
f.write(content)
new_size = len(content)
print(f"Original size: {original_size} bytes")
print(f"New size: {new_size} bytes")
print(f"Reduced by: {original_size - new_size} bytes ({(1 - new_size/original_size)*100:.1f}%)")