|
import os |
|
import re |
|
|
|
def fix_blurhash_block(content): |
|
|
|
pattern = r'{{<\s*blurhash\s*\n((?:[^>}]|\n)*?)>}}' |
|
|
|
def replace_block(match): |
|
lines = match.group(1).strip().split('\n') |
|
|
|
processed_lines = [] |
|
for line in lines: |
|
|
|
clean_line = line.strip() |
|
|
|
processed_lines.append(f" {clean_line}") |
|
|
|
|
|
if 'alt=' in clean_line: |
|
grid_line = ' grid="true"' |
|
processed_lines.append(grid_line) |
|
|
|
|
|
return '{{< blurhash\n' + '\n'.join(processed_lines) + '\n>}}' |
|
|
|
|
|
return re.sub(pattern, replace_block, content, flags=re.MULTILINE) |
|
|
|
def process_file(file_path): |
|
try: |
|
|
|
with open(file_path, 'r', encoding='utf-8') as f: |
|
content = f.read() |
|
|
|
|
|
modified_content = fix_blurhash_block(content) |
|
|
|
|
|
if content != modified_content: |
|
with open(file_path, 'w', encoding='utf-8') as f: |
|
f.write(modified_content) |
|
print(f"Processed: {file_path}") |
|
|
|
except Exception as e: |
|
print(f"Error processing {file_path}: {str(e)}") |
|
|
|
def main(): |
|
|
|
for root, dirs, files in os.walk('.'): |
|
for file in files: |
|
if file.endswith('.cringe'): |
|
file_path = os.path.join(root, file) |
|
process_file(file_path) |
|
|
|
if __name__ == '__main__': |
|
main() |
|
|