summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Kurtz <seankurtz75@gmail.com>2026-11-25 20:30:22 -0600
committerSean Kurtz <seankurtz75@gmail.com>2026-11-25 20:30:22 -0600
commit1101f029610080c53ac857a258c6b1b0b64c4b88 (patch)
treeb2004564119085d0f75ba9043f6bdf4c55a5239b
parentdeb0ed011fe2cfc7058facb3f63b7feaeb8d4a8e (diff)
downloadzash-chore/c23-idioms.tar.gz
web: the specification as a page, converted from typst's HTMLchore/c23-idioms
typst writes no markdown, so the site had the typeset HTML export and no page that a reader could search or link into. web/spec-md.py reduces the export to what goldmark reads and hands it to pandoc, then puts back the heading ids the spec cross-references itself by and carries the MathML over untouched: browsers render it, so the page ships no TeX script. `make docs` writes it with the other document pages, and the site stays hand-written pages until someone runs that.
-rw-r--r--.gitignore8
-rw-r--r--Makefile15
-rw-r--r--web/README.md30
-rw-r--r--web/assets/css/zash.css2
-rw-r--r--web/content/docs/_index.md4
-rw-r--r--web/layouts/partials/docs-nav.html6
-rw-r--r--web/layouts/single.html4
-rw-r--r--web/spec-md.py135
8 files changed, 197 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore
index 45ee3f9..bd81591 100644
--- a/.gitignore
+++ b/.gitignore
@@ -22,3 +22,11 @@ __pycache__/
web/public/
web/resources/
web/.hugo_build.lock
+
+# Generated into the site by `make docs` (see web/README.md).
+web/content/docs/readme.md
+web/content/docs/design.md
+web/content/docs/specification.md
+web/static/zash-spec.html
+web/static/zash-spec.pdf
+web/static/reference/
diff --git a/Makefile b/Makefile
index 589fc36..9e4d912 100644
--- a/Makefile
+++ b/Makefile
@@ -437,8 +437,10 @@ docs: doc webdocs
# web/README.md). README.md and DESIGN.md are already markdown, so they are
# copied rather than converted, with a front-matter block in front and the
# logo block at the top pointed at the site's own copy. The specification
-# is typst's HTML export, which keeps the typeset maths; the PDF is copied
-# too, and the Doxygen HTML that `doc` wrote is copied to web/static/reference.
+# is converted from typst's HTML export by web/spec-md.py, which keeps the
+# heading ids the spec cross-references and carries the MathML over; the PDF
+# is copied too, and the Doxygen HTML that `doc` wrote is copied to
+# web/static/reference.
# Nothing is committed: the pages feed `hugo --source web`, and
# `make clean` removes them. WEBDOCS is source:weight:title.
#
@@ -478,6 +480,14 @@ webdocs: doc
else \
echo "webdocs: no typst, web/static/zash-spec.html not written"; \
fi
+ @if [ -f web/static/zash-spec.html ] && command -v pandoc >/dev/null 2>&1 \
+ && command -v python3 >/dev/null 2>&1; then \
+ python3 web/spec-md.py web/static/zash-spec.html \
+ web/content/docs/specification.md || exit 1; \
+ echo web/content/docs/specification.md; \
+ else \
+ echo "webdocs: needs typst, pandoc and python3, specification.md not written"; \
+ fi
@cp formal/zash-spec.pdf web/static/zash-spec.pdf
@if [ -d docs/html ]; then \
rm -rf web/static/reference \
@@ -508,6 +518,7 @@ clean:
rm -f zash.amblist
rm -rf docs cov $(ZTOOLS)
rm -f web/content/docs/readme.md web/content/docs/design.md \
+ web/content/docs/specification.md \
web/static/zash-spec.html web/static/zash-spec.pdf
rm -rf web/static/reference
diff --git a/web/README.md b/web/README.md
index 3b5fadc..5748dd9 100644
--- a/web/README.md
+++ b/web/README.md
@@ -7,6 +7,7 @@ not a build dependency of the shell.
## Local preview
```sh
+make docs # render the documents into web/ (see below)
hugo server --source web # http://localhost:1313/
hugo --source web --minify # -> web/public/
```
@@ -23,6 +24,7 @@ web/
content/
_index.md home page
docs/ the documentation pages, ordered by weight
+ readme.md, design.md: written by `make docs`
layouts/
baseof.html shell of every page
home.html hero and the terminal card
@@ -34,9 +36,35 @@ web/
css/zash.css the design
css/chroma.css `hugo gen chromastyles --style=tokyonight-night`
js/copy.js copy buttons on code blocks, optional
- static/ the logo
+ static/ the logo; the specification and the Doxygen reference,
+ copied in by `make docs`: zash-spec.html, zash-spec.pdf,
+ reference/
```
+## The documents
+
+`README.md`, `DESIGN.md` and the specification are the site's reference pages
+too, so `make docs` (the same target that writes `docs/` for the repository)
+puts copies here, and only here - they are ignored by git, like `docs/`:
+
+- `README.md` and `DESIGN.md` are already markdown, so they are copied with a
+ front-matter block added, the logo block pointed at `static/zash-logo.svg`,
+ a link into the other document turned into a `../design/` page link, and a
+ link to any other file in the tree turned into a GitHub link. `notitle`
+ there keeps `single.html` from printing the title twice, since each document
+ opens with its own heading.
+- The specification is a page too: `web/spec-md.py` turns typst's HTML
+ export into markdown, keeping the heading ids the spec cross-references
+ itself by and carrying the MathML over as it is (browsers render it, so the
+ page needs no TeX script). Typst has no markdown writer. The typeset HTML
+ export and the PDF are copied beside it, and the docs sidebar links all
+ three.
+- The source reference is the Doxygen HTML from `docs/html`, copied to
+ `static/reference/`; its links are relative, so it serves as it is.
+
+So a checkout needs `make docs` before `hugo` for a complete site; the rest of
+the pages are hand-written.
+
No theme module is used: the CSS is a few hundred lines, and the palette comes
from `packaging/zash-logo.svg` - mainframe navy, periwinkle and a signal blue.
The site is dark only, on purpose.
diff --git a/web/assets/css/zash.css b/web/assets/css/zash.css
index 24f8f6a..445e7b3 100644
--- a/web/assets/css/zash.css
+++ b/web/assets/css/zash.css
@@ -481,6 +481,8 @@ code,
pre,
kbd {
font-family: var(--mono);
+ /* <<, <= and ->> are shell syntax, not \u00ab and \u2264 */
+ font-variant-ligatures: none;
}
:not(pre) > code {
diff --git a/web/content/docs/_index.md b/web/content/docs/_index.md
index 8893fad..499d1db 100644
--- a/web/content/docs/_index.md
+++ b/web/content/docs/_index.md
@@ -4,4 +4,6 @@ title: Docs
Everything about building, testing and the current state of zash. The
authoritative documents are in the source tree: `README.md`, `DESIGN.md` and
-`formal/zash-spec.pdf`.
+`formal/zash-spec.pdf`; the README and the design notes are rendered here from
+those same files, and the specification as HTML and PDF, with the source
+reference from Doxygen.
diff --git a/web/layouts/partials/docs-nav.html b/web/layouts/partials/docs-nav.html
index 213a1eb..8f691b5 100644
--- a/web/layouts/partials/docs-nav.html
+++ b/web/layouts/partials/docs-nav.html
@@ -1,5 +1,7 @@
{{ with site.GetPage "/docs" }}
<aside>
+ {{ $spec := "zash-spec" | relURL }}
+ {{ $ref := "reference/" | relURL }}
<div class="group">
<h2>Docs</h2>
{{ range .Pages.ByWeight }}
@@ -10,7 +12,9 @@
<h2>Source</h2>
<a href="{{ site.Params.repo }}/blob/main/README.md">README</a>
<a href="{{ site.Params.repo }}/blob/main/DESIGN.md">DESIGN.md</a>
- <a href="{{ site.Params.repo }}/blob/main/formal/zash-spec.pdf">Specification (PDF)</a>
+ <a href="{{ $spec }}.html">Specification (typeset HTML)</a>
+ <a href="{{ $spec }}.pdf">Specification (PDF)</a>
+ <a href="{{ $ref }}">Source reference</a>
</div>
</aside>
{{ end }}
diff --git a/web/layouts/single.html b/web/layouts/single.html
index 8171148..aef02ce 100644
--- a/web/layouts/single.html
+++ b/web/layouts/single.html
@@ -5,12 +5,12 @@
<article>
<div class="docs-head">
<p class="kicker">docs</p>
- <h1>{{ .Title }}</h1>
+ {{ if not .Params.notitle }}<h1>{{ .Title }}</h1>{{ end }}
{{ with .Description }}<p class="lede">{{ . }}</p>{{ end }}
</div>
{{ .Content }}
<p class="edit">
- <a href="{{ site.Params.repo }}/edit/main/web/content/{{ .File.Path }}">Edit this page</a>
+ <a href="{{ site.Params.repo }}/edit/main/{{ with .Params.source }}{{ . }}{{ else }}web/content/{{ $.File.Path }}{{ end }}">Edit this page</a>
</p>
</article>
</div>
diff --git a/web/spec-md.py b/web/spec-md.py
new file mode 100644
index 0000000..bc77956
--- /dev/null
+++ b/web/spec-md.py
@@ -0,0 +1,135 @@
+#!/usr/bin/env python3
+"""spec-md.py - turn typst's HTML export of the spec into site markdown.
+
+usage: spec-md.py spec.html out.md
+
+typst has no markdown writer, so the HTML export is reduced to what goldmark
+reads and handed to pandoc for headings, lists, tables, links and emphasis.
+The typst heading ids are put back, because the spec cross-references its
+sections by them, and the MathML is carried over untouched: browsers render it
+natively and the page ships no TeX script.
+"""
+
+import re
+import subprocess
+import sys
+
+FRONT = """---
+title: Specification
+weight: 60
+source: formal/zash-spec.typ
+notitle: true
+---
+"""
+
+
+def tables(body):
+ """A table whose first row is all bold has a header; typst writes no <th>."""
+
+ def fix(match):
+ table = match.group(0)
+ row = re.search(r"<tr>.*?</tr>", table, re.S)
+ if not row or row.group(0).count("<strong>") != row.group(0).count("<td>"):
+ return table
+ head = row.group(0).replace("<td>", "<th>").replace("</td>", "</th>")
+ end = row.end()
+ return table[: row.start()] + "<thead>" + head + "</thead>" + table[end:]
+
+ return re.sub(r"<table>.*?</table>", fix, body, flags=re.S)
+
+
+def blocks(body):
+ """<div> is a rule, so it becomes <p>; in a list item only its children count.
+
+ The outline is an unnumbered <ol>, shown as a bullet list.
+ """
+ out = []
+ items = 0
+ stack = []
+ for tag in re.split(r"(<[^>]+>)", body):
+ if re.match(r"<li\b", tag):
+ items += 1
+ out.append(tag)
+ elif tag == "</li>":
+ items -= 1
+ out.append(tag)
+ elif re.match(r"<ol\b", tag):
+ stack.append("ul" if "list-style-type: none" in tag else "ol")
+ out.append(f"<{stack[-1]}>")
+ elif tag == "</ol>":
+ out.append(f"</{stack.pop()}>")
+ elif tag == "<div>":
+ stack.append("p" if items == 0 else "")
+ out.append("<p>" if items == 0 else "")
+ elif tag == "</div>":
+ out.append("</p>" if stack.pop() else "")
+ else:
+ out.append(tag)
+ return "".join(out)
+
+
+def main():
+ if len(sys.argv) != 3:
+ sys.exit("usage: spec-md.py spec.html out.md")
+ src, dst = sys.argv[1:]
+ try:
+ with open(src, encoding="utf-8") as fp:
+ page = fp.read()
+ except OSError as e:
+ sys.exit(f"spec-md.py: {e}")
+
+ body = page.split("<body", 1)[1].split(">", 1)[1].split("</body>", 1)[0]
+ heads = re.findall(r'<h[1-6](?: id="([^"]*)")?>', body)
+
+ # Math goes through pandoc untouched, so it is parked on placeholders.
+ maths = []
+
+ def park(match):
+ maths.append(match.group(0))
+ return f"MATH-{len(maths) - 1}"
+
+ body = re.sub(r"<math[^>]*>.*?</math>", park, body, flags=re.S)
+ body = re.sub(
+ r'<span style="display: inline-block">(.*?)</span>', r"<code>\1</code>", body
+ )
+ for _ in range(2): # underlined links nest one inside the other
+ body = re.sub(
+ r'<span style="text-decoration: underline">(.*?)</span>', r"\1", body
+ )
+ body = re.sub(r'<span class="prefix">(.*?)</span>', r"\1", body)
+ body = tables(body)
+ # A code block without a class is written as an indented block; the page
+ # fences them, so they survive a table or a list around them.
+ body = body.replace("<pre><code>", '<pre><code class="text">')
+
+ text = subprocess.run(
+ ["pandoc", "-f", "html", "-t", "gfm", "--wrap=none"],
+ input=blocks(body),
+ capture_output=True,
+ text=True,
+ check=True,
+ ).stdout
+
+ # pandoc's gfm writer drops heading ids; the spec links to them. A
+ # heading written as text would shift every id after it, so count first.
+ lines = text.splitlines()
+ numbered = [i for i, line in enumerate(lines) if re.match(r"#{1,6} ", line)]
+ if len(numbered) != len(heads):
+ sys.exit(f"spec-md.py: {len(numbered)} headings, {len(heads)} ids")
+ for i, anchor in zip(numbered, heads, strict=True):
+ if anchor:
+ lines[i] = f"{lines[i]} {{#{anchor}}}"
+
+ text = "\n".join(lines)
+ for i in reversed(range(len(maths))):
+ text = text.replace(f"MATH-{i}", maths[i])
+
+ try:
+ with open(dst, "w", encoding="utf-8") as fp:
+ fp.write(FRONT + "\n" + re.sub(r"\n{3,}", "\n\n", text).strip() + "\n")
+ except OSError as e:
+ sys.exit(f"spec-md.py: {e}")
+
+
+if __name__ == "__main__":
+ main()