fix: Search plugin: matched text is replaced with search text (#1298)

* Fix search plugin will replace matching text

* Fix bug that will replace a unexpected text

* Fix bug that will replace a unexpected text

* Optimized

Co-authored-by: 沈唁 <52o@qq52o.cn>
This commit is contained in:
黄朝晖 2020-07-24 10:22:54 +08:00 committed by GitHub
parent 9f4f79e0f7
commit 78775b6ee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -170,7 +170,10 @@ export function search(query) {
'...' +
escapeHtml(postContent)
.substring(start, end)
.replace(regEx, `<em class="search-keyword">${keyword}</em>`) +
.replace(
regEx,
word => `<em class="search-keyword">${word}</em>`
) +
'...';
resultStr += matchContent;