66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Inject inline style tag into all HTML files to force 12pt font
|
|
"""
|
|
import os
|
|
import re
|
|
from pathlib import Path
|
|
|
|
def inject_style_tag(file_path):
|
|
"""Add style tag after <head> to force 12pt."""
|
|
try:
|
|
with open(file_path, 'r', encoding='utf-8', errors='ignore') as f:
|
|
content = f.read()
|
|
|
|
original_content = content
|
|
|
|
# Check if our style tag already exists
|
|
if '/* FORCE ALL FONTS TO 12PT */' in content:
|
|
return False
|
|
|
|
# Inject style tag after <head> or <HEAD>
|
|
style_injection = '''<style type="text/css">
|
|
/* FORCE ALL FONTS TO 12PT */
|
|
* { font-size: 12pt !important; }
|
|
body, p, li, ol, ul, div, span, td, th, h1, h2, h3, h4, h5, h6 { font-size: 12pt !important; }
|
|
</style>
|
|
'''
|
|
|
|
# Try to inject after <head>
|
|
content = re.sub(r'(<head[^>]*>)', r'\1\n' + style_injection, content, flags=re.IGNORECASE)
|
|
|
|
if content != original_content:
|
|
with open(file_path, 'w', encoding='utf-8', errors='ignore') as f:
|
|
f.write(content)
|
|
return True
|
|
return False
|
|
except Exception as e:
|
|
print(f"Error processing {file_path}: {e}")
|
|
return False
|
|
|
|
def main():
|
|
base_dir = Path('/home/pts/Documents/QBPOS_Help_Web/QB_Help_Web/POS_Help')
|
|
|
|
if not base_dir.exists():
|
|
print(f"Error: Directory {base_dir} not found")
|
|
return
|
|
|
|
# Find all .htm files
|
|
htm_files = list(base_dir.rglob('*.htm'))
|
|
|
|
print(f"Found {len(htm_files)} HTML files")
|
|
print("Injecting inline style tags...")
|
|
|
|
modified_count = 0
|
|
for htm_file in htm_files:
|
|
if inject_style_tag(htm_file):
|
|
modified_count += 1
|
|
if modified_count % 100 == 0:
|
|
print(f" Processed {modified_count} files...")
|
|
|
|
print(f"\nComplete! Modified {modified_count} files")
|
|
print("All files now have inline style tags forcing 12pt font.")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|