File tree 3 files changed +30
-2
lines changed
3 files changed +30
-2
lines changed Original file line number Diff line number Diff line change 36
36
"*.js" : " eslint --fix"
37
37
},
38
38
"dependencies" : {
39
+ "markdown-to-txt" : " ^2.0.1" ,
39
40
"medium-zoom" : " ^1.1.0" ,
40
41
"opencollective-postinstall" : " ^2.0.2" ,
41
42
"prismjs" : " ^1.29.0" ,
Original file line number Diff line number Diff line change
1
+ import markdownToTxt from 'markdown-to-txt' ;
1
2
import {
2
3
getAndRemoveConfig ,
3
4
getAndRemoveDocisfyIgnoreConfig ,
@@ -34,6 +35,13 @@ function escapeHtml(string) {
34
35
return String ( string ) . replace ( / [ & < > " ' ] / g, s => entityMap [ s ] ) ;
35
36
}
36
37
38
+ function cleanMarkdown ( text ) {
39
+ if ( text ) {
40
+ text = markdownToTxt ( text ) ;
41
+ }
42
+ return text ;
43
+ }
44
+
37
45
function getAllPaths ( router ) {
38
46
const paths = [ ] ;
39
47
@@ -226,8 +234,8 @@ export function search(query) {
226
234
227
235
if ( matchesScore > 0 ) {
228
236
const matchingPost = {
229
- title : handlePostTitle ,
230
- content : postContent ? resultStr : '' ,
237
+ title : cleanMarkdown ( handlePostTitle ) ,
238
+ content : cleanMarkdown ( postContent ? resultStr : '' ) ,
231
239
url : postUrl ,
232
240
score : matchesScore ,
233
241
} ;
Original file line number Diff line number Diff line change @@ -232,4 +232,23 @@ test.describe('Search Plugin Tests', () => {
232
232
await page . keyboard . press ( 'z' ) ;
233
233
await expect ( searchFieldElm ) . toBeFocused ( ) ;
234
234
} ) ;
235
+ test ( 'search result should remove markdown' , async ( { page } ) => {
236
+ const docsifyInitConfig = {
237
+ markdown : {
238
+ homepage : `
239
+ # The [mock](example.com) link
240
+ There is lots of words.
241
+ ` ,
242
+ } ,
243
+ scriptURLs : [ '/dist/plugins/search.js' ] ,
244
+ } ;
245
+
246
+ const searchFieldElm = page . locator ( 'input[type=search]' ) ;
247
+ const resultsHeadingElm = page . locator ( '.results-panel h2' ) ;
248
+
249
+ await docsifyInit ( docsifyInitConfig ) ;
250
+
251
+ await searchFieldElm . fill ( 'There' ) ;
252
+ await expect ( resultsHeadingElm ) . toHaveText ( 'The mock link' ) ;
253
+ } ) ;
235
254
} ) ;
You can’t perform that action at this time.
0 commit comments