Spaces:
Running
Running
File size: 1,092 Bytes
4260a62 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
import re
from pathlib import Path
def sync_flowchart():
mmd_path = Path("docs/flowchart.mmd")
readme_path = Path("README.md")
if not mmd_path.exists():
print(f"Error: {mmd_path} not found")
return
if not readme_path.exists():
print(f"Error: {readme_path} not found")
return
with open(mmd_path, "r") as f:
mmd_content = f.read().strip()
with open(readme_path, "r") as f:
readme_content = f.read()
# Regex to find the mermaid block in README.md
# It looks for ```mermaid ... ```
pattern = r"```mermaid\n(.*?)\n```"
new_mermaid_block = f"```mermaid\n{mmd_content}\n```"
if re.search(pattern, readme_content, re.DOTALL):
new_readme_content = re.sub(pattern, new_mermaid_block, readme_content, flags=re.DOTALL)
with open(readme_path, "w") as f:
f.write(new_readme_content)
print("Successfully synced flowchart to README.md")
else:
print("Could not find mermaid block in README.md")
if __name__ == "__main__":
sync_flowchart()
|