dorfteich/packages/shared/src/editor-schema/plain-text.ts
Claude Fable 5 92a3b2f6d5 #152: Datums-Marker >> (Zieldatum) / << (Startdatum)
Neuer Inline-Atom date_marker {kind: due|start, date: ISO}. Markdown
kanonisch ISO (>>2026-12-31), Eingabe-Kulanz dd.mm.yyyy; Block-Guard
vor blockquote hält zeilenführende >>Daten aus dem Zitat-Parser;
ungültige Kalenderdaten bleiben Text. Editor: InputRule beim Tippen
(+Leerzeichen), Anzeige per Intl.DateTimeFormat in Nutzersprache,
Überfällig-Färbung. Die User.locale-Verdrahtung existierte bereits
(auth-context, #17) — keine Änderung nötig. 6 Unit-Tests inkl.
Task-Listen-Zeile mit Marker und Mention.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0155v2aT8AG1kZDQEZiCLBWC
2026-07-20 00:59:05 +02:00

20 lines
969 B
TypeScript

import { Node } from 'prosemirror-model';
/** Search/preview representation (data-model.md `page_content_cache`). */
export function docToPlainText(doc: Node): string {
const text = doc.textBetween(0, doc.content.size, '\n\n', (leaf) => {
if (leaf.type.name === 'image') return (leaf.attrs.alt as string) ?? '';
// A wikilink contributes its shown text (explicit display or the slug) so
// search and previews include what the reader sees (issue #46).
if (leaf.type.name === 'wikilink') {
return (leaf.attrs.displayText as string | null) ?? (leaf.attrs.targetSlug as string);
}
// A mention reads as `@username` (issue #150), so search finds it.
if (leaf.type.name === 'mention') return `@${leaf.attrs.username as string}`;
// A date marker contributes its ISO date (issue #152).
if (leaf.type.name === 'date_marker') return leaf.attrs.date as string;
return '';
});
return text.replace(/\n{3,}/g, '\n\n').trim();
}