Repository navigation
Expand file tree
/
Copy pathrender_disaster_drill_printable.py
More file actions
124 lines (112 loc) · 4.47 KB
/
Copy pathrender_disaster_drill_printable.py
File metadata and controls
124 lines (112 loc) · 4.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
"""Render docs/disaster-drill.md to a partner-printable HTML page."""
from __future__ import annotations
import html
import re
from pathlib import Path
ROOT = Path(__file__).resolve().parents[1]
MD = ROOT / "docs" / "disaster-drill.md"
def md_to_html(md: str) -> str:
lines = md.splitlines()
out: list[str] = []
in_code = False
for line in lines:
if line.startswith("```"):
if not in_code:
out.append("<pre><code>")
in_code = True
else:
out.append("</code></pre>")
in_code = False
continue
if in_code:
out.append(html.escape(line))
continue
if line.startswith("# "):
out.append(f"<h1>{html.escape(line[2:])}</h1>")
elif line.startswith("## "):
out.append(f"<h2>{html.escape(line[3:])}</h2>")
elif line.startswith("### "):
out.append(f"<h3>{html.escape(line[4:])}</h3>")
elif line.startswith("> "):
out.append(f"<blockquote>{html.escape(line[2:])}</blockquote>")
elif line.startswith("- [ ] "):
out.append(f'<li class="chk">☐ {html.escape(line[6:])}</li>')
elif line.startswith("- "):
out.append(f"<li>{html.escape(line[2:])}</li>")
elif line.strip() == "---":
out.append("<hr/>")
elif line.strip() == "":
out.append("")
elif line.startswith("|"):
out.append(f'<pre class="tbl">{html.escape(line)}</pre>')
else:
t = html.escape(line)
t = re.sub(r"\*\*(.+?)\*\*", r"<strong>\1</strong>", t)
t = re.sub(r"`([^`]+)`", r"<code>\1</code>", t)
out.append(f"<p>{t}</p>")
return "\n".join(out)
def render_page(md: str) -> str:
body = md_to_html(md)
return f"""<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>SkyCache disaster mode drill playbook</title>
<meta name="description" content="Partner printable: SkyCache disaster mode drill. Local mesh and mule - not free commercial broadband."/>
<style>
body {{ font-family: system-ui, Segoe UI, sans-serif; max-width: 44rem; margin: 0 auto; padding: 1.5rem; line-height: 1.5; }}
h1 {{ font-size: 1.6rem; }}
h2 {{ margin-top: 1.6rem; border-top: 1px solid #8883; padding-top: 0.8rem; }}
pre, pre.tbl {{ background: #1113; padding: 0.75rem; overflow-x: auto; font-size: 0.85rem; }}
blockquote {{ border-left: 4px solid #0d9488; margin: 1rem 0; padding: 0.25rem 0.75rem; }}
li.chk {{ list-style: none; margin-left: 0; }}
.banner {{ background: #0f766e22; border: 1px solid #0d9488; padding: 0.75rem 1rem; border-radius: 8px; margin-bottom: 1.25rem; }}
@media print {{
body {{ max-width: none; font-size: 11pt; }}
.noprint {{ display: none; }}
a {{ color: inherit; text-decoration: none; }}
}}
</style>
</head>
<body>
<p class="noprint"><a href="https://skycache.jonbailey.xyz/disaster/">Disaster page</a>
· <a href="https://skycache.jonbailey.xyz/partners/">Partners</a>
· <a href="#" onclick="window.print();return false;">Print</a></p>
<div class="banner"><strong>Partner printable drill</strong> - SkyCache disaster mode elevates emergency/health on local mesh + mule. Not free Starlink. Not medical advice. Not a complete archive.</div>
{body}
<p class="noprint" style="margin-top:2rem;opacity:.7">Source: SkyCache docs/disaster-drill.md · https://skycache.jonbailey.xyz/</p>
</body>
</html>
"""
def main(argv: list[str] | None = None) -> int:
import argparse
ap = argparse.ArgumentParser(
description="Render docs/disaster-drill.md to partner-printable HTML"
)
ap.add_argument(
"--out",
type=Path,
default=ROOT / "docs" / "disaster-drill-printable.html",
help="In-repo (or other) destination HTML path",
)
ap.add_argument(
"--also-web",
type=Path,
default=None,
help="Optional extra copy (e.g. skycache-web public/downloads path). "
"Not written unless this flag is set.",
)
args = ap.parse_args(argv)
page = render_page(MD.read_text(encoding="utf-8"))
dests = [args.out]
if args.also_web is not None:
dests.append(args.also_web)
for d in dests:
d = Path(d)
d.parent.mkdir(parents=True, exist_ok=True)
d.write_text(page, encoding="utf-8")
print("wrote", d, d.stat().st_size)
return 0
if __name__ == "__main__":
raise SystemExit(main())