docSummary

tcmts.cli.pages.docSummary · #sqag2jv6 · term · runs anywhere

A definition's doc, first paragraph only, as plain text (for overviews and search results).

import type { DefRecord } from "#codebase/tcmts/core/types";

export function docSummary(rec: DefRecord): string | undefined {
  const first = rec.doc?.split(/\n\s*\n/)[0]?.replace(/\{@\w+\s+([^}|\s]+)(?:\s*\|\s*([^}]*)|\s+([^}]*))?\}/g, (_m, name, a, b) => (a ?? b ?? name).trim());
  return first?.replace(/\s+/g, " ").trim() || undefined;
}

uses

used by