Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 10 additions & 11 deletions src/adapter/highlight-adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@ import { InstantSearchParams } from '../types'
* @returns string
*/
function replaceHighlightTags(
value: string,
value: any,
highlightPreTag?: string,
highlightPostTag?: string
): string {
// Value has to be a string to have highlight.
// Highlight is applied by MeiliSearch (<em> tags)
// We replace the <em> by the expected tag for InstantSearch
highlightPreTag = highlightPreTag || '__ais-highlight__'
highlightPostTag = highlightPostTag || '__/ais-highlight__'
if (isString(value)) {
return value
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag)
}
// We JSON stringify to avoid loss of nested information
return JSON.stringify(value)
// Highlight is applied by MeiliSearch (<em> tags)
// We replace the <em> by the expected tag for InstantSearch
const stringifiedValue = isString(value)
? value
: JSON.stringify(value, null, 2)

return stringifiedValue
.replace(/<em>/g, highlightPreTag)
.replace(/<\/em>/g, highlightPostTag)
}

/**
Expand Down