X-Git-Url: http://unremediatedgender.space/source?a=blobdiff_plain;ds=sidebyside;f=notes%2Fpatriate_links.py;h=c1f23cc2bb3e19b1f226175e1cc99593cc7f0943;hb=HEAD;hp=1781b75e979c2331c374e0235eb29a691fa3f335;hpb=4ec03361902f5ccde1d52e1fff00782fddfcbc9a;p=Ultimately_Untrue_Thought.git diff --git a/notes/patriate_links.py b/notes/patriate_links.py index 1781b75..9f666cd 100755 --- a/notes/patriate_links.py +++ b/notes/patriate_links.py @@ -11,15 +11,19 @@ input_file_path = sys.argv[1] output_file_path = "out.md" # Define the regular expression patterns for Markdown links and anchors -markdown_link_pattern = re.compile(r'\]\(/(\d{4}/\w{3}/[-\w]+/)\)') +relative_link_pattern = re.compile(r'\]\(/(\d{4}/\w{3}/[-\w]+/)(#[-\w]+)?\)') +relative_image_link_pattern = re.compile(r'\]\((/images/[-\w./]+)\)') anchor_pattern = re.compile(r'') +# TODO: don't neglect images + # Read the content of the original markdown file with open(input_file_path, 'r') as file: content = file.read() # Replace the Markdown links with the new format -rewritten_content = markdown_link_pattern.sub(r'](http://unremediatedgender.space/\1)', content) +rewritten_content = relative_link_pattern.sub(r'](http://unremediatedgender.space/\1\2)', content) +rewritten_content = relative_image_link_pattern.sub(r'](http://unremediatedgender.space/\1)', rewritten_content) # Remove the anchors rewritten_content = anchor_pattern.sub('', rewritten_content)