check in
[Ultimately_Untrue_Thought.git] / notes / patriate_links.py
diff --git a/notes/patriate_links.py b/notes/patriate_links.py
new file mode 100755 (executable)
index 0000000..1781b75
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/python3
+
+import re
+import sys
+
+# Python script to rewrite Markdown links and remove anchors
+# mostly by GPT-4
+
+# Define the path for the input and output files
+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]+/)\)')
+anchor_pattern = re.compile(r'<a id="[-\w]+"></a>')
+
+# 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)
+
+# Remove the anchors
+rewritten_content = anchor_pattern.sub('', rewritten_content)
+
+# Write the rewritten content to a new file
+with open(output_file_path, 'w') as file:
+    file.write(rewritten_content)
+
+print(f"rewritten markdown has been saved to {output_file_path}")