From 2e67dc718e71d00f3998b4d97cba5e913aa3a9dd Mon Sep 17 00:00:00 2001 From: Alicia Sykes Date: Wed, 6 Mar 2024 21:59:26 +0000 Subject: [PATCH] Adds @Crazywolf13's docs transformation script --- do-markdown-magic.py | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 do-markdown-magic.py diff --git a/do-markdown-magic.py b/do-markdown-magic.py new file mode 100644 index 00000000..1cec57e0 --- /dev/null +++ b/do-markdown-magic.py @@ -0,0 +1,41 @@ +import os +import re + +def process_file(file_path): + with open(file_path, 'r', encoding='utf-8') as file: + content = file.read() + + # Remove Comments + content = re.sub(r'', '', content, flags=re.DOTALL) + + # Replace
with
+ content = content.replace('
', '
') + + # Make each link relative, so replace ./docs with /docs + content = content.replace('./docs', '/docs') + + # Remove .md extension from every link while ensuring idempotency + content = re.sub(r'(\[[^\]]+\]\((?!https?://)[^)#]+?)\.md(/?#?[^)]*?)(\))', r'\1\2\3', content) + + # Replace back to top buttons + # Assuming this pattern is correct; adjust if necessary + content = re.sub(r'\[.*Back to top.*\]', '[⬆️ Back to Top](https://riot.im/app/#)', content) + + # Remove any
tags + content = re.sub(r'
.*?
', '', content, flags=re.DOTALL) + + # Save the processed content back to the file + with open(file_path, 'w', encoding='utf-8') as file: + file.write(content) + +def process_docs_folder(folder_path): + for root, dirs, files in os.walk(folder_path): + for file in files: + if file.endswith('.md'): + file_path = os.path.join(root, file) + process_file(file_path) + +if __name__ == "__main__": + # Update this path to the correct relative path where the script will be run in the GitHub Action + docs_folder_path = "./docs/" + process_docs_folder(docs_folder_path)