Skip to content

Commit

Permalink
rename unescape to removeHighlightTags
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Apr 1, 2021
1 parent e3fc6a3 commit b568362
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions packages/docsearch-react/src/DocSearchModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
import { useSearchClient } from './useSearchClient';
import { useTouchEvents } from './useTouchEvents';
import { useTrapFocus } from './useTrapFocus';
import { groupBy, identity, noop, unescape } from './utils';
import { groupBy, identity, noop, removeHighlightTags } from './utils';

export interface DocSearchModalProps extends DocSearchProps {
initialScrollY: number;
Expand Down Expand Up @@ -225,7 +225,7 @@ export function DocSearchModal({
const hits = results[0].hits;
const nbHits: number = results[0].nbHits;
const sources = groupBy(hits, (hit) =>
unescape(hit.hierarchy.lvl0)
removeHighlightTags(hit.hierarchy.lvl0)
);

// We store the `lvl0`s to display them as search suggestions
Expand Down
4 changes: 2 additions & 2 deletions packages/docsearch-react/src/ResultsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { SelectIcon, SourceIcon } from './icons';
import { Results } from './Results';
import { ScreenStateProps } from './ScreenState';
import { InternalDocSearchHit } from './types';
import { unescape } from './utils';
import { removeHighlightTags } from './utils';

type ResultsScreenProps = ScreenStateProps<InternalDocSearchHit>;

Expand All @@ -16,7 +16,7 @@ export function ResultsScreen(props: ResultsScreenProps) {
return null;
}

const title = unescape(
const title = removeHighlightTags(
collection.items[0]._highlightResult.hierarchy_camel[0].lvl0.value
);

Expand Down
2 changes: 1 addition & 1 deletion packages/docsearch-react/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export * from './groupBy';
export * from './identity';
export * from './noop';
export * from './unescape';
export * from './removeHighlightTags';
8 changes: 8 additions & 0 deletions packages/docsearch-react/src/utils/removeHighlightTags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const regexHighlightTags = /(<mark>|<\/mark>)/g;
const regexHasHighlightTags = RegExp(regexHighlightTags.source);

export function removeHighlightTags(value: string): string {
return value && regexHasHighlightTags.test(value)
? value.replace(regexHighlightTags, '')
: value;
}
8 changes: 0 additions & 8 deletions packages/docsearch-react/src/utils/unescape.ts

This file was deleted.

0 comments on commit b568362

Please sign in to comment.