MCPcopy
hub / github.com/dvanoni/notero / buildRichText

Function buildRichText

src/content/sync/notion-utils/build-rich-text.ts:5–25  ·  view source on GitHub ↗
(
  textContent: string | null | undefined,
  { annotations, link, preserveWhitespace }: RichTextOptions = {},
)

Source from the content-addressed store, hash-verified

3import type { RichText, RichTextOptions, RichTextText } from '../notion-types';
4
5export function buildRichText(
6 textContent: string | null | undefined,
7 { annotations, link, preserveWhitespace }: RichTextOptions = {},
8): RichText {
9 if (!textContent?.length) return [];
10
11 const text = preserveWhitespace
12 ? textContent
13 : collapseWhitespace(textContent);
14
15 const hasAnnotations = Boolean(
16 annotations && Object.keys(annotations).length,
17 );
18
19 return chunkString(text, LIMITS.TEXT_CONTENT_CHARACTERS).map((content) => {
20 const richText: RichTextText = { text: { content } };
21 if (hasAnnotations) richText.annotations = annotations;
22 if (link) richText.text.link = link;
23 return richText;
24 });
25}
26
27function collapseWhitespace(text: string): string {
28 return text.replace(/[\s\n]+/g, ' ');

Callers 3

buildPropertiesMethod · 0.90
PropertyBuilderClass · 0.90
convertRichTextNodeFunction · 0.90

Calls 2

chunkStringFunction · 0.90
collapseWhitespaceFunction · 0.85

Tested by

no test coverage detected