MCPcopy
hub / github.com/NotionX/react-notion-x / Text

Function Text

packages/react-notion-x/src/components/text.tsx:25–285  ·  view source on GitHub ↗
({
  value,
  block,
  linkProps,
  linkProtocol
}: {
  value?: Decoration[]
  block: Block
  linkProps?: any
  linkProtocol?: string
  inline?: boolean // TODO: currently unused
})

Source from the content-addressed store, hash-verified

23 */
24
25export function Text({
26 value,
27 block,
28 linkProps,
29 linkProtocol
30}: {
31 value?: Decoration[]
32 block: Block
33 linkProps?: any
34 linkProtocol?: string
35 inline?: boolean // TODO: currently unused
36}) {
37 const { components, recordMap, mapPageUrl, mapImageUrl, rootDomain } =
38 useNotionContext()
39
40 return (
41 <React.Fragment>
42 {value?.map(([text, decorations], index) => {
43 // TODO: sometimes notion shows a max of N items to prevent overflow
44 // if (trim && index > 18) {
45 // return null
46 // }
47
48 if (!decorations) {
49 if (text === ',') {
50 return <span key={index} style={{ padding: '0.5em' }} />
51 } else {
52 return <React.Fragment key={index}>{text}</React.Fragment>
53 }
54 }
55
56 const formatted = decorations.reduce(
57 (element: React.ReactNode, decorator) => {
58 switch (decorator[0]) {
59 case 'p': {
60 // link to an internal block (within the current workspace)
61 const blockId = decorator[1]
62 const linkedBlock = getBlockValue(recordMap.block[blockId])
63 if (!linkedBlock) {
64 console.log('"p" missing block', blockId)
65 return null
66 }
67
68 // console.log('p', blockId)
69
70 return (
71 <components.PageLink
72 className='notion-link'
73 href={mapPageUrl(blockId)}
74 >
75 <PageTitle block={linkedBlock} />
76 </components.PageLink>
77 )
78 }
79
80 case '‣': {
81 // link to an external block (outside of the current workspace)
82 const linkType = decorator[1][0]

Callers

nothing calls this directly

Calls 5

useNotionContextFunction · 0.90
getBlockValueFunction · 0.90
parsePageIdFunction · 0.90
getHashFragmentValueFunction · 0.90
formatDateFunction · 0.90

Tested by

no test coverage detected