From daca88d9ec3fb681188993378ce3eeb5c1105083 Mon Sep 17 00:00:00 2001
From: Patrick Kollitsch <83281+davidsneighbour@users.noreply.github.com>
Date: Sat, 21 Nov 2026 04:26:55 +0000
Subject: [PATCH] feat(styles): add hyphenation utility for post content (#1128)
---
assets/ananke/css/_styles.css | 20 ++++++++++++++++++++
tests/e2e/hyphenation.spec.ts | 30 ++++++++++++++++++++++++++++++
DESIGN.md | 2 +-
layouts/page/single.html | 2 +-
layouts/single.html | 2 +-
5 files changed, 53 insertions(+), 3 deletions(-)
diff --git a/DESIGN.md b/DESIGN.md
index af59124..0bf5e35 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -275,7 +275,7 @@
Tachyons typography utilities define the scale and families. Ananke's defaults layer these choices on top:
* **Body shell:** `avenir` with `bg-near-white` on the `<body>`.
-* **Article body:** `serif f4 lh-copy nested-links`, overridable with `post_content_classes`.
+* **Article body:** `serif f4 lh-copy nested-links`, overridable with `post_content_classes`. Single-page content also has `hyphenate`, Ananke's own hyphenation utility in `_styles.css` (Tachyons has none); sites redefine the class in custom CSS to change or disable it.
* **Headlines:** `athelas` for article and summary headings; site hero headings use lightweight sans-serif (`fw2`).
* **Navigation:** lightweight sans-serif with responsive sizes (`f5 f4-ns` for menu items and `f3 fw2` for the site title/logo text).
* **Metadata:** `helvetica tracked ttu` and small text sizes for section labels, dates, reading time, and word count.
diff --git a/assets/ananke/css/_styles.css b/assets/ananke/css/_styles.css
index b438297..d270a0a 100644
--- a/assets/ananke/css/_styles.css
+++ b/assets/ananke/css/_styles.css
@@ -26,6 +26,26 @@
}
/* ------------------------------------------------------------------ *
+ * Hyphenation utility (Tachyons has none)
+ *
+ * Browsers hyphenate only text in a language they have a dictionary
+ * for; baseof.html sets `lang` from the site locale. Words need six
+ * letters, with three on each side of the break. Headings and code
+ * keep their words whole. Sites change or disable this by redefining
+ * `.hyphenate` in ananke.custom_css, for example
+ * `.hyphenate { hyphens: manual; }`.
+ * ------------------------------------------------------------------ */
+
+.hyphenate {
+ hyphens: auto;
+ hyphenate-limit-chars: 6 3 3;
+}
+
+.hyphenate :where(h1, h2, h3, h4, h5, h6, code, kbd, samp) {
+ hyphens: manual;
+}
+
+/* ------------------------------------------------------------------ *
* Header navigation (see layouts/_partials/site-navigation.html)
*
* Colours, type, and spacing come from Tachyons classes in the template;
diff --git a/layouts/page/single.html b/layouts/page/single.html
index 2e7900c..b8bf7f9 100644
--- a/layouts/page/single.html
+++ b/layouts/page/single.html
@@ -16,7 +16,7 @@
{{ .Title }}
</h1>
</header>
- <div class="nested-copy-line-height lh-copy f4 nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }}">
+ <div class="nested-copy-line-height lh-copy hyphenate f4 nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }}">
{{- partials.Include "hook.html" (dict "hook" "content-before" "context" .) -}}
{{ .Content }}
{{- partials.Include "hook.html" (dict "hook" "content-after" "context" .) -}}
diff --git a/layouts/single.html b/layouts/single.html
index 4d170e6..1be77b7 100644
--- a/layouts/single.html
+++ b/layouts/single.html
@@ -60,7 +60,7 @@
<span class="f6 mv4 dib tracked"> - {{ lang.Translate "wordCount" .WordCount }} </span>
{{ end }}
</header>
- <div class="nested-copy-line-height lh-copy {{ $.Param "post_content_classes" | compare.Default "serif"}} f4 nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }} {{ compare.Conditional (compare.Eq $.Site.Language.Direction "rtl") "pl4-l" "pr4-l" }} {{ if $needs_aside }}w-two-thirds-l{{ else }}w-100-l{{ end }}">
+ <div class="nested-copy-line-height lh-copy hyphenate {{ $.Param "post_content_classes" | compare.Default "serif"}} f4 nested-links {{ $.Param "text_color" | compare.Default "mid-gray" }} {{ compare.Conditional (compare.Eq $.Site.Language.Direction "rtl") "pl4-l" "pr4-l" }} {{ if $needs_aside }}w-two-thirds-l{{ else }}w-100-l{{ end }}">
{{- partials.Include "hook.html" (dict "hook" "content-before" "context" .) -}}
{{- .Content -}}
{{- partials.Include "hook.html" (dict "hook" "content-after" "context" .) -}}
diff --git a/tests/e2e/hyphenation.spec.ts b/tests/e2e/hyphenation.spec.ts
new file mode 100644
index 0000000..494a29c
--- /dev/null
+++ b/tests/e2e/hyphenation.spec.ts
@@ -0,0 +1,30 @@
+import { expect, test } from "@playwright/test";
+
+const POST = "/posts/hello/";
+
+const hyphens = (selector: string) => (page: import("@playwright/test").Page) =>
+ page
+ .locator(selector)
+ .first()
+ .evaluate((element) => getComputedStyle(element).hyphens);
+
+test.describe("hyphenation utility", () => {
+ test("hyphenates post paragraphs in the page language", async ({ page }) => {
+ await page.goto(POST);
+ await expect(page.locator("html")).toHaveAttribute("lang", /.+/);
+ await expect(page.locator("article .hyphenate")).toHaveCount(1);
+ expect(await hyphens("article .hyphenate p")(page)).toBe("auto");
+ });
+
+ test("keeps code words whole", async ({ page }) => {
+ await page.goto(POST);
+ expect(await hyphens("article .hyphenate p code")(page)).toBe("manual");
+ expect(await hyphens("article .hyphenate pre")(page)).toBe("none");
+ });
+
+ test("site CSS can redefine the class", async ({ page }) => {
+ await page.goto(POST);
+ await page.addStyleTag({ content: ".hyphenate { hyphens: manual; }" });
+ expect(await hyphens("article .hyphenate p")(page)).toBe("manual");
+ });
+});
--
Gitblit v1.10.0