my highlight code doesnt seem to work for ranges that occur over multiple containers in…
- User
my highlight code doesnt seem to work for ranges that occur over multiple containers in my react markdown. how can i fix this? import { ComponentPropsWithoutRef } from 'react'; import React from 'react'; import { cn } from '@/utils';
interface PropsWithChildren { children: React.ReactNode; }
const Highlight = ({ children }: { children: React.ReactNode }) => { return <span className={cn("bg-yellow-100","text-volcanic-700")}>{children}; };
export const Code = ({ children }: ComponentPropsWithoutRef<'code'>) => { const processText = (text: string): React.ReactNode => { const parts = text.split(/([H]|[/H])/); return parts.map((part, index) => { if (part === '[H]' || part === '[/H]') { return null; // Ignore the markers themselves } if (index % 4 === 2) { // Text within markers return {part}; } return part; // Regular text }); };
const processChildren = (children: React.ReactNode): React.ReactNode => { if (typeof children === 'string') { return processText(children); } if (Array.isArray(children)) { return children.map((child, index) => ( <React.Fragment key={index}>{processChildren(child)}</React.Fragment> )); } return children; };
return {processChildren(children)}; };
- Assistant
- User
please fix the types of the arguments for each function... processNode needs arugmenet types
- Assistant
- User
children: React... No overload matches this call. The last overload gave the following error. Object literal may only specify known properties, and 'children' does not exist in type 'Partial & Attributes'.ts(2769) index.d.ts(591, 14): The last overload is declared here.
- Assistant
- User
fix this: if (React.isValidElement(node) && node.props.children) { return React.cloneElement(node, { children: React.Children.map(node.props.children, (child) => processNode(child, isHighlighted) ), }); } No overload matches this call. The last overload gave the following error. Object literal may only specify known properties, and 'children' does not exist in type 'Partial & Attributes'.ts(2769) index.d.ts(591, 14): The last overload is declared here.
- Assistant