opensheaf-literate

Weaving: from the documents to the website

The documents are Markdown and read well on GitHub, but a literate program is best read with its chunks linked to one another: each fragment says where its chunk is used and where it continues, each reference is a link to the chunk it names. The weaver, src/literate/weave.py, makes such a website out of the documents, one page per document, with an index of the chunks. It reads the documents with the same code as the tangler, so that the two never disagree about what is program and what is prose, and leaves the prose to Python-Markdown and the colours of the code to Pygments. These two packages are needed only to weave, not to tangle: they are the extra weave of the package (pip install "opensheaf-literate[weave]"), and the command line imports this module only when it weaves.

"""Weaving: a website out of the literate documents."""
import html
import re
import shutil
from pathlib import Path

import markdown
from pygments import highlight
from pygments.formatters import HtmlFormatter
from pygments.lexers import BashLexer, TextLexer, get_lexer_for_filename
from pygments.util import ClassNotFound

from .tangle import FILE, REFERENCE, Error, blocks

HERE = Path(__file__).resolve().parent


⟨pages, titles and anchors⟩


⟨the web of chunks⟩


⟨the frame of the pages⟩


⟨weaving a website⟩

What the website says about the project (its name, a line about it, its repository, its logo) comes from the project's configuration, described with the command line.

Pages, titles and anchors

Each document becomes a page of the same name (index.md becomes the front page, index.html). Its title is its first heading, written either way Markdown allows. Every fragment gets an anchor made of the name of its chunk and its number among the fragments of that chunk.

def page_of(doc):
    return doc.stem + ".html"


def title_of(doc):
    lines = doc.read_text(encoding="utf-8").split("\n")
    for i, line in enumerate(lines):
        if line.startswith("# "):
            return line[2:].strip()
        if line.strip() and i + 1 < len(lines) and re.match(r"^=+\s*$", lines[i + 1]):
            return line.strip()
    return doc.stem


def slug(name):
    return re.sub(r"[^a-z0-9]+", "-", name.lower()).strip("-")


def esc(text):
    return html.escape(text, quote=True)

The web of chunks

The weaver needs more than the tangler: not only the fragments of each chunk, but also, for each chunk, the fragments that refer to it, and the file it ends up in, which decides how its code is coloured. Links to the files in the repository need its address and the branch they point to.

class Web:
    """The documents, their code blocks, and how the chunks refer to one another."""

    def __init__(self, docs, repository="", branch="main"):
        self.docs, self.repository, self.branch = docs, repository, branch
        self.blocks = {doc: blocks(doc) for doc in docs}
        self.fragments = {}
        for doc in docs:
            for block in self.blocks[doc]:
                self.fragments.setdefault(block.name, []).append(block)
        ⟨number the fragments and find their users⟩
        ⟨find the file of every chunk⟩

    ⟨links to fragments and chunks⟩

    ⟨rendering a code block⟩

    ⟨rendering a document⟩

    ⟨the index of chunks⟩

Blocks are dataclasses, which compare by value; we index them by their place, the document and first line, which is unique.

self.anchor, self.number = {}, {}
for name, fragments in self.fragments.items():
    for k, block in enumerate(fragments):
        self.anchor[block.doc, block.start] = f"{slug(name)}-{k + 1}"
        self.number[block.doc, block.start] = k
self.users = {}
for fragments in self.fragments.values():
    for block in fragments:
        for line in block.lines:
            ref = REFERENCE.match(line)
            if ref:
                users = self.users.setdefault(ref.group(2), [])
                if block.name not in [b.name for b in users]:
                    users.append(block)

A chunk is coloured as the file it is part of: we go down from every file through the references, and each chunk keeps the first file that reaches it.

self.file = {}
for name in self.fragments:
    if FILE.match(name):
        todo = [name]
        while todo:
            chunk = todo.pop()
            if chunk in self.file or chunk not in self.fragments:
                continue
            self.file[chunk] = name
            todo.extend(ref.group(2) for block in self.fragments[chunk]
                        for line in block.lines for ref in [REFERENCE.match(line)] if ref)

A link to a fragment is an anchor on the same page or on another; a link to a chunk goes to its first fragment, and a reference to a chunk that is not defined is shown, in red, rather than lost. Pygments chooses the colours by the name of the file; a file without a suffix is a script, for the shell more often than not.

Rendering a code block

The code is coloured by Pygments, which knows nothing of references: we replace each reference by a word that is an identifier in every language, colour, and replace the word, with whatever span Pygments put around it, by a link to the chunk.

def code_html(self, block, here):
    lines, refs = [], []
    for line in block.lines:
        ref = REFERENCE.match(line)
        if ref:
            lines.append(f"{ref.group(1)}CHUNKREF{len(refs)}X")
            refs.append(ref.group(2))
        else:
            lines.append(line)
    code = highlight("\n".join(lines) + "\n", self.lexer(block.name), HtmlFormatter(nowrap=True))
    for k, name in enumerate(refs):
        link = self.chunk_link(name, here)
        code = re.sub(rf'<span class="[^"]*">CHUNKREF{k}X</span>|CHUNKREF{k}X', lambda m: link, code)
    return code

Above the code stands the name of the chunk, followed by ≡ for its first fragment and +≡ for the others, as in Norman Ramsey's noweb; below it, where the chunk is used, where it went on before and goes on after, and, for a file, when the project says where its repository is, a link to the file there.

def block_html(self, block, here):
    name, fragments = block.name, self.fragments[block.name]
    k, anchor = self.number[block.doc, block.start], self.anchor[block.doc, block.start]
    title = f"<code>{esc(name)}</code>" if FILE.match(name) else f"⟨{esc(name)}⟩"
    notes = []
    if k > 0:
        notes.append(f'continues <a href="{self.href(fragments[k - 1], here)}">the fragment before</a>')
    if k + 1 < len(fragments):
        notes.append(f'continued <a href="{self.href(fragments[k + 1], here)}">further on</a>')
    users = self.users.get(name, [])
    if users:
        notes.append("used in " + ", ".join(
            f'<a href="{self.href(b, here)}">⟨{esc(b.name)}⟩</a>' for b in users))
    if FILE.match(name) and k == 0 and self.repository:
        notes.append(f'<a href="{esc(self.repository)}/blob/{esc(self.branch)}/{esc(name)}">'
                     "the file in the repository</a>")
    return (f'<div class="chunk" id="{anchor}">'
            f'<div class="chunk-name"><a href="#{anchor}">{title}</a> {"+≡" if k else "≡"}</div>'
            f'<pre class="code">{self.code_html(block, here)}</pre>'
            + (f'<div class="chunk-notes">{"; ".join(notes)}.</div>' if notes else "")
            + "</div>")

Rendering a document

The code blocks are taken out of the document and replaced by placeholders, each a paragraph of its own; Markdown renders the rest; the placeholders are then replaced by the rendered blocks. Links between documents ([tangling](10-tangle.md)) are made links between pages, and GitHub's alerts (> [!WARNING]) boxes.

def document_html(self, doc):
    lines = doc.read_text(encoding="utf-8").split("\n")
    parts, last = [], 0
    for k, block in enumerate(self.blocks[doc]):
        parts += lines[last:block.start] + ["", f"CHUNKBLOCK{k}X", ""]
        last = block.end
    parts += lines[last:]
    body = markdown.markdown("\n".join(parts), extensions=["tables", "fenced_code", "codehilite", "toc"],
                             extension_configs={"codehilite": {"guess_lang": False, "css_class": "code"}})
    for k, block in enumerate(self.blocks[doc]):
        body = body.replace(f"<p>CHUNKBLOCK{k}X</p>", self.block_html(block, doc))
    body = re.sub(r'href="([\w.-]+)\.md(#[^"]*)?"',
                  lambda m: f'href="{m.group(1)}.html{m.group(2) or ""}"', body)
    return re.sub(r"<blockquote>\s*<p>\[!(WARNING|NOTE|IMPORTANT|TIP|CAUTION)\]\s*",
                  lambda m: f'<blockquote class="alert {m.group(1).lower()}"><p>', body)

The index of chunks

The last page lists the files, each with the document that makes it, and every chunk in alphabetical order, with its fragments and its users.

def index_html(self):
    here = Path("chunks.md")
    files = [n for n in self.fragments if FILE.match(n)]
    rows = "".join(
        f'<tr><td><a href="{self.href(self.fragments[n][0], here)}"><code>{esc(n)}</code></a></td>'
        f'<td>{esc(title_of(self.fragments[n][0].doc))}</td></tr>' for n in files)
    items = []
    for name in sorted((n for n in self.fragments if not FILE.match(n)), key=str.lower):
        fragments = ", ".join(f'<a href="{self.href(b, here)}">{k + 1}</a>'
                              for k, b in enumerate(self.fragments[name]))
        users = ", ".join(f'<a href="{self.href(b, here)}">⟨{esc(b.name)}⟩</a>'
                          for b in self.users.get(name, []))
        items.append(f"<li>{self.chunk_link(name, here)}: {fragments}"
                     + (f"; used in {users}" if users else "") + "</li>")
    return ("<h1>Files and chunks</h1><h2>Files</h2>"
            f"<table><tr><td>File</td><td>Made in</td></tr>{rows}</table>"
            f'<h2>Chunks</h2><ul class="chunks">{"".join(items)}</ul>')

The frame of the pages

Every page has the same frame, a template with placeholders in double braces: a header with the name of the project and a line about it, the list of chapters at the side, and links to the chapters before and after at the end. A placeholder the weaver does not know is an error, so that a misspelt one in a project's own template is not left on its pages.

def fill(template, **values):
    def value(m):
        if m.group(1) not in values:
            raise Error(f"the template uses {{{{{m.group(1)}}}}}, which the weaver does not fill")
        return values[m.group(1)]
    return re.sub(r"\{\{(\w+)\}\}", value, template)

A project may have a logo. It stands on the left of the name in the header of every page, as tall as the letters, and above the title of the front page. A logo drawn in black on a transparent background disappears on a dark background: the project can give a second image for dark backgrounds, or ask for the logo to be inverted there ("invert"), which is right for a mark in one colour.

def logo_html(config):
    if not config.logo:
        return ""
    invert = " invert" if config.logoDark == "invert" else ""
    img = f'<img class="logo{invert}" src="{esc(Path(config.logo).name)}" alt="">'
    if config.logoDark and config.logoDark != "invert":
        return (f'<picture><source srcset="{esc(Path(config.logoDark).name)}" '
                f'media="(prefers-color-scheme: dark)">{img}</picture>')
    return img

On the right of the header stand links: those the project adds, the index of chunks, and the source in the repository. The index of chunks is marked as the page being read when it is.

def header_links(config, page):
    links = [f'<a href="{esc(href)}">{esc(text)}</a>' for text, href in config.links.items()]
    current = ' aria-current="page"' if page == "chunks.html" else ""
    links.append(f'<a href="chunks.html"{current}>chunks</a>')
    if config.repository:
        links.append(f'<a href="{esc(config.repository)}">source</a>')
    return " ".join(links)

The pages are then written one by one. The name of the project is text; the line about it (tagline) is HTML, so that it may hold a link.

def write_pages(web, out, template, config):
    pages = [(page_of(d), title_of(d)) for d in web.docs] + [("chunks.html", "Files and chunks")]
    logo = logo_html(config)
    for k, (page, title) in enumerate(pages):
        body = web.index_html() if page == "chunks.html" else web.document_html(web.docs[k])
        if page == "index.html" and logo:
            body = re.sub(r"(<h1[^>]*>)", lambda m: m.group(1) + logo, body, count=1)
        nav = "".join(f'<li{" class=current" if p == page else ""}><a href="{p}">{esc(t)}</a></li>'
                      for p, t in pages)
        turn = ""
        if k > 0:
            turn += f'<a class="prev" href="{pages[k - 1][0]}">← {esc(pages[k - 1][1])}</a>'
        if k + 1 < len(pages):
            turn += f'<a class="next" href="{pages[k + 1][0]}">{esc(pages[k + 1][1])} →</a>'
        (out / page).write_text(
            fill(template, title=esc(title), name=esc(config.name), tagline=config.tagline,
                 logo=logo, links=header_links(config, page), repository=esc(config.repository),
                 nav=f"<ol>{nav}</ol>", body=body, turn=turn),
            encoding="utf-8")
    return len(pages)

Weaving a website

The weaver writes the pages, the stylesheet and the images of the logo into a folder, site/ unless the project or the command line says otherwise; the folder is not meant to be kept in the repository. The template and the stylesheet are those below, which are installed with the package, unless the project gives its own (template, stylesheet in its configuration): a project's template must use only the placeholders above, and its stylesheet replaces ours entirely, so it is best started from a copy of ours.

def weave(config, docs, out, branch=None):
    """Weave the documents into a website in folder `out`; return the number of pages."""
    if not docs:
        raise Error("no documents to weave")
    web = Web(docs, config.repository, branch or config.branch)
    out = Path(out)
    out.mkdir(parents=True, exist_ok=True)
    template = Path(config.template or HERE / "weave.html").read_text(encoding="utf-8")
    pages = write_pages(web, out, template, config)
    ⟨write the stylesheet⟩
    for image in (config.logo, config.logoDark):
        if image and image != "invert":
            shutil.copyfile(image, out / Path(image).name)
    return pages

The stylesheet is copied as it is. Pygments marks the tokens of the code with classes, but its colours are not used: the stylesheet gives the few tokens it distinguishes their weight and tone itself.

shutil.copyfile(config.stylesheet or HERE / "weave.css", out / "style.css")

The template and the stylesheet

The template is installed next to the module, as data of the package. The masthead holds the logo and the name on the left and the links on the right; the line about the project closes every page, under the links to the chapters before and after.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>{{title}} · {{name}}</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header class="site">
  <a class="home" href="index.html">{{logo}}{{name}}</a>
  <nav class="links">{{links}}</nav>
</header>
<div class="layout">
<nav class="chapters">{{nav}}</nav>
<main>
{{body}}
<nav class="turn">{{turn}}</nav>
<footer class="colophon">{{name}}: <span>{{tagline}}</span></footer>
</main>
</div>
</body>
</html>

The stylesheet makes the woven pages a small book of their own, not the pages of any other site: a sheet of warm paper with black ink, one column of prose, and hierarchy from size, space and italics rather than from weight. A woven program is read with a lot of code between its paragraphs, and its faces are chosen for that: the prose and the titles in Libertinus Serif, a sturdy book face in the line of Linux Libertine, at 19.5px with a close leading of 1.35 in a column of 38rem; the code in JetBrains Mono; the apparatus around the text in Geist, a plain sans. The three come from Google Fonts; a page opened without a network falls back on the faces of the system. The import comes first, since a stylesheet allows it nowhere else.

@import url("https://fonts.googleapis.com/css2?family=Libertinus+Serif:ital,wght@0,400;0,600;1,400;1,600&family=JetBrains+Mono:wght@400;600&family=Geist:wght@400;600&display=swap");

The faces and the colours are custom properties, set once and again for a dark background (following the system) and for print. Besides the paper, the ink and their greys, there are two tones for warnings and errors, and five for the code: keywords, names being defined, built-in names, strings, and numbers and constants; comments are in the grey of the secondary text. Each colour is at least 4.5:1 on the tint of the code.

:root {
  color-scheme: light;
  --serif: "Libertinus Serif", "Linux Libertine O", "Linux Libertine", Georgia, serif;
  --sans: Geist, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --paper: #f9f8f5; --surface: #f1efea; --rule: #dedbd3; --ink: #171716;
  --muted: #6a6861; --faint: #a09d95; --bad: #9d2b22; --warn: #7d5200;
  --hl-keyword: #a3331f; --hl-name: #1e5aa0; --hl-builtin: #6f3f9e;
  --hl-string: #3b6b2e; --hl-number: #8a5a00;
}
@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --paper: #12141a; --surface: #1b1e25; --rule: #31353e; --ink: #e6e7ea;
    --muted: #9a9ea8; --faint: #646975; --bad: #eda59c; --warn: #e7c277;
    --hl-keyword: #f0907a; --hl-name: #8cb8ee; --hl-builtin: #c6a1ec;
    --hl-string: #9ccc87; --hl-number: #e0b25c;
  }
}
@media print {
  :root {
    color-scheme: light;
    --paper: #fff; --surface: #fff; --rule: #999; --ink: #000; --muted: #333; --faint: #666;
    --bad: #000; --warn: #000; --hl-keyword: #000; --hl-name: #000; --hl-builtin: #000;
    --hl-string: #333; --hl-number: #000;
  }
}
continues the fragment before; continued further on.

The page has a masthead above a column of text, with the list of chapters at its side on a wide window and above it on a narrow one. The apparatus around the text (the links of the masthead, the chapters, the notes under the code, the links to the next chapter) is in a small Geist, in grey, the page being read in ink; navigation is not underlined. Links in the text are in ink, with a thin grey underline that turns to ink under the pointer. The title of a page is centred, like the title of a paper, with the logo above it on the front page; headings are in the regular weight, subsections in italics.

* { box-sizing: border-box; }
html { font-size: 19.5px; }
body { margin: 0; background: var(--paper); color: var(--ink);
  font-family: var(--serif); font-size: 1rem; line-height: 1.35;
  font-kerning: normal; font-variant-numeric: lining-nums;
  text-rendering: optimizeLegibility; -webkit-font-smoothing: antialiased; }
@media (max-width: 40rem) { html { font-size: 18px; } }
:focus-visible { outline: 1.5px solid var(--ink); outline-offset: 3px; }
::selection { background: var(--surface); }
a:link, a:visited { color: inherit; text-decoration: underline; text-decoration-thickness: 1px;
  text-underline-offset: 0.2em; text-decoration-color: var(--faint); }
a:hover, a:focus { text-decoration-color: currentColor; }

header.site, .layout { max-width: 58rem; margin: 0 auto; padding: 0 1.6rem; }
header.site { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.3rem 1.5rem;
  padding-top: 1.6rem; margin-bottom: 3rem; }
header.site a { text-decoration: none; }
header.site .home { font-size: 1.05rem; letter-spacing: -0.01em; }
header.site .links { margin-left: auto; display: flex; gap: 1.5rem;
  font-family: var(--sans); font-size: 0.7rem; }
header.site .links a { display: inline-block; color: var(--muted); }
header.site .links a::first-letter { text-transform: uppercase; }
header.site .links a:hover, header.site .links a[aria-current="page"] { color: var(--ink); }
img.logo { height: 1.05em; width: auto; vertical-align: -0.17em; margin-right: 0.4em; }
h1 img.logo { display: block; height: 1.3em; margin: 0 auto 0.5em; }
@media (prefers-color-scheme: dark) { img.logo.invert { filter: invert(1); } }

.layout { display: flex; gap: 3rem; }
nav.chapters { flex: 0 0 11rem; position: sticky; top: 1.5rem; align-self: flex-start;
  max-height: calc(100vh - 3rem); overflow-y: auto; padding-top: 0.6rem;
  font-family: var(--sans); font-size: 0.65rem; line-height: 1.45; }
nav.chapters ol { margin: 0; padding-left: 1.5em; }
nav.chapters li { margin: 0 0 0.7em; color: var(--muted); }
nav.chapters li::marker { color: var(--faint); }
nav.chapters a:link, nav.chapters a:visited { color: var(--muted); text-decoration: none; }
nav.chapters a:hover, nav.chapters li.current a { color: var(--ink); }
main { flex: 1; min-width: 0; max-width: 38rem; padding-bottom: 5rem; }
@media (max-width: 56rem) {
  .layout { display: block; }
  nav.chapters { position: static; max-height: none; margin-bottom: 2.5rem; }
}

h1, h2, h3, h4 { font-weight: 400; line-height: 1.2; text-wrap: balance; }
h1 { font-size: 2.4rem; line-height: 1.1; letter-spacing: -0.02em; text-align: center;
  margin: 0 0 1.2em; }
h2 { font-size: 1.5rem; letter-spacing: -0.01em; margin: 2.2em 0 0.4em; }
h3 { font-size: 1.15rem; font-style: italic; margin: 1.7em 0 0.2em; }
h4 { font-size: 1rem; font-style: italic; margin: 1.2em 0 0; }
@media (max-width: 40rem) { h1 { font-size: 2rem; } }
p { margin: 0.8em 0; }
strong, b { font-weight: 600; }
dfn { font-style: italic; }
li::marker { color: var(--faint); }
ol li::marker { color: var(--muted); }
continues the fragment before; continued further on.

The code is on a faint tint, without a frame, a little smaller than the prose, with its chunk name above it as a caption. Chunk names, above the code and in it, are in the italic of the text face, a little larger than the code, since a serif italic looks smaller than the monospaced letters around it. The code is shown as it is typed, without the ligatures of the monospaced face (-> stays two characters). The colours of the code are few and quiet, in the regular weight, so that the code reads as text: keywords, and the properties of a stylesheet, in brick red; the names a fragment defines (functions, classes, the selectors of a stylesheet, the tags of a page) in blue; built-in names, decorators, variables and the attributes of a page in violet; strings in green, with what is interpolated into them in ochre, as are numbers, units and constants; comments in grey italics. Tables are ruled as in a book, alerts (GitHub's > [!WARNING]) stand on the tint with a run-in label, a warning in amber.

code, pre { font-family: var(--mono); font-variant-numeric: normal;
  font-variant-ligatures: none; font-feature-settings: "calt" 0, "liga" 0; }
code { font-size: 0.8em; background: var(--surface); border-radius: 3px; padding: 0.1em 0.3em; }
pre code, h1 code, h2 code, h3 code, .chunk-name code { background: none; padding: 0; }
pre code { font-size: inherit; }
pre { overflow-x: auto; }
pre.code, div.code pre { margin: 0.3em 0; padding: 0.9em 1.1em; background: var(--surface);
  border-radius: 4px; font-size: 0.59rem; line-height: 1.6; }
.code :is(.k, .kd, .kn, .kr, .kp, .ow, .sa) { color: var(--hl-keyword); }
.code :is(.nf, .fm, .nc, .ne, .nt, .nn) { color: var(--hl-name); }
.code :is(.nb, .bp, .vm, .nd, .nv, .na) { color: var(--hl-builtin); }
.code :is(.s, .s1, .s2, .sb, .sc, .dl, .sd, .sh, .sx, .sr, .ss) { color: var(--hl-string); }
.code :is(.si, .se) { color: var(--hl-number); }
.code :is(.m, .mb, .mf, .mh, .mi, .mo, .il, .kc, .kt, .l, .ld) { color: var(--hl-number); }
.code :is(.c, .c1, .ch, .cm, .cp, .cpf, .cs) { color: var(--muted); font-style: italic; }
.code .err { color: inherit; border: 0; }
.code a.ref { font-family: var(--serif); font-style: italic; font-size: 1.2em; }
.undefined { color: var(--bad); font-family: var(--serif); font-style: italic; }

.chunk { margin: 1.6em 0; }
.chunk-name { font-style: italic; color: var(--muted); }
.chunk-name a:link, .chunk-name a:visited { color: var(--ink); text-decoration: none; }
.chunk-name code { font-style: normal; font-size: 0.75em; }
.chunk-notes { font-family: var(--sans); font-size: 0.65rem; line-height: 1.5;
  color: var(--muted); }
.chunk-notes a:link, .chunk-notes a:visited { color: inherit; }

table { border-collapse: collapse; margin: 1em 0; font-size: 0.9rem; line-height: 1.45; }
td { padding: 0.55em 1.2em 0.55em 0; border-bottom: 1px solid var(--rule); vertical-align: top; }
td:last-child { padding-right: 0; }
tr:first-child td { font-family: var(--sans); font-size: 0.6rem; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); vertical-align: bottom;
  border-top: 1px solid var(--ink); border-bottom: 1px solid var(--ink); }
tr:last-child td { border-bottom: 1px solid var(--ink); }

blockquote { margin: 1em 0; padding: 0 0 0 1.5em; font-style: italic; }
blockquote.alert { font-style: normal; background: var(--surface); border-radius: 4px;
  padding: 0.8em 1.1em; margin: 1.6em 0; }
blockquote.alert > p { margin: 0.4em 0; }
blockquote.alert > p:first-child::before { font-weight: 600; }
blockquote.warning > p:first-child::before { content: "Warning. "; color: var(--warn); }
blockquote.caution > p:first-child::before { content: "Caution. "; color: var(--warn); }
blockquote.important > p:first-child::before { content: "Important. "; }
blockquote.note > p:first-child::before { content: "Note. "; }
blockquote.tip > p:first-child::before { content: "Tip. "; }
ul.chunks { padding-left: 1.2em; }
ul.chunks li { margin: 0.2em 0; }

nav.turn { display: flex; justify-content: space-between; gap: 1.5em; margin-top: 4rem;
  font-family: var(--sans); font-size: 0.7rem; }
nav.turn a:link, nav.turn a:visited { color: var(--muted); text-decoration: none; }
nav.turn a:hover { color: var(--ink); }
nav.turn .next { margin-left: auto; text-align: right; }
footer.colophon { margin-top: 1.5rem; font-family: var(--sans); font-size: 0.65rem;
  color: var(--muted); }
footer.colophon a:link, footer.colophon a:visited { color: inherit; }
@media print {
  nav.chapters, nav.turn, header.site .links { display: none; }
  .layout { display: block; }
}