HTML version: Add tooling
parent
259d246ae5
commit
372f2d4f74
|
@ -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
|
|
@ -0,0 +1,65 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import sys, os
|
||||
|
||||
|
||||
def htmlencode(string):
|
||||
outstring = ""
|
||||
for char in string:
|
||||
if char in ["<", ">", "'", "’", "\"", "&"]:
|
||||
replacements = {
|
||||
"<": "<",
|
||||
">": ">",
|
||||
"'": "'",
|
||||
"’": "'",
|
||||
"\"": """,
|
||||
"&": "&"
|
||||
}
|
||||
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")
|
|
@ -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 I’m gonna actually build this but imagine alternating
|
||||
lines on the paper.
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue