Skip to content

Commit 248ed5e

Browse files
Merge pull request avinashkranjan#85 from ragreenburg/html_to_md
Answer to Issue avinashkranjan#11 Html to md
2 parents c2d3b40 + 2863a5e commit 248ed5e

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

HTML_to_MD/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# How to use the html to md script.
2+
All you have to do is download the html2md package with pip (`pip install html2md`) then change the path's that are currently in the script to the location to your html file and where you would like the md file to be saved.
3+
After that just run the script and it should work just fine.

HTML_to_MD/html_to_md.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import html2md
2+
3+
"""
4+
User needs to change the two paths here or else it wont work.
5+
"""
6+
path = "Path/To/Your/HTML"
7+
8+
9+
def html_to_md():
10+
#opens your html file
11+
html = open(path, "r").read()
12+
#converts the html file to a md file
13+
md = html2md.convert(html)
14+
#Path where your md file is saved
15+
md_path = "Path/Where/You/Want/To/Save_MD.file"
16+
#Opens the path location and writes from html to md
17+
with open(md_path, "w") as mrd:
18+
mrd.write(md)
19+
mrd.close()
20+
#Simply tells you it is done.
21+
md_save_str = f"You have successfully written the HTML to a MD file and it is saved at {md_path}"
22+
print(md_save_str)
23+
24+
25+
html_to_md()

0 commit comments

Comments
 (0)