")
+ dirindexfile.write(line)
+ linecounter += 1
+
+ dirindexfile.write(foot)
+ return linecounter
+
+
+# Parse arguments "--html", "--stdout", --spellcheck and "Some Headline"
+# there are 3 parameters. if --html is given, the fileending will be .html.
+# Else, if stdout is choosen there can be no fileending, but it will still contain html
+# the name of the program is stored in myname
+# dont set a name to outfile, it just is initialised here and will be overwritten
+
+optwords = ["--html", "--stdout", "--spellcheck"]
+outfile = ""
+args = sys.argv
+myname = args.pop(0)
+for wish in optwords:
+ if args.count(wish):
+ if wish == "--html":
+ fileending = ".html"
+ args.pop(args.index(wish))
+ if wish == "--spellcheck":
+ dospellcheck = "y"
+ args.pop(args.index(wish))
+ if wish == "--stdout":
+ outfile = sys.stdout
+ args.pop(args.index(wish))
+# Check, if that topic already exists and fetch the appropriate filename
+if len(args) == 1:
+ headline = args[0]
+ inputfile = headline + ".md"
+ outputfile = glob.glob(
+ targetdir + "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9] [0-2][0-9]:[0-6][0-9] " + headline + "*" + fileending
+ )
+ outputfilelength = len(outputfile)
+ if outputfilelength >= 1:
+ outputfile = outputfile[outputfilelength - 1]
+ else:
+ outputfile = targetdir + datetime.datetime.now().strftime("%Y-%m-%d %H:00 ") + headline + fileending
+
+
+elif len(args) == 0:
+ selection = selectfile()
+ inputfile = selection[0]
+ outputfile = selection[1] + fileending
+ headline = selection[2]
+elif len(args) > 1:
+ sys.exit(red + "Too much or wrong parameters:\n" + yellow + myname + ' [--html] [--stdout] ["Some Topic"] ')
+
+
+# This is informal asking yes/no for editing the text
+if outfile == sys.stdout:
+ outputfile = "STDOUT"
+print(yellow + "\nYou will edit now: '" + green + inputfile + yellow + "'\nOutputfile= '" + green + outputfile + "'")
+a = input("\nPress to continue or to stop: ")
+edit(inputfile)
+
+
+# Set ouput to stdout, if requested. Caution, the prompts of this script go there, too,
+# be careful with copy & paste
+if outfile != sys.stdout:
+ html_out_file = open(outputfile, "w")
+else:
+ html_out_file = outfile
+
+# The head of the output. Strip path from myname
+head1 = (
+ '\n\
+\n'
+ + headline
+ + '\n\
+\n\
+\n\
+\n\
+ '
+)
+
+# Some fancy css for minimalistic terminal style
+
+
+style_fn = ''
+head2 = "\n"
+body1 = 'Back
Moin
'
+foot = ' \n'
+
+# write beginning of html-file
+html_out_file.write(head1 + style_fn + head2 + body1)
+
+# The centerpiece - read md-file, convert to html, add head and foot and write result
+with open(inputfile, "r", encoding="utf-8") as infile:
+ md_data = infile.read()
+ html_output = markdown.markdown(md_data)
+ html_out_file.write(html_output)
+ html_out_file.write(foot)
+html_out_file.close()
+
+# if the new filename is not stdout, return new filename to stdout, so some calling shellscript can use it.
+if outfile != sys.stdout:
+ print(outputfile)
+
+# Dig the files-directory and generate an index.
+linecounter = mkdirindex(filesdir, indexfilename, filesdirheadline)
+print("Dirindex in ", filesdir, " has ", linecounter, "lines")
+
+# Have a nice time.