2021-04-14 01:26:24 +02:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
import sys, os, re, markdown, datetime
|
|
|
|
|
2021-10-14 00:11:27 +02:00
|
|
|
|
2021-04-18 20:43:19 +02:00
|
|
|
# Getoptions
|
2021-04-14 01:26:24 +02:00
|
|
|
try:
|
2021-04-14 12:59:22 +02:00
|
|
|
parameters = sys.argv[1]
|
2021-04-14 01:26:24 +02:00
|
|
|
except:
|
|
|
|
sys.exit(
|
|
|
|
sys.argv[0]
|
|
|
|
+ ": Bitte eine Text oder Markdowndatei angeben.\ Dieses Tool wandelt eine entsprechende Datei in eine einfache Webseite"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2021-04-17 16:21:17 +02:00
|
|
|
if parameters == "--html":
|
|
|
|
fileending = ".html"
|
2021-04-14 12:59:22 +02:00
|
|
|
try:
|
2021-04-17 16:21:17 +02:00
|
|
|
parameters = sys.argv[2]
|
2021-04-14 12:59:22 +02:00
|
|
|
except:
|
|
|
|
sys.exit(
|
|
|
|
sys.argv[0]
|
|
|
|
+ ": Bitte eine Text oder Markdowndatei angeben.\ Dieses Tool wandelt eine entsprechende Datei in eine einfache Webseite"
|
|
|
|
)
|
|
|
|
else:
|
2021-04-17 16:21:17 +02:00
|
|
|
fileending = ""
|
2021-04-14 12:59:22 +02:00
|
|
|
|
2021-04-17 16:21:17 +02:00
|
|
|
mark_down_file = parameters
|
2021-04-14 12:59:22 +02:00
|
|
|
|
2021-04-17 16:21:17 +02:00
|
|
|
creationtime = datetime.datetime.now().strftime("%Y-%m-%d %H:00 ")
|
2021-04-23 20:15:14 +02:00
|
|
|
creationtimeheader = datetime.datetime.now().strftime("%Y-%m-%d %H:%M")
|
2021-04-14 01:26:24 +02:00
|
|
|
|
|
|
|
if re.match(".*\.md$", mark_down_file):
|
2021-04-23 20:15:14 +02:00
|
|
|
new_file_name = creationtime + " " + re.sub(".md$", fileending, mark_down_file)
|
2021-04-14 01:26:24 +02:00
|
|
|
html_out_file = open(new_file_name, "w")
|
|
|
|
title_of_text = re.sub(".md$", "", mark_down_file)
|
|
|
|
else:
|
|
|
|
html_out_file = sys.stdout
|
2021-04-17 16:21:17 +02:00
|
|
|
title_of_text = mark_down_file
|
2021-04-14 01:26:24 +02:00
|
|
|
|
|
|
|
head1 = (
|
2021-04-23 20:15:14 +02:00
|
|
|
'<!DOCTYPE HTML><html><head>\n\
|
|
|
|
<meta http-equiv="content-type" content="text/html; charset=UTF-8">\n<title>'
|
2021-04-14 01:26:24 +02:00
|
|
|
+ title_of_text
|
|
|
|
+ '</title>\n\
|
|
|
|
<meta name="syntax" content="markdown">\n\
|
|
|
|
<meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">\n\
|
|
|
|
<meta name="ctime" content="'
|
2021-04-23 20:15:14 +02:00
|
|
|
+ creationtimeheader
|
2021-10-14 00:11:27 +02:00
|
|
|
+ '"> '
|
2021-04-14 01:26:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
styles = " <!--\n\
|
2021-04-23 20:15:14 +02:00
|
|
|
* { font-family: monospace; color: #00f020; background-color: #1c1414; font-size: 1.15em; }\n\
|
|
|
|
a { font-size: 1.0em;}\n\
|
2021-10-14 00:11:27 +02:00
|
|
|
ul { font-size: 1.15em;}\n\
|
|
|
|
p { font-size: 1.15em;}\n\
|
|
|
|
li { font-size: 1.15em;}\n\
|
2021-04-24 14:23:19 +02:00
|
|
|
ol { font-size: 1.0em;}\n\
|
2021-04-23 20:15:14 +02:00
|
|
|
em { font-size: 1.0em;}\n\
|
|
|
|
table { background-color: #1c1414; }\n\
|
2021-10-14 00:11:27 +02:00
|
|
|
blockquote { font-size: 1.15em; }\n\
|
2021-04-23 20:15:14 +02:00
|
|
|
body { font-family: monospace; color: #00f020; background-color: #1c1414; }\n\
|
|
|
|
pre { white-space: pre-wrap; font-family: monospace; color: #00f020; font-background-color: #1c1414; }\n\
|
2021-04-14 01:26:24 +02:00
|
|
|
.Statement { color: #00f020; font-weight: bold; }\n\
|
2021-04-23 20:15:14 +02:00
|
|
|
.Headandfoot { color: #00f020; font-weight: bold; } "
|
|
|
|
|
2021-10-14 00:11:27 +02:00
|
|
|
style_fn = '<link rel="stylesheet" type="text/css" href="/vimstyles.css">'
|
|
|
|
|
|
|
|
head2 = "</head><body>\n"
|
|
|
|
body1 = '<a href="./">Back</a>'
|
2021-04-14 01:26:24 +02:00
|
|
|
foot = "</body> </html>"
|
|
|
|
|
|
|
|
|
2021-10-14 00:11:27 +02:00
|
|
|
html_out_file.write(head1 + style_fn + head2 + body1)
|
2021-04-14 01:26:24 +02:00
|
|
|
|
2021-10-14 00:11:27 +02:00
|
|
|
with open(mark_down_file, "r", encoding="utf-8") as infile:
|
|
|
|
md_data = infile.read()
|
|
|
|
html_output = markdown.markdown(md_data)
|
|
|
|
html_out_file.write(html_output)
|
2021-04-14 01:26:24 +02:00
|
|
|
html_out_file.write(foot)
|
2021-04-17 16:21:17 +02:00
|
|
|
|
2021-04-23 20:15:14 +02:00
|
|
|
# return new filename to stdout, so some calling shellscript can use it.
|
2021-04-18 20:43:19 +02:00
|
|
|
print(new_file_name)
|