feat(vorlagen): Editor, Liste und Versionsgeschichte (#24)
This commit was merged in pull request #24.
This commit is contained in:
@@ -104,6 +104,9 @@ export const AbschnittSchema = z.object({
|
||||
.default([]),
|
||||
});
|
||||
|
||||
/** Ein Abschnitt so, wie ihn ein Editor oder eine Datei liefert – vor dem Pruefen. */
|
||||
export type AbschnittEingabe = z.input<typeof AbschnittSchema>;
|
||||
|
||||
export const VariableSchema = z.object({
|
||||
/**
|
||||
* Der Schluessel steht als `{{schluessel}}` in Titeln, Hilfetexten und
|
||||
@@ -176,6 +179,28 @@ export type Austausch = z.infer<typeof AustauschSchema>;
|
||||
* soll, wenn ein Platzhalter zu keiner Variablen und zu keinem eingebauten Wert
|
||||
* gehoert. Das Ersetzen selbst kommt in #012.
|
||||
*/
|
||||
/**
|
||||
* Aus einem Zod-Pfad eine Stelle machen, die man auf dem Bildschirm wiederfindet.
|
||||
*
|
||||
* `struktur.abschnitte.2.schritte.0.titel` ist fuer den Aufbau richtig und fuer
|
||||
* den Redakteur nutzlos — er muesste von null an zaehlen und wuesste immer noch
|
||||
* nicht, ob „2“ den dritten Abschnitt meint. Daraus wird „Abschnitt 03,
|
||||
* Schritt 1: “. Der Rest der Meldung kommt unveraendert aus dem Schema.
|
||||
*/
|
||||
export function stelleBenennen(pfad: readonly PropertyKey[]): string {
|
||||
const teile: string[] = [];
|
||||
for (let i = 0; i < pfad.length; i += 1) {
|
||||
const name = String(pfad[i]);
|
||||
const index = Number(pfad[i + 1]);
|
||||
if (!Number.isInteger(index)) continue;
|
||||
if (name === "abschnitte") teile.push(`Abschnitt ${String(index + 1).padStart(2, "0")}`);
|
||||
else if (name === "schritte") teile.push(`Schritt ${index + 1}`);
|
||||
else if (name === "variablen") teile.push(`Variable ${index + 1}`);
|
||||
else if (name === "optionen") teile.push(`Option ${index + 1}`);
|
||||
}
|
||||
return teile.length > 0 ? `${teile.join(", ")}: ` : "";
|
||||
}
|
||||
|
||||
export function platzhalterFinden(text: string): readonly string[] {
|
||||
const gefunden = new Set<string>();
|
||||
for (const treffer of text.matchAll(/\{\{\s*([a-z][a-z0-9_]*)\s*\}\}/g)) {
|
||||
|
||||
Reference in New Issue
Block a user