Sort pages by their number, drop repeated photos, mark uncertain words

The model now wraps words it isn't sure of in {word} or {word|other}; the
reader shows the first reading. Pages are ordered by the number on each
photo and a page photographed twice is kept once (fewer uncertain words,
then more text). meta.photos records which photo goes with which page.
New POST /images/:n/transcribe re-reads a single photo for the editor.
Seeded plays get an img/ folder on their first photo.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HA82gVRDXpoukzgMFumoJt
This commit is contained in:
agent 2026-11-04 16:15:27 +00:00
parent 3f2cf95f1d
commit ab842a1d73
8 changed files with 187 additions and 43 deletions

View file

@ -1,4 +1,4 @@
// Parser for the play markup in public/plays/*.txt (format documented in AGENTS.md).
// Parser for the play markup (format documented in AGENTS.md).
//
// Result: [{ num, missing, blocks }] where a block is one of
// { type: "speech", speaker, cont, parts } cont = continues from the previous page
@ -8,7 +8,12 @@
// { type: "gap" } explicit blank line
// and a part is { kind: "text" | "stage" | "verse", lines: [string] }.
export function parsePlay(source) {
// Uncertain readings: "{word}" or "{word|other reading}" (the first one is used).
export const UNCERTAIN = /\{([^{}\n]*)\}/g;
export const plainText = (s) => s.replace(/\{([^{}|\n]*)(?:\|[^{}\n]*)?\}/g, "$1").replace(/ ?\[\?\]/g, "");
// plain: drop the uncertainty marks (for reading); the editor keeps them.
export function parsePlay(source, { plain = false } = {}) {
const pages = [];
let page = null;
let block = null; // block currently receiving lines
@ -23,7 +28,8 @@ export function parsePlay(source) {
else parts.push({ kind, lines: [line] });
};
for (const raw of source.replace(/\r/g, "").split("\n")) {
for (let raw of source.replace(/\r/g, "").split("\n")) {
if (plain) raw = plainText(raw);
if (raw.trim() === "") continue;
if (raw.startsWith("=") || raw.startsWith("!")) {
@ -112,7 +118,7 @@ export function lint(pages) {
const out = [];
const seen = new Set();
for (const p of pages) {
if (p.num === "?") out.push({ page: p.num, message: "Text před první značkou strany (=číslo)." });
if (p.num === "?" || p.num === "") out.push({ page: p.num, message: "Strana nemá číslo." });
if (seen.has(p.num)) out.push({ page: p.num, message: `Strana ${p.num} je v textu dvakrát.` });
seen.add(p.num);
for (const b of p.blocks) {
@ -120,7 +126,7 @@ export function lint(pages) {
if (!b.parts) continue;
for (const part of b.parts)
for (const line of part.lines)
if (line.includes("[?]")) out.push({ page: p.num, message: `Nejisté čtení: „${line.trim()}“` });
if (/[{}]/.test(line.replace(UNCERTAIN, ""))) out.push({ page: p.num, message: `Neuzavřená složená závorka: „${line.trim()}“` });
}
}
return out;