toolkit / utils /remove_extra_whitespace.py
k4d3's picture
chmod
fea0c98
raw
history blame
697 Bytes
from utils.file_processor import FileProcessor, ProcessorOptions
import re
from pathlib import Path
class WhitespaceProcessor(FileProcessor):
def process_content(self, content: str) -> str:
# Replace multiple spaces with a single space
content = ' '.join(content.split())
# Replace multiple newlines with a single newline
return '\n'.join(line.strip() for line in content.split('\n'))
def main():
options = ProcessorOptions(
recursive=True,
dry_run=False,
file_extensions={'.txt', '.caption'}
)
processor = WhitespaceProcessor(options)
processor.process_directory(Path('.'))
if __name__ == "__main__":
main()