123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- import type {Fuse} from 'sentry/utils/fuzzySearch';
- type Options = {
- htmlString: string;
- key: string;
- markTags: {
- highlightPostTag: string;
- highlightPreTag: string;
- };
- };
- export default function parseHtmlMarks({key, htmlString, markTags}: Options) {
- const {highlightPreTag, highlightPostTag} = markTags;
- const indices: [number, number][] = [];
- let value = htmlString;
- // eslint-disable-next-line no-constant-condition
- while (true) {
- const openIndex = value.indexOf(highlightPreTag);
- const openIndexEnd = openIndex + highlightPreTag.length;
- if (openIndex === -1 || value.indexOf(highlightPostTag) === -1) {
- break;
- }
- value = value.slice(0, openIndex) + value.slice(openIndexEnd);
- const closeIndex = value.indexOf(highlightPostTag);
- const closeIndexEnd = closeIndex + highlightPostTag.length;
- value = value.slice(0, closeIndex) + value.slice(closeIndexEnd);
- indices.push([openIndex, closeIndex - 1]);
- }
- return {key, value, indices} as Fuse.FuseResultMatch;
- }
|