import { Fragment } from "react";
import { highlightRanges } from "@/lib/search-core";
/** `text` with the query's words marked (lib/search-core.ts `highlightRanges`). */
export function Highlighted({ text, query }: { text: string; query: string }) {
const ranges = highlightRanges(text, query);
const out = [];
let at = 0;
for (const [start, end] of ranges) {
out.push(text.slice(at, start), {text.slice(start, end)});
at = end;
}
out.push(text.slice(at));
// data-highlight-ignore: fumadocs' own highlighter (every query letter) skips this subtree.
return (
{out.map((part, i) =>
typeof part === "string" ? {part} : part
)}
);
}