Skip to content

Commit 9bb016a

Browse files
committed
fix(search): clean markdown elements in search contents
1 parent 2948731 commit 9bb016a

File tree

2 files changed

+41
-10
lines changed

2 files changed

+41
-10
lines changed

package-lock.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/plugins/search/search.js

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ function escapeHtml(string) {
3535
return String(string).replace(/[&<>"']/g, s => entityMap[s]);
3636
}
3737

38+
function formatContent(text) {
39+
return escapeHtml(cleanMarkdown(ignoreDiacriticalMarks(text)));
40+
}
41+
3842
function cleanMarkdown(text) {
3943
if (text) {
4044
text = markdownToTxt(text);
@@ -183,19 +187,14 @@ export function search(query) {
183187
keywords.forEach(keyword => {
184188
// From https://github.com/sindresorhus/escape-string-regexp
185189
const regEx = new RegExp(
186-
escapeHtml(ignoreDiacriticalMarks(keyword)).replace(
187-
/[|\\{}()[\]^$+*?.]/g,
188-
'\\$&',
189-
),
190+
formatContent(keyword).replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'),
190191
'gi',
191192
);
192193
let indexTitle = -1;
193194
let indexContent = -1;
194-
handlePostTitle = postTitle
195-
? escapeHtml(ignoreDiacriticalMarks(postTitle))
196-
: postTitle;
195+
handlePostTitle = postTitle ? formatContent(postTitle) : postTitle;
197196
handlePostContent = postContent
198-
? escapeHtml(ignoreDiacriticalMarks(postContent))
197+
? formatContent(postContent)
199198
: postContent;
200199

201200
indexTitle = postTitle ? handlePostTitle.search(regEx) : -1;
@@ -234,8 +233,8 @@ export function search(query) {
234233

235234
if (matchesScore > 0) {
236235
const matchingPost = {
237-
title: cleanMarkdown(handlePostTitle),
238-
content: cleanMarkdown(postContent ? resultStr : ''),
236+
title: formatContent(handlePostTitle),
237+
content: formatContent(postContent ? resultStr : ''),
239238
url: postUrl,
240239
score: matchesScore,
241240
};

0 commit comments

Comments
 (0)