Skip to content

Commit c3daf11

Browse files
committed
Fix bug that will replace a unexpected text
1 parent 795c342 commit c3daf11

File tree

1 file changed

+3
-11
lines changed

1 file changed

+3
-11
lines changed

src/plugins/search/search.js

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -166,21 +166,13 @@ export function search(query) {
166166
end = postContent.length;
167167
}
168168

169-
let originKeyword = escapeHtml(postContent)
170-
.substring(indexContent, end)
171-
.match(regEx);
172-
originKeyword = Array.isArray(originKeyword)
173-
? originKeyword[0]
174-
: keyword;
175-
176169
const matchContent =
177170
'...' +
178171
escapeHtml(postContent)
179172
.substring(start, end)
180-
.replace(
181-
regEx,
182-
`<em class="search-keyword">${originKeyword}</em>`
183-
) +
173+
.replace(regEx, function(word) {
174+
return `<em class="search-keyword">${word}</em>`;
175+
}) +
184176
'...';
185177

186178
resultStr += matchContent;

0 commit comments

Comments
 (0)