Neuer Inline-Atom mention {userId, username}: Markdown-Regel @username
(E-Mail-sicher über Wortgrenzen), Serializer, HTML-Span dt-mention,
Plain-Text für die Suche, Extraktor extractMentionUserIds. Neue
Endpoints GET /users/search (auth, min. 2 Zeichen, Limit 10,
Rate-Limit) und GET /users/brief (Batch-Auflösung für live
Anzeigenamen; gelöschte Nutzer → toter Chip). Editor: MentionView mit
Live-displayName, MentionAutocomplete (Klon des Wikilink-Musters),
Chip-CSS. 5 Unit-Tests.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0155v2aT8AG1kZDQEZiCLBWC
18 lines
833 B
TypeScript
18 lines
833 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}`;
|
|
return '';
|
|
});
|
|
return text.replace(/\n{3,}/g, '\n\n').trim();
|
|
}
|