Skip to content

Commit c1840b6

Browse files
committed
Transform all fields in highlight to string
1 parent 3506649 commit c1840b6

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

src/format.ts

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,14 @@ function replaceHighlightTags(
66
highlightPreTag?: string,
77
highlightPostTag?: string
88
): string {
9-
// If the value of the attribute is a string,
10-
// the highlight is applied by MeiliSearch (<em> tags)
11-
// and we replace the <em> by the expected tag for InstantSearch
12-
if (isString(value)) {
13-
highlightPreTag = highlightPreTag || '__ais-highlight__'
14-
highlightPostTag = highlightPostTag || '__/ais-highlight__'
15-
return value
16-
.replace(/<em>/g, highlightPreTag)
17-
.replace(/<\/em>/g, highlightPostTag)
18-
}
19-
return value
9+
// Value has to be a string.
10+
// Some field may have highlight applied by MeiliSearch (<em> tags)
11+
// We replace the <em> by the expected tag for InstantSearch
12+
highlightPreTag = highlightPreTag || '__ais-highlight__'
13+
highlightPostTag = highlightPostTag || '__/ais-highlight__'
14+
return JSON.stringify(value)
15+
.replace(/<em>/g, highlightPreTag)
16+
.replace(/<\/em>/g, highlightPostTag)
2017
}
2118

2219
function createHighlighResult<T extends Record<string, any>>({

0 commit comments

Comments
 (0)