In the end I managed to fix this by using the following python script. To use this script, change the path at the bottom of the file to be the root of the vault you’re working on. If you comment out the three lines after if new_content != content:
and uncomment the two print statements after that, you can test the output.
import os
import re
def deslugify(slug):
return slug.replace('-', ' ')
def process_file(file_path):
with open(file_path, 'r', encoding='utf-8') as f:
content = f.read()
# Find and replace markdown-style links
# e.g. [Some Header](#some-header) → [Some Header](<#some header>)
new_content = re.sub(
r'\[([^\]]+)\]\(#([a-z0-9\-]+)\)',
lambda m: f'[{m.group(1)}](<#{deslugify(m.group(2))}>)',
content,
flags=re.IGNORECASE
)
if new_content != content:
with open(file_path, 'w', encoding='utf-8') as f:
f.write(new_content)
print(f"Updated: {file_path}")
# print(f"Would update: {file_path}")
# print(new_content)
def process_directory(directory):
for root, _, files in os.walk(directory):
for filename in files:
if filename.endswith('.md'):
process_file(os.path.join(root, filename))
# 🟡 Change this to your folder path
target_directory = '/path/to/vault/root'
process_directory(target_directory)
``