Skip to content

Instantly share code, notes, and snippets.

@sspaeti
Created September 26, 2021 08:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sspaeti/73a0fd505f8d30dc09198b148255b4c6 to your computer and use it in GitHub Desktop.
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
"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