Static app (no build step) served by unprivileged nginx in a container: choose a font, size and theme, pick a character to highlight their lines and step through them, read in a distraction-free mode, or export a PDF via the print dialog (one page per original page). Includes the transcription of typescript pages 5-27 (pages 1-4 and 7 are missing in the original), a parser with node:test tests, and self-hosted OFL fonts. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
43 lines
2 KiB
JavaScript
43 lines
2 KiB
JavaScript
// Run: node --test tests/ (or see AGENTS.md for the container one-liner)
|
||
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import { readFileSync } from "node:fs";
|
||
import { parsePlay, speakers, joinLines, tidySpacing } from "../public/parse.js";
|
||
|
||
const play = parsePlay(readFileSync(new URL("../public/plays/hra.txt", import.meta.url), "utf8"));
|
||
|
||
test("pages are in order and missing ones are marked", () => {
|
||
const nums = play.map((p) => p.num);
|
||
assert.deepEqual(nums.slice(0, 4), ["1-4", "5", "6", "7"]);
|
||
assert.deepEqual(play.filter((p) => p.missing).map((p) => p.num), ["1-4", "7"]);
|
||
assert.equal(nums.at(-1), "27");
|
||
});
|
||
|
||
test("text at the top of a page continues the previous speaker", () => {
|
||
const p15 = play.find((p) => p.num === "15");
|
||
assert.equal(p15.blocks[0].speaker, "Lysák");
|
||
assert.equal(p15.blocks[0].cont, true);
|
||
});
|
||
|
||
test("cast is found and counted", () => {
|
||
const names = speakers(play).map((s) => s.name);
|
||
for (const n of ["Mise", "Lída", "Lysák", "Továrník", "Švec", "Paní bába", "Lysáková"]) assert.ok(names.includes(n), n);
|
||
assert.ok(!names.includes(""));
|
||
});
|
||
|
||
test("verse stays separate from the stage direction before it", () => {
|
||
const p19 = play.find((p) => p.num === "19");
|
||
const julius = p19.blocks.find((b) => b.speaker === "Julius" && b.parts.some((x) => x.kind === "verse"));
|
||
assert.deepEqual(julius.parts.map((x) => x.kind), ["stage", "verse"]);
|
||
});
|
||
|
||
test("hyphenated line breaks are rejoined, dashes are kept", () => {
|
||
assert.equal(joinLines(["Mám vždycky velmi nepří-", "jemné poslání."]), "Mám vždycky velmi nepříjemné poslání.");
|
||
assert.equal(joinLines(["takovém houfci ne -", "spokojenců"]), "takovém houfci nespokojenců");
|
||
assert.equal(joinLines(["Jsem jen tak –", "nalehko."]), "Jsem jen tak – nalehko.");
|
||
});
|
||
|
||
test("spacing is tidied without touching numbers", () => {
|
||
assert.equal(tidySpacing("Ano, roky.Nyní je rok 1931.Jaké ?"), "Ano, roky. Nyní je rok 1931. Jaké?");
|
||
assert.equal(tidySpacing("nadějí .Jsem směšný"), "nadějí. Jsem směšný");
|
||
});
|