This code is suppsoed to return a markdown containing sections of highlighted text based…
- User
This code is suppsoed to return a markdown containing sections of highlighted text based on selected text highlighted by the user. However, right now when i highlight text it disapears. const renderAnnotatedText = (text: string) => { if (annotationIndex === null || !selectedText) { // Render it in the same style as previous with STYLE_LEVEL_TO_CLASSES.p return ( ); }
codeconst parts = text.split(new RegExp((`${selectedText}`), 'g')); let currentCharIndex = 0; const children: React.ReactNode[] = parts.map((part, index) => { if (part === selectedText && currentCharIndex === annotationIndex) { currentCharIndex += part.length; return ( <React.Fragment key={index}> <span className="bg-yellow-100">{selectedText}</span> <input ref={inputRef} type='text' style={{ fontSize: '14px', // Adjust the font size as needed height: '2rem', // Adjust the height as needed width: '200px', // Adjust the width as needed padding: '0.5rem', // Adjust the padding as needed lineHeight: '1.5', // Adjust the line height as needed fontFamily: 'Arial, sans-serif' // Adjust the font family as needed }} className={cn( 'min-h-[1rem] md:min-h-[2rem]', "w-auto", 'self-center', 'rounded', 'px-1 px-2', 'border', 'bg-danger-50', 'text-lg', 'border-secondary-400', 'transition ease-in-out', 'focus:border-secondary-700', 'focus:outline-none', 'placeholder-base' )} placeholder="Add annotation . . ." onKeyDown={(e) => { if (e.key === "Enter") { const target = e.target as HTMLInputElement; const index = annotations.findIndex(a => a.text === selectedText); if (index !== -1) { addAnnotation(target.value); } target.value = ""; } }} /> </React.Fragment> ); } currentCharIndex += part.length; return <Markdown key={index} text={part} className={cn(STYLE_LEVEL_TO_CLASSES.p)}/>; }); return <>{children}</>; - Assistant
- User
Sorry can you completely re-write the function to return text with in it for highlighted text portions? Then I can use this in a markdown you think?
- Assistant
- User
- Assistant