We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 4b02177 commit 4d537a7Copy full SHA for 4d537a7
src/plugins/search/search.js
@@ -165,13 +165,18 @@ export function search(query) {
165
end = postContent.length;
166
}
167
168
- const matchContent =
169
- '...' +
170
- escapeHtml(postContent)
171
- .substring(start, end)
172
- .replace(regEx, `<em class="search-keyword">${keyword}</em>`) +
173
- '...';
174
-
+ let content = escapeHtml(postContent).substring(start, end);
+ let matchKeywords = content.match(regEx);
+
+ matchKeywords = new Set(matchKeywords);
+ matchKeywords.forEach(keyword => {
+ content = content.replace(
+ new RegExp(keyword, 'g'),
175
+ `<em class="search-keyword">${keyword}</em>`
176
+ );
177
+ });
178
179
+ const matchContent = '...' + content + '...';
180
resultStr += matchContent;
181
182
});
0 commit comments