I am trying to convert all the .html files under a directory into Markdown. After some Googling I discovered a Pypi script called html2text.
Then I wrote a code block that can convert one .html into .md at a time.
import html2text as ht
import os
import sys
from pathlib import Path
text_maker = ht.HTML2Text()
with open('myHtmlFilePath.html','r',encoding='UTF-8') as f:
htmlpage = f.read()
text = text_maker.handle(htmlpage)
with open('myMarkdownFileName.md','w') as f:
f.write(text)
Is there any possibility that I can wrap this code block in a loop, so that it can convert any file with the filename extension .html into .md under a given directory?