Skip to content

Commit 779ce27

Browse files
bors[bot]bidoubiwa
andauthored
Merge #531
531: fix highlight on non arrays r=bidoubiwa a=bidoubiwa <img width="809" alt="Screenshot 2021-09-27 at 18 47 51" src="https://user-images.githubusercontent.com/33010418/134955251-f5619ca2-c178-4e5e-b08b-dde1d4871409.png"> `@mdubus` fixes: #435 Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 6c5b3b5 + 30bb5c8 commit 779ce27

File tree

1 file changed

+10
-11
lines changed

1 file changed

+10
-11
lines changed

src/adapter/highlight-adapter.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,21 @@ import { InstantSearchParams } from '../types'
1111
* @returns string
1212
*/
1313
function replaceHighlightTags(
14-
value: string,
14+
value: any,
1515
highlightPreTag?: string,
1616
highlightPostTag?: string
1717
): string {
18-
// Value has to be a string to have highlight.
19-
// Highlight is applied by MeiliSearch (<em> tags)
20-
// We replace the <em> by the expected tag for InstantSearch
2118
highlightPreTag = highlightPreTag || '__ais-highlight__'
2219
highlightPostTag = highlightPostTag || '__/ais-highlight__'
23-
if (isString(value)) {
24-
return value
25-
.replace(/<em>/g, highlightPreTag)
26-
.replace(/<\/em>/g, highlightPostTag)
27-
}
28-
// We JSON stringify to avoid loss of nested information
29-
return JSON.stringify(value)
20+
// Highlight is applied by MeiliSearch (<em> tags)
21+
// We replace the <em> by the expected tag for InstantSearch
22+
const stringifiedValue = isString(value)
23+
? value
24+
: JSON.stringify(value, null, 2)
25+
26+
return stringifiedValue
27+
.replace(/<em>/g, highlightPreTag)
28+
.replace(/<\/em>/g, highlightPostTag)
3029
}
3130

3231
/**

0 commit comments

Comments
 (0)