/********************************************************************************** * Copyright (c) 2025 EclipseSource and others. * * This program and the accompanying materials are made available under the * terms of the MIT License as outlined in the LICENSE file. **********************************************************************************/ import React from 'react'; import Markdown from 'react-markdown'; import remarkGfm from 'remark-gfm'; import { Tooltip, TooltipContent, TooltipTrigger } from '../tooltip/tooltip'; export function createHighlightedText(label?: string, highlights?: [number, number][]): React.JSX.Element { if (label === undefined) { return No label provided; } if (highlights === undefined || highlights.length === 0) { return {label}; } highlights.sort((a, b) => a[0] - b[0]); const result: React.JSX.Element[] = []; let currentPosition = 0; highlights.forEach(([start, end], index) => { if (currentPosition < start) { result.push({label.slice(currentPosition, start)}); } result.push( {label.slice(start, end + 1)} ); currentPosition = end + 1; }); // Add any remaining text after the last highlight if (currentPosition < label.length) { result.push({label.slice(currentPosition)}); } return (
{result}
); } export function createLabelWithTooltip(child: React.JSX.Element, tooltip?: string): React.JSX.Element { const label =
{child}
; if (tooltip === undefined) { return label; } return ( {label}
{tooltip}
); }