#!/usr/bin/env python3 """Builds the help pages, build/site/guide.html: the written guide (tools/site/guide_sections.md) plus reference tables made from the game's own data, so they can't drift from the game: every item (data/items.json), every recipe (data/recipes.json), the fish (data/fish.json), and the creatures and server settings (dumped from the scripts by tools/site/dump_data.gd). python3 tools/site/make_guide.py Called by tools/site/make_site.sh. """ import html, json, os, re, sys ROOT = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "..")) esc = lambda s: html.escape(str(s), quote=True) # --- the written guide: a small, strict markdown subset ----------------------------- def inline(s): s = esc(s) s = re.sub(r"`([^`]+)`", r"\1", s) s = re.sub(r"\*\*([^*]+)\*\*", r"\1", s) # [text](https://...) links (after esc: the URL has no quotes or brackets). s = re.sub(r"\[([^\]]+)\]\((https://[^)\s\"<>]+)\)", r'\1', s) return s def written_sections(): """[(id, title, html)] from guide_sections.md.""" out, cur, buf, in_list = [], None, [], False def close_list(): nonlocal in_list if in_list: buf.append("") in_list = False for raw in open(os.path.join(ROOT, "tools", "site", "guide_sections.md"), encoding="utf-8"): line = raw.rstrip("\n") m = re.match(r"^## (.+?) \{#([a-z0-9-]+)\}\s*$", line) if m: close_list() if cur: out.append((cur[1], cur[0], "\n".join(buf))) cur, buf = (m.group(1), m.group(2)), [] continue if cur is None: continue if line.startswith("### "): close_list() buf.append("

%s

" % inline(line[4:])) elif line.startswith("- "): if not in_list: buf.append("