Created
May 22, 2025 08:26
-
-
Save faithandbrave/40cf4559a6a48578788e860ee55ad08c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import os | |
| import re | |
| BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | |
| def find_md_files(base_dir): | |
| for root, dirs, files in os.walk(base_dir): | |
| for file in files: | |
| if file.endswith('.md'): | |
| yield os.path.join(root, file) | |
| def add_space_to_number_list(text): | |
| # (1),(2) のようなパターンを (1), (2) に置換 | |
| pattern = r'\((\d+)\),(?=\(\d+\))' | |
| return re.sub(pattern, r'(\1), ', text) | |
| def process_file(filepath): | |
| with open(filepath, 'r', encoding='utf-8') as f: | |
| content = f.read() | |
| new_content = add_space_to_number_list(content) | |
| if new_content != content: | |
| with open(filepath, 'w', encoding='utf-8') as f: | |
| f.write(new_content) | |
| print(f"[Replaced] {filepath}") | |
| if __name__ == '__main__': | |
| for md_file in find_md_files(BASE_DIR): | |
| process_file(md_file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment