generate html from .md and stdout from other files. New renaming of files. v0.03

This commit is contained in:
Wolfgang Nowak 2021-04-17 16:21:17 +02:00
parent 23e7340925
commit ef5f39473d

View file

@ -11,21 +11,22 @@ except:
)
if parameters== "--html":
fileending=".html"
if parameters == "--html":
fileending = ".html"
try:
mark_down_file = sys.argv[2]
parameters = sys.argv[2]
except:
sys.exit(
sys.argv[0]
+ ": Bitte eine Text oder Markdowndatei angeben.\ Dieses Tool wandelt eine entsprechende Datei in eine einfache Webseite"
)
else:
fileending=""
fileending = ""
mark_down_file = parameters
# creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H ")
creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ")
# creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
if re.match(".*\.md$", mark_down_file):
new_file_name = creationtime + " " + re.sub(".md$", fileending, mark_down_file)
@ -33,10 +34,11 @@ if re.match(".*\.md$", mark_down_file):
title_of_text = re.sub(".md$", "", mark_down_file)
else:
html_out_file = sys.stdout
title_of_text = mark_down_file
head1 = (
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">\n\
'<!DOCTYPE HTML>\n\
<html>\n\
<head>\n\
<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n\
@ -55,7 +57,7 @@ head1 = (
styles = " <!--\n\
* { font-family: monospace; color: #00f020; background-color: #1c1414; font-size: 1.1em;}\n\
* { font-family: monospace; color: #00f020; background-color: #1c1414; font-size: 1.15em;}\n\
body { font-family: monospace; }\n\
pre { white-space: pre-wrap; font-family: monospace; color: #00f020; background-color: #1c1414; }\n\
.Statement { color: #00f020; font-weight: bold; }\n\
@ -72,3 +74,5 @@ with open(mark_down_file) as infile:
a = markdown.markdown(line)
html_out_file.write(a)
html_out_file.write(foot)
print(new_file_name)