6 # Python script to rewrite Markdown links and remove anchors
9 # Define the path for the input and output files
10 input_file_path = sys.argv[1]
11 output_file_path = "out.md"
13 # Define the regular expression patterns for Markdown links and anchors
14 markdown_link_pattern = re.compile(r'\]\(/(\d{4}/\w{3}/[-\w]+/)\)')
15 anchor_pattern = re.compile(r'<a id="[-\w]+"></a>')
17 # TODO: don't neglect links with #-section
18 # TODO: don't neglect images
20 # Read the content of the original markdown file
21 with open(input_file_path, 'r') as file:
24 # Replace the Markdown links with the new format
25 rewritten_content = markdown_link_pattern.sub(r'](http://unremediatedgender.space/\1)', content)
28 rewritten_content = anchor_pattern.sub('', rewritten_content)
30 # Write the rewritten content to a new file
31 with open(output_file_path, 'w') as file:
32 file.write(rewritten_content)
34 print(f"rewritten markdown has been saved to {output_file_path}")