Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import mistune
- from bs4 import BeautifulSoup as bs
- def main():
- file = input("Name of Markdown file: ")
- while ('.md' not in file):
- print("that is not a recognized Markdown file.")
- file = input("Name of Markdown file: ")
- fileName = file.split('.')[0]
- html_doc = open(fileName+".html", 'w')
- generated_html = ("<!DOCTYPE html>" +
- "<!--Converted via md-to-html-->" +
- "<html><head></head><body>")
- with open(file) as f:
- content = f.readlines()
- for line in content:
- generated_html += mistune.markdown(line)
- generated_html += "</body></html>"
- # make BeautifulSoup
- soup = bs(generated_html, "html.parser")
- # prettify the html
- prettyHTML = soup.prettify()
- # write to the html doc
- html_doc.write(prettyHTML)
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement