Phase 8b: Cloze-Render im Study-View

Study-View hat jetzt Cloze-Branch in promptMarkdown/answerMarkdown.
Aktiver Cluster wird im Prompt zu […], in der Answer fett markiert,
restliche Cluster sind expanded. Optionales `extra`-Feld wird unter
der Answer angehängt (Anki-kompatibel).

Render-Helpers (clusterIdForSubIndex, renderClozePrompt,
renderClozeAnswer) leben in @cards/domain (Phase 8a) und sind dort
12-fach getestet — die Svelte-Komponente bleibt dünn.

E2E-Smoke gegen lokale DB: Cloze-Card mit zwei Clustern
({{c1::Frankreich}} {{c2::Paris}}) erzeugt 2 Reviews (sub_index 0+1).
Type-check + svelte-check 0 errors.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Till JS 2026-05-08 17:37:53 +02:00
parent 553a78d73b
commit 0b609c46fd

View file

@ -2,7 +2,12 @@
import { onMount, onDestroy } from 'svelte';
import { page } from '$app/state';
import { goto } from '$app/navigation';
import type { Rating } from '@cards/domain';
import {
clusterIdForSubIndex,
renderClozePrompt,
renderClozeAnswer,
type Rating,
} from '@cards/domain';
import { getDeck } from '$lib/api/decks.ts';
import { listDueReviews, gradeReview, type DueReview } from '$lib/api/reviews.ts';
import { devUser } from '$lib/auth/dev-stub.svelte.ts';
@ -32,6 +37,11 @@
return fields.front ?? '';
case 'basic-reverse':
return subIndex === 0 ? (fields.front ?? '') : (fields.back ?? '');
case 'cloze': {
const text = fields.text ?? '';
const clusterId = clusterIdForSubIndex(text, subIndex);
return clusterId !== null ? renderClozePrompt(text, clusterId) : text;
}
default:
return fields.front ?? '';
}
@ -47,6 +57,13 @@
return fields.back ?? '';
case 'basic-reverse':
return subIndex === 0 ? (fields.back ?? '') : (fields.front ?? '');
case 'cloze': {
const text = fields.text ?? '';
const clusterId = clusterIdForSubIndex(text, subIndex);
const body = clusterId !== null ? renderClozeAnswer(text, clusterId) : text;
const extra = fields.extra ? `\n\n${fields.extra}` : '';
return body + extra;
}
default:
return fields.back ?? '';
}