|
import os |
|
import re |
|
|
|
def move_example_images_section(file_path): |
|
with open(file_path, 'r') as file: |
|
content = file.read() |
|
|
|
example_images_section = re.search(r'## Example Images.*?(?=##|$)', content, re.DOTALL) |
|
introduction_index = content.find('## Introduction') |
|
|
|
if example_images_section and introduction_index != -1: |
|
example_images_text = example_images_section.group() |
|
|
|
|
|
content = content.replace(example_images_text, '') |
|
|
|
|
|
new_content = content[:introduction_index] + example_images_text + '\n' + content[introduction_index:] |
|
|
|
with open(file_path, 'w') as file: |
|
file.write(new_content) |
|
|
|
def recurse_directories(target_dir='.'): |
|
for root, dirs, files in os.walk(target_dir): |
|
for file in files: |
|
if file.endswith('.md'): |
|
file_path = os.path.join(root, file) |
|
move_example_images_section(file_path) |
|
|
|
if __name__ == '__main__': |
|
target_directory = '.' |
|
recurse_directories(target_directory) |
|
|
|
|