import sys
import pypandoc
import os
from bs4 import BeautifulSoup

filename=sys.argv[1]
print(filename)

with open(filename, "r") as fin:
    source=fin.read()

if source.startswith("---\n"):
    frontmatter, contents=source.split("\n---\n")
    output = pypandoc.convert_text(contents, 'gfm', format='html')#, extra_args=["--type=gfm"])
    with open(sys.argv[2], "w+") as fout:
        fout.write(frontmatter+"\n---\n"+output)
else:
    output = pypandoc.convert_text(source, 'gfm', format='html')#, extra_args=["--type=gfm"])
    with open(sys.argv[2], "w+") as fout:
        fout.write(output)
