here is my current code for my react markdwon component for code... right now it only…
- User
here is my current code for my react markdwon component for code... right now it only hightlights the first code paragraph. It correctly adds the higlights tokens but does not render them. can you fix the code so it renderes highlights in other code containers? 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
for some reason my code used in my react markdown component for rendering highlighted text is not working? the highlight tokens are correctly applied. but iti snt correctly highlighting the characters betwen them. my code sometimes comes in multiple containers... whati s going on here? 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; };
- Assistant