From the below part of a code I would like to generate an output in .html
format from a given .md
file through command line arguments
#main.py
import os, argparse,
import configparser, webbrowser
parser = argparse.ArgumentParser()
parser.add_argument('--display', dest='display',action='store_true', help='displays the md file',default=None)
parser.add_argument('--inputmarkdown',type=argparse.FileType("r"),help='Provide the markdown file location')
parser.add_argument('--outputmarkdown', type = str, default = "./Output",help='Provide the output display file location')
args = parser.parse_args()
if args.display:
subprocess.run(["pandoc", "--toc", "--standalone","--mathjax", "-t", "html", "--simple_tables", "args.inputmarkdown", "-o", "args.outputmarkdown", "--metadata", "pagetitle=test display"])
url = "file://(args.outputmarkdown)"
webbrowser.open(url,new=1,autoraise=True)
Using the below command line arguments
python3 main.py --display --inputmarkdown file/path/firsttest.md --outputmarkdown /file/path/test/firsttest.html
The above doesn't perform the task and I just have the webbrowser open with file:/// Can someone suggest where the issue is?
The problem is probably with the url string. You are not formatting it. And the variables in the subprocess call are quoted.
Try This
import os, argparse,
import webbrowser
parser = argparse.ArgumentParser()
parser.add_argument('--display', dest='display', action='store_true', help='displays the md file', default=None)
parser.add_argument('--inputmarkdown', help='Provide the markdown file location')
parser.add_argument('--outputmarkdown', default="./Output", help='Provide the output display file location')
parser.add_argument('--pagetitle', dest='pagetitle', default='test display')
args = parser.parse_args()
if args.display:
subprocess.run(["pandoc", "--toc", "--standalone", "--mathjax", "-t", "html", "--simple_tables", args.inputmarkdown, "-o", args.outputmarkdown, "--metadata", f"pagetitle={args.pagetitle}"])
url = f"file://{args.outputmarkdown}"
webbrowser.open(url,new=1,autoraise=True)