Created
September 26, 2021 08:43
-
-
Save sspaeti/73a0fd505f8d30dc09198b148255b4c6 to your computer and use it in GitHub Desktop.
Convert exported HTML pages to Markdown pages recursively where you start this script from
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"Convert exported HTML pages to Markdown pages recursively where you start this script from" | |
import os | |
from markdownify import markdownify | |
from pathlib import Path | |
for dirpath, dirs, files in os.walk("."): | |
print("--" + dirpath) | |
for filename in files: | |
if filename.endswith(".html"): | |
print(f"filename: {filename}") | |
file = open(os.path.join(dirpath, filename), "r").read() | |
html = markdownify(file, heading_style="ATX") | |
markdown_file = open(os.path.join(dirpath, filename.replace(".html", ".md")), "w") | |
n = markdown_file.write(html) | |
markdown_file.close() | |
else: | |
continue |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment