HTML version: Add tooling

master
BodgeMaster 2023-09-02 15:46:55 +02:00
parent 259d246ae5
commit 372f2d4f74
3 changed files with 144 additions and 0 deletions

17
README.md Normal file
View File

@ -0,0 +1,17 @@
HTML classes / used elements:
p.light (light font)
p (default)
p.strong (bold font)
p.heavy (very bold font)
p.comment (italic font, gray)
pre.terminal (dark background, light green, strictly limited to 80 characters width)
pre.paper (alternating yellow-ish white and light green lines, black, if posible with a typewriter look)
span.comment (italic font, gray)
li.comment (...)
h1 (full width, centered, horizontal line below, space below)
ul (use small dots or dashes)
use different sets of quotes or formatting depending on whether the quoted text is literal speech

65
md2htmlbody.py Executable file
View File

@ -0,0 +1,65 @@
#!/usr/bin/env python3
import sys, os
def htmlencode(string):
outstring = ""
for char in string:
if char in ["<", ">", "'", "", "\"", "&"]:
replacements = {
"<": "&lt;",
">": "&gt;",
"'": "&apos;",
"": "&apos;",
"\"": "&quot;",
"&": "&amp;"
}
outstring = outstring + replacements[char]
elif ord(char)>127:
outstring = outstring + "&#" + str(ord(char)) + ";"
else:
outstring = outstring + char
return outstring
if len(sys.argv)<3:
print("Usage: " + sys.argv[0] + " <source file> <destination file>")
sys.exit(1)
if not os.path.isfile(sys.argv[1]):
print("Not a file: " + sys.argv[1])
sys.exit(2)
if os.path.isfile(sys.argv[2]):
print("File exists: " + sys.argv[2])
print("Refusing to operate.")
sys.exit(2)
source_file = open(sys.argv[1], "r", encoding="utf-8")
destination_file = open(sys.argv[2], "w", encoding="ascii")
element_type=""
next_source_line = source_file.readline()
while not next_source_line=="":
if next_source_line == "\n":
#TODO: use appropriate end action based on element type
#TODO: deal with closing nested elements
destination_file.write("</"+element_type+">\n")
element_type=""
next_source_line = source_file.readline()
continue
if element_type=="":
#TODO: determine appropriate element type
element_type="p"
destination_file.write("<"+element_type+">\n")
#TODO: deal with multiple spaces appropriately
destination_file.write(" " + htmlencode(next_source_line))
next_source_line = source_file.readline()
if next_source_line=="" and not element_type=="":
#TODO: deal with closing nested elements
destination_file.write("</"+element_type+">\n")

62
template.html Normal file
View File

@ -0,0 +1,62 @@
<html>
<head>
<title> Layout Test </title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1> Layout Test Page </h1>
<p>
This is a test page used for deeloping the stylesheet used for all
the chapters once they have been converted to HTML.
</p>
<p class="light">
Here is some light text.
</p>
<p>
More normal text to fill up the page...
</p>
<p class="strong">
Here is some strong text.
</p>
<p>
It should have a slightly higher font weight than normal - ever so
slightly less than bold.
</p>
<p class="heavy">
Here is some heavy text.
</p>
<p>
It should have a significantly higher font weight than normal - ever
so slightly more than bold.
</p>
<p class="comment">
This is a comment paragraph.
</p>
<p>
There are also <span class="comment"> inline comments </span>.
</p>
<ul>
<li class="comment">
Another form of comments: List items.
</li>
<li class="comment">
Yaaaaay!
</li>
</ul>
<p>
Here are two types of pre-formatted text:
</p>
<pre class="terminal">
This is text on a terminal.
Hello World!
</pre>
<pre class="paper">
This is text printed to tractor feed paper.
Hello World!
Do you see them alternating lines?
Fancy, right?
I have no idea how Im gonna actually build this but imagine alternating
lines on the paper.
</pre>
</body>
</html>