@@ -35,6 +35,10 @@ function escapeHtml(string) {
35
35
return String ( string ) . replace ( / [ & < > " ' ] / g, s => entityMap [ s ] ) ;
36
36
}
37
37
38
+ function formatContent ( text ) {
39
+ return escapeHtml ( cleanMarkdown ( ignoreDiacriticalMarks ( text ) ) ) ;
40
+ }
41
+
38
42
function cleanMarkdown ( text ) {
39
43
if ( text ) {
40
44
text = markdownToTxt ( text ) ;
@@ -183,19 +187,14 @@ export function search(query) {
183
187
keywords . forEach ( keyword => {
184
188
// From https://github.com/sindresorhus/escape-string-regexp
185
189
const regEx = new RegExp (
186
- escapeHtml ( ignoreDiacriticalMarks ( keyword ) ) . replace (
187
- / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g,
188
- '\\$&' ,
189
- ) ,
190
+ formatContent ( keyword ) . replace ( / [ | \\ { } ( ) [ \] ^ $ + * ? . ] / g, '\\$&' ) ,
190
191
'gi' ,
191
192
) ;
192
193
let indexTitle = - 1 ;
193
194
let indexContent = - 1 ;
194
- handlePostTitle = postTitle
195
- ? escapeHtml ( ignoreDiacriticalMarks ( postTitle ) )
196
- : postTitle ;
195
+ handlePostTitle = postTitle ? formatContent ( postTitle ) : postTitle ;
197
196
handlePostContent = postContent
198
- ? escapeHtml ( ignoreDiacriticalMarks ( postContent ) )
197
+ ? formatContent ( postContent )
199
198
: postContent ;
200
199
201
200
indexTitle = postTitle ? handlePostTitle . search ( regEx ) : - 1 ;
@@ -234,8 +233,8 @@ export function search(query) {
234
233
235
234
if ( matchesScore > 0 ) {
236
235
const matchingPost = {
237
- title : cleanMarkdown ( handlePostTitle ) ,
238
- content : cleanMarkdown ( postContent ? resultStr : '' ) ,
236
+ title : formatContent ( handlePostTitle ) ,
237
+ content : formatContent ( postContent ? resultStr : '' ) ,
239
238
url : postUrl ,
240
239
score : matchesScore ,
241
240
} ;
0 commit comments