* Returns true when a React element is a block-level media wrapper (image or * video). The `img` component in `createMarkdownComponents` marks its output * with a `data-block-media` prop so we can reliably distinguish media from * other custom components (links, mentions, etc.) that also have non
(child: React.ReactNode)
| 8 | * types in react-markdown v10. |
| 9 | */ |
| 10 | function isBlockMedia(child: React.ReactNode): boolean { |
| 11 | if (!React.isValidElement(child)) return false; |
| 12 | |
| 13 | const props = child.props as { |
| 14 | children?: React.ReactNode; |
| 15 | node?: { tagName?: unknown }; |
| 16 | [key: string]: unknown; |
| 17 | }; |
| 18 | const node = props?.node as { tagName?: unknown } | undefined; |
| 19 | |
| 20 | if (props?.["data-block-media"] != null || node?.tagName === "img") { |
| 21 | return true; |
| 22 | } |
| 23 | |
| 24 | return React.Children.toArray(props.children).some(isBlockMedia); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * Classifies an array of React children into media vs non-media buckets. |