HTML documentation, part 1

This commit is contained in:
tildearrow 2023-09-19 16:44:36 -05:00
parent 5eaafb9f78
commit 6394e239ee
3 changed files with 70 additions and 256 deletions

1
.gitignore vendored
View file

@ -32,4 +32,5 @@ res/binary_to_compressed_c.exe
res/docpdf/manual.html
res/docpdf/manual.pdf
res/docpdf/.venv
res/docpdf/htmldoc/
res/furnace.appdata.xml

View file

@ -2,6 +2,10 @@
echo "compiling Furnace doc (HTML)..."
if [ -e htmldoc ]; then
rm -r htmldoc
fi
if [ ! -e .venv ]; then
python3 -m virtualenv .venv || exit 1
fi
@ -14,3 +18,8 @@ if [ ! -e .venv/req_installed ]; then
fi
python3 make_htmldoc.py
echo "copying assets..."
for i in `find ../../doc -name "*.png"`; do
cp "$i" "htmldoc${i#../../doc}"
done

View file

@ -35,30 +35,23 @@ def fix_links(match):
if os.path.splitext(match.group(2))[-1] == '.png':
return '[%s](%s)' % (
match.group(1),
os.path.join(os.path.split(my_file)[0], match.group(2))
match.group(2)
)
# urls to other files
BASE_URL = 'https://github.com/tildearrow/furnace/tree/master/'
if match.group(2).startswith(BASE_URL):
file_path = match.group(2).split(BASE_URL)[-1]
if os.path.splitext(file_path)[-1] == '':
file_path += '/README.md'
return '[%s](#%s)' % (
match.group(1),
file_path.replace('/','__')
)
# preserve external urls
elif match.group(2).startswith('http'):
return match.group(0)
elif match.group(2).endswith('README.md'):
return '[%s](%s)' % (
match.group(1),
match.group(2).replace('README.md','index.html')
)
# fix paths
act_path = os.path.split(my_file)[0] + '/' + match.group(2)
act_path = os.path.relpath(os.path.abspath(act_path))
return '[%s](#%s)' % (
return '[%s](%s)' % (
match.group(1),
act_path.replace(os.path.sep,'__')
match.group(2).replace('.md','.html')
)
def fix_headings(match):
@ -92,6 +85,15 @@ if __name__ == "__main__":
LOGGER.info("processing file %s" % my_file)
data = md.read()
# retrieve path
pagePath = 'htmldoc' + os.path.sep + my_file[10:]
pagePathH = re.sub(r'\.md$','.html',pagePath).replace("README.html","index.html")
docDir = pagePath[:pagePath.rfind(os.path.sep)]
LOGGER.info("path: %s" % pagePathH)
if not os.path.exists(docDir):
os.makedirs(docDir)
# retrieve title
pageTitle = data.partition('\n')[0].replace("# ","")
@ -100,245 +102,47 @@ if __name__ == "__main__":
data = re.sub(r'^\s*(#+)', fix_headings, data, flags=re.MULTILINE)
# convert
html +='<section id="%s">%s</section>' % (
my_file.replace(os.path.sep, "__"),
html = '''
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
body {
background-color: #222;
color: #eee;
font-family: sans-serif;
}
a {
color: #adf;
text-decoration: none;
}
a:visited {
color: #adf;
text-decoration: none;
}
b {
color: #fff;
}
h1 {
text-align: center;
}
</style>
<title>%s</title>
</head>
<body>
%s
</body>
</html>
''' % (
pageTitle,
markdown.markdown(data, extensions=['nl2br', 'mdx_breakless_lists', GithubFlavoredMarkdownExtension()])
)
# build html
final_html = ('''
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Furnace Manual</title>
<style>
@font-face {
font-family: 'Exo 2';
font-style: normal;
src: url("fonts/Exo2[wght].ttf") format("truetype");
}
@font-face {
font-family: 'Exo 2';
font-style: italic;
src: url("fonts/Exo2-Italic[wght].ttf") format("truetype");
}
@font-face {
font-family: 'IBM Plex Mono';
font-style: normal;
src: url("fonts/IBMPlexMono-Regular.ttf") format("truetype");
}
body {
font-family: 'Exo 2';
line-height: 1.25;
font-size: 11pt;
color: #000;
}
section {
page-break-before:always;
text-align: left;
hyphens: auto;
}
code {
font-family: 'IBM Plex Mono';
}
ul {
padding-left: 10pt;
margin-right: 4pt;
list-style-type: none;
}
ul > li:before {
content: '-';
padding-right: 3pt;
}
h1 {
hyphens: none;
text-align: left;
}
h2 {
hyphens: none;
text-align: center;
font-size: 36pt;
margin: 0;
padding: 0 0 4pt 10pt;
border-style: none none double none;
border-width: 0 0 6pt 0;
}
h3 {
hyphens: none;
text-align: left;
font-size: 20pt;
margin: 0;
padding: 0 0 2pt 10pt;
border-style: none none solid none;
border-width: 0 0 2pt 0;
border-color: #999;
}
h4 {
hyphens: none;
text-align: left;
font-size: 15pt;
margin: 0;
padding: 0 0 2pt 4pt;
}
h5,h6 {
hyphens: none;
text-align: left;
}
img {
max-width: 100%%;
}
a {
color: #204788;
text-decoration: none;
letter-spacing: .01em;
}
a[href^='#']:after {
content: target-counter(attr(href),page);
font-weight: normal;
font-size: 0.5em;
color: #555;
}
a[href^='http']:after {
content: ' (' attr(href) ') ';
font-weight: normal;
color: #555;
}
a.indexItemPre {
color: #000;
text-decoration: none;
letter-spacing: .01em;
}
a.indexItemPre[href^='#']:after {
content: ' ' leader('.') ' ';
font-size: 1em;
}
a.indexItem {
float: right;
overflow: hidden;
}
a.indexItem[href^='#']:after {
content: target-counter(attr(href),page);
color: #000;
font-size: 11pt;
}
#cover {
height: 100%%;
text-align: center;
display: flex;
flex-direction: column;
}
#cover * {
flex-grow: 1;
}
#cover h1 {
text-align: center;
font-size: 2.25em;
}
pre {
font-size: .8em;
}
li > p {
display: inline;
}
table {
display: block;
width: 100%%;
max-width: 100%%;
overflow: auto;
border-collapse: collapse;
text-align: left;
}
table tr {
border-top: 1pt solid #aaa;
}
th, td {
padding: 2pt 3pt;
border: 1pt solid #ccc;
}
th {
hyphens: none;
padding: 2pt 4pt;
text-transform: uppercase;
font-size: .8em;
}
td {
font-size: 11pt;
}
@page {
size: a4;
margin: 14mm 16mm 3cm 16mm;
}
@page:left {
@bottom-left {
content: counter(page);
font-family: 'Exo 2';
font-size: 10pt;
}
}
@page:right {
@bottom-left {
content: 'Furnace manual';
font-family: 'Exo 2';
font-size: 10pt;
color: #777;
}
@bottom-right {
content: counter(page);
font-family: 'Exo 2';
font-size: 10pt;
}
}
@page:first {
@bottom-left {
content: '';
}
@bottom-right {
content: '';
}
}
</style>
</head>
<body>
<section id="cover">
<div>
</div>
<div>
<img src="../logo.png" style="width: 288pt;">
<h1>Furnace<br/>User Manual</h1>
</div>
<div>
<i>for version 0.6</i>
</div>
</section>
<section id="authors">
<div>
</div>
<div>
<h3>authors</h3>
<ul>
<li>cam900</li>
<li>DeMOSic</li>
<li>Electric Keet</li>
<li>freq-mod</li>
<li>host12prog</li>
<li>nicco1690</li>
<li>tildearrow</li>
</ul>
<p>special thanks to ZoomTen for providing tools which assisted in the production of this document!</p>
<p>copyright © 2023 tildearrow and other authors.</p>
<p>this documentation is under the <a href="https://creativecommons.org/licenses/by/3.0/">Creative Commons Attribution 3.0 Unported</a> license.</p>
<p>you may reproduce, modify and/or distribute this documentation provided this copyright notice (including license and attribution) is present and any necessary disclaimers whether modifications have been made.</p>
<p>this documentation is provided as-is and without warranty of any kind.</p>
<p>this manual is written for version 0.6 of Furnace.<br/>it may not necessarily apply to previous or future versions.</p>
</section>
<section id="index">
%s
</section>
%s
</body>
</html>
''' % (
index, html
)
)
with open(pagePathH, 'w') as ht:
ht.write(html)