Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DRIVERS-2789 Convert DNS Seedlist Spec to Markdown #1538

Merged
merged 3 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions scripts/migrate_to_md.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@

# Pre-process the file.
for (i, line) in enumerate(lines):
# Replace curly quotes with regular quotes.
line = line.replace('”', '"')
line = line.replace('“', '"')
line = line.replace('’', "'")
line = line.replace('‘', "'")
lines[i] = line

# Replace the colon fence blocks with bullets,
# e.g. :Status:, :deprecated:, :changed:.
# This also includes the changelog entries.
Expand All @@ -59,12 +66,6 @@
if line.strip() == '.. contents::':
lines[i] = ''

# Replace curly quotes with regular quotes.
line = line.replace('”', '"')
line = line.replace('“', '"')
line = line.replace('’', "'")
line = line.replace('‘', "'")

# Run pandoc and capture output.
proc = subprocess.Popen(['pandoc', '-f', 'rst', '-t', 'gfm'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
data = ''.join(lines).encode('utf8')
Expand Down Expand Up @@ -128,15 +129,15 @@
suffix = f'\S*/{target}'
rel_pattern = re.compile(f'(\.\.{suffix})')
md_pattern = re.compile(f'(\(http{suffix})')
rst_pattern = re.compile(f'(<http{suffix})')
html_pattern = re.compile(f'(http{suffix})')
abs_pattern = re.compile(f'(/source{suffix})')
for p in Path("source").rglob("*"):
if p.suffix not in ['.rst', '.md']:
continue
found = False
with p.open() as fid:
lines = fid.readlines()
new_lines = []
changed_lines = []
relpath = os.path.relpath(md_file, start=p.parent)
for line in lines:
new_line = line
Expand All @@ -149,25 +150,26 @@
print('*** Error in link: ', matchstr, p)
else:
new_line = line.replace(matchstr, f'({relpath}')
elif re.search(rst_pattern, line):
matchstr = re.search(rst_pattern, line).groups()[0]
if not matchstr.startswith('<https://github.com/mongodb/specifications/blob/master/source'):
elif re.search(html_pattern, line):
matchstr = re.search(html_pattern, line).groups()[0]
if not matchstr.startswith('https://github.com/mongodb/specifications/blob/master/source'):
print('*** Error in link: ', matchstr, p)
else:
new_line = line.replace(matchstr, f'<{relpath}')
new_line = line.replace(matchstr, f'{relpath}')
elif re.search(abs_pattern, line):
matchstr = re.search(abs_pattern, line).groups()[0]
new_line = line.replace(matchstr, relpath)

if new_line != line:
found = True
print(new_line)
changed_lines.append(new_line)
new_lines.append(new_line)

if found:
if changed_lines:
with p.open('w') as fid:
fid.writelines(new_lines)
print(f'Updated link(s) in {p}')
print('-' * 80)
print(f'Updated link(s) in {p}...')
print(' ' + '\n '.join(changed_lines))

print('Created markdown file:')
print(md_file)
2 changes: 1 addition & 1 deletion source/connection-string/connection-string-spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Other schemes are also possible and are introduced through additional specificat
top of the connection string as documented in this specification.

For example the `mongodb+srv` specification, introduced with
[Initial DNS Seedlist Discovery](../initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.rst), obtains
[Initial DNS Seedlist Discovery](../initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.md), obtains
information from DNS in addition to just the connection string.

### Userinfo (optional)
Expand Down
2 changes: 1 addition & 1 deletion source/connection-string/connection-string-spec.rst
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ For example the ``mongodb+srv`` specification, introduced with `Initial DNS
Seedlist Discovery`_, obtains information from DNS in addition to just the
connection string.

.. _`Initial DNS Seedlist Discovery`: ../initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.rst
.. _`Initial DNS Seedlist Discovery`: ../initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.md

-------------------
Userinfo (optional)
Expand Down
1 change: 1 addition & 0 deletions source/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
- [GridFS Spec](gridfs/gridfs-spec.md)
- [Handling of DBRefs](./dbref.md)
- [Index Management](index-management/index-management.md)
- [Initial DNS Seedlist Discovery](initial-dns-seedlist-discovery/initial-dns-seedlist-discovery.md)
- [MongoDB Driver Performance Benchmarking](benchmarking/benchmarking.md)
- [Server Selection](server-selection/server-selection.md)
- [Server Selection Test Plan](server-selection/server-selection-tests.md)
Expand Down
Loading
Loading