From bdbd7cf006410b37fc524ec62eb694092bc47f90 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 31 Jan 2024 16:18:42 -0600 Subject: [PATCH] update script to handle all path types --- scripts/migrate_to_md.py | 67 ++++++++++--------- .../client-side-encryption/tests/README.rst | 2 +- .../tests/cmap-format/README.md | 10 +-- .../tests/README.rst | 2 +- source/retryable-reads/retryable-reads.rst | 2 +- source/retryable-writes/retryable-writes.rst | 2 +- .../server-discovery-and-monitoring.rst | 4 +- source/server-selection/server-selection.rst | 2 +- 8 files changed, 46 insertions(+), 45 deletions(-) diff --git a/scripts/migrate_to_md.py b/scripts/migrate_to_md.py index f47d177c39..63219f177d 100644 --- a/scripts/migrate_to_md.py +++ b/scripts/migrate_to_md.py @@ -84,54 +84,55 @@ # Write the new content to the markdown file. md_file = str(path).replace('.rst', '.md') -with open(md_file, 'w') as fid: - fid.write('\n'.join(new_lines)) +# with open(md_file, 'w') as fid: +# fid.write('\n'.join(new_lines)) # Handle links in other files. # We accept relative path links or links to master # (https://github.com/mongodb/specifications/blob/master/source/...) # and rewrite them to use appropriate md links. # If the link is malformed we ignore and print an error. -curr = path -target = path.name -while curr.parent.name != "source": - target = f"{curr.parent.name}/{target}" - curr = curr.parent -pattern = re.compile(f'(<.*{target}[>#])') -pattern2 = re.compile(f'(/source/{target}[>#])') -for p in Path("source").rglob("*.rst"): +rel_pattern = re.compile(f'(\.\.\S*/{path.name})') +md_pattern = re.compile(f'(\(http\S*/{path.name})') +rst_pattern = re.compile(f'(