Skip to content

Commit

Permalink
fix: Search plugin: matched text is replaced with search text (#1298)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
huangzhhui and sy-records authored Jul 24, 2020
1 parent 9f4f79e commit 78775b6
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/plugins/search/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

1 comment on commit 78775b6

@vercel
Copy link

@vercel vercel bot commented on 78775b6 Jul 24, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.