import re import os docs_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', 'docs')) schema_md_path = os.path.join(docs_dir, 'database_schema.md') mmd_path = os.path.join(docs_dir, 'erd.mmd') with open(schema_md_path, 'r', encoding='utf-8') as f: content = f.read() match = re.search(r'```mermaid\n(.*?)```', content, re.DOTALL) if match: mermaid_code = match.group(1).strip() with open(mmd_path, 'w', encoding='utf-8') as f: f.write(mermaid_code) print(f"Mermaid code extracted to {mmd_path}") else: print("Could not find mermaid block in database_schema.md")