No longer runs markdown twice to make printme.html.
Instead uses empty spans to mark page breaks and then replaces them.
This commit is contained in:
parent
a769a38dff
commit
f7fbbd5fe4
|
@ -15,6 +15,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
|
|
||||||
![Main Assembly](assemblies/main_assembled.png)
|
![Main Assembly](assemblies/main_assembled.png)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
|
|
||||||
---
|
---
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
@ -24,6 +25,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
1. [Mains In Assembly](#mains_in_assembly)
|
1. [Mains In Assembly](#mains_in_assembly)
|
||||||
1. [Main Assembly](#main_assembly)
|
1. [Main Assembly](#main_assembly)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -54,6 +56,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
| 1 | . | . | . | 1 | socket_box.stl |
|
| 1 | . | . | . | 1 | socket_box.stl |
|
||||||
| 1 | 4 | . | . | 5 | Total 3D printed parts count |
|
| 1 | 4 | . | . | 5 | Total 3D printed parts count |
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -81,6 +84,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
|
|
||||||
![base_assembled](assemblies/base_assembled.png)
|
![base_assembled](assemblies/base_assembled.png)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -117,6 +121,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
|
|
||||||
![feet_assembled](assemblies/feet_assembled.png)
|
![feet_assembled](assemblies/feet_assembled.png)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -156,6 +161,7 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
|
|
||||||
![mains_in_assembled](assemblies/mains_in_assembled.png)
|
![mains_in_assembled](assemblies/mains_in_assembled.png)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
@ -199,4 +205,5 @@ Earth leakage can be measured Canadian CSA style by disconnected the neutral lin
|
||||||
|
|
||||||
![main_assembled](assemblies/main_assembled.png)
|
![main_assembled](assemblies/main_assembled.png)
|
||||||
|
|
||||||
|
<span></span>
|
||||||
[Top](#TOP)
|
[Top](#TOP)
|
||||||
|
|
|
@ -79,11 +79,8 @@ def bom_to_assemblies(bom_dir, bounds_map):
|
||||||
flat_bom = flat_bom[:-1]
|
flat_bom = flat_bom[:-1]
|
||||||
return [assembly["name"] for assembly in flat_bom]
|
return [assembly["name"] for assembly in flat_bom]
|
||||||
|
|
||||||
def eop(print_mode, doc_file, last = False, first = False):
|
def eop(doc_file, last = False, first = False):
|
||||||
if print_mode:
|
print('<span></span>', file = doc_file) # An invisable marker for page breaks because markdown takes much longer if the document contains a div
|
||||||
if not last:
|
|
||||||
print('\n<div style="page-break-after: always;"></div>', file = doc_file)
|
|
||||||
else:
|
|
||||||
if not first:
|
if not first:
|
||||||
print('[Top](#TOP)', file = doc_file)
|
print('[Top](#TOP)', file = doc_file)
|
||||||
if not last:
|
if not last:
|
||||||
|
@ -206,7 +203,6 @@ def views(target, do_assemblies = None):
|
||||||
#
|
#
|
||||||
# Build the document
|
# Build the document
|
||||||
#
|
#
|
||||||
for print_mode in [True, False]:
|
|
||||||
doc_name = top_dir + "readme.md"
|
doc_name = top_dir + "readme.md"
|
||||||
with open(doc_name, "wt") as doc_file:
|
with open(doc_name, "wt") as doc_file:
|
||||||
#
|
#
|
||||||
|
@ -223,14 +219,13 @@ def views(target, do_assemblies = None):
|
||||||
if len(text):
|
if len(text):
|
||||||
print(blurbs[0], file = doc_file)
|
print(blurbs[0], file = doc_file)
|
||||||
else:
|
else:
|
||||||
if print_mode:
|
|
||||||
print(Fore.MAGENTA + "Missing project description" + Fore.WHITE)
|
print(Fore.MAGENTA + "Missing project description" + Fore.WHITE)
|
||||||
#
|
#
|
||||||
# Only add the image if the first blurb section doesn't contain one.
|
# Only add the image if the first blurb section doesn't contain one.
|
||||||
#
|
#
|
||||||
if not re.search(r'\!\[.*\]\(.*\)', blurbs[0], re.MULTILINE):
|
if not re.search(r'\!\[.*\]\(.*\)', blurbs[0], re.MULTILINE):
|
||||||
print('![Main Assembly](assemblies/%s.png)\n' % flat_bom[-1]["name"].replace('_assembly', '_assembled'), file = doc_file)
|
print('![Main Assembly](assemblies/%s.png)\n' % flat_bom[-1]["name"].replace('_assembly', '_assembled'), file = doc_file)
|
||||||
eop(print_mode, doc_file, first = True)
|
eop(doc_file, first = True)
|
||||||
#
|
#
|
||||||
# Build TOC
|
# Build TOC
|
||||||
#
|
#
|
||||||
|
@ -243,7 +238,7 @@ def views(target, do_assemblies = None):
|
||||||
print(file = doc_file)
|
print(file = doc_file)
|
||||||
if len(blurbs) > 1:
|
if len(blurbs) > 1:
|
||||||
print(blurbs[1], file = doc_file)
|
print(blurbs[1], file = doc_file)
|
||||||
eop(print_mode, doc_file)
|
eop(doc_file)
|
||||||
#
|
#
|
||||||
# Global BOM
|
# Global BOM
|
||||||
#
|
#
|
||||||
|
@ -292,7 +287,7 @@ def views(target, do_assemblies = None):
|
||||||
print(file = doc_file)
|
print(file = doc_file)
|
||||||
if len(blurbs) > 2:
|
if len(blurbs) > 2:
|
||||||
print(blurbs[2], file = doc_file)
|
print(blurbs[2], file = doc_file)
|
||||||
eop(print_mode, doc_file)
|
eop(doc_file)
|
||||||
#
|
#
|
||||||
# Assembly instructions
|
# Assembly instructions
|
||||||
#
|
#
|
||||||
|
@ -367,28 +362,47 @@ def views(target, do_assemblies = None):
|
||||||
if "blurb" in ass and ass["blurb"]:
|
if "blurb" in ass and ass["blurb"]:
|
||||||
print(ass["blurb"], file = doc_file)
|
print(ass["blurb"], file = doc_file)
|
||||||
else:
|
else:
|
||||||
if print_mode:
|
|
||||||
print(Fore.MAGENTA + "Missing instructions for %s" % name, Fore.WHITE)
|
print(Fore.MAGENTA + "Missing instructions for %s" % name, Fore.WHITE)
|
||||||
|
|
||||||
name = name.replace('_assembly', '_assembled')
|
name = name.replace('_assembly', '_assembled')
|
||||||
print('![%s](assemblies/%s)\n' % (name, name + suffix), file = doc_file)
|
print('![%s](assemblies/%s)\n' % (name, name + suffix), file = doc_file)
|
||||||
eop(print_mode, doc_file, last = ass == flat_bom[-1] and not main_blurb)
|
eop(doc_file, last = ass == flat_bom[-1] and not main_blurb)
|
||||||
#
|
#
|
||||||
# If main module is suppressed print any blurb here
|
# If main module is suppressed print any blurb here
|
||||||
#
|
#
|
||||||
if main_blurb:
|
if main_blurb:
|
||||||
print(main_blurb, file = doc_file)
|
print(main_blurb, file = doc_file)
|
||||||
eop(print_mode, doc_file, last = True)
|
eop(doc_file, last = True)
|
||||||
#
|
#
|
||||||
# Convert to HTML
|
# Convert to HTML
|
||||||
#
|
#
|
||||||
html_name = "printme.html" if print_mode else "readme.html"
|
html_name = 'readme.html'
|
||||||
t = time.time()
|
t = time.time()
|
||||||
with open(top_dir + html_name, "wt") as html_file:
|
with open(top_dir + html_name, "wt") as html_file:
|
||||||
do_cmd(("python -m markdown -x tables -x sane_lists " + doc_name).split(), html_file)
|
do_cmd(("python -m markdown -x tables -x sane_lists " + doc_name).split(), html_file)
|
||||||
times.add_time(top_dir + html_name, t)
|
times.add_time(top_dir + html_name, t)
|
||||||
times.print_times()
|
times.print_times()
|
||||||
#
|
#
|
||||||
|
# Make the printme.html by replacing empty spans that invisbly mark the page breaks by page break divs.
|
||||||
|
#
|
||||||
|
with open(top_dir + 'readme.html', 'rt') as src:
|
||||||
|
lines = src.readlines()
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
with open(top_dir + 'printme.html', 'wt') as dst:
|
||||||
|
while i < len(lines):
|
||||||
|
line = lines[i]
|
||||||
|
if line.startswith('<p><span></span>'): # Empty span used to mark page breaks
|
||||||
|
i += 1
|
||||||
|
if lines[i].startswith('<a href="#TOP">Top</a>'): # The first page break won't have one
|
||||||
|
i += 1
|
||||||
|
if i < len(lines) and lines[i] == '<hr />\n': # The last page break doesn't have one
|
||||||
|
dst.write('<div style="page-break-after: always;"></div>\n')
|
||||||
|
i += 1
|
||||||
|
else:
|
||||||
|
dst.write(line)
|
||||||
|
i += 1
|
||||||
|
#
|
||||||
# Spell check
|
# Spell check
|
||||||
#
|
#
|
||||||
do_cmd(('codespell -L od ' + top_dir + 'readme.md').split())
|
do_cmd(('codespell -L od ' + top_dir + 'readme.md').split())
|
||||||
|
|
Loading…
Reference in New Issue