@@ -202,7 +202,7 @@ export default class ReadwiseMirror extends Plugin {
202
202
const { title, highlights } = book ;
203
203
const num_highlights = highlights . length ;
204
204
console . warn ( `Readwise: Replacing colon with ${ this . settings . colonSubstitute } ` ) ;
205
- const sanitizedTitle = title . replace ( / : / g , this . settings . colonSubstitute ?? '-' ) . replace ( / [ < > " ' / \\ | ? * ] + / g , '' ) ;
205
+ const sanitizedTitle = this . sanitizeTitle ( book . title ) ;
206
206
const contents = `\n- [[${ sanitizedTitle } ]] *(${ num_highlights } highlights)*` ;
207
207
logString += contents ;
208
208
}
@@ -389,19 +389,7 @@ export default class ReadwiseMirror extends Plugin {
389
389
390
390
391
391
// Sanitize title, replace colon with substitute from settings
392
- const sanitizedTitle = this . settings . useSlugify
393
- ? slugify ( title . replace ( / : / g, this . settings . colonSubstitute ?? '-' ) , {
394
- separator : this . settings . slugifySeparator ,
395
- lowercase : this . settings . slugifyLowercase ,
396
- } )
397
- : // ... else filenamify the title
398
- filenamify ( title . replace ( / : / g, this . settings . colonSubstitute ?? '-' ) , {
399
- replacement : ' ' ,
400
- maxLength : 255 ,
401
- } ) // Ensure we remove additional critical characters, replace multiple spaces with one, and trim
402
- . replace ( / [ < > " ' / \\ | ? * # ] + / g, '' )
403
- . replace ( / + / g, ' ' )
404
- . trim ( ) ;
392
+ const sanitizedTitle = this . sanitizeTitle ( title ) ;
405
393
406
394
// Filter highlights
407
395
const filteredHighlights = this . filterHighlights ( highlights ) ;
@@ -628,6 +616,25 @@ export default class ReadwiseMirror extends Plugin {
628
616
}
629
617
}
630
618
619
+ // Sanitize title for use as filename
620
+ private sanitizeTitle ( title : string ) {
621
+ return this . settings . useSlugify
622
+ ? slugify ( title . replace ( / : / g, this . settings . colonSubstitute ?? '-' ) , {
623
+ separator : this . settings . slugifySeparator ,
624
+ lowercase : this . settings . slugifyLowercase ,
625
+ } )
626
+ : // ... else filenamify the title and limit to 255 characters
627
+ filenamify ( title . replace ( / : / g, this . settings . colonSubstitute ?? '-' ) , {
628
+ replacement : ' ' ,
629
+ maxLength : 255 ,
630
+ } )
631
+ // Ensure we remove additional critical characters, replace multiple spaces with one, and trim
632
+ // Replace # as this inrerferes with WikiLinks (other characters are taken care of in "filenamify")
633
+ . replace ( / [ # ] + / g, ' ' )
634
+ . replace ( / + / g, ' ' )
635
+ . trim ( ) ;
636
+ }
637
+
631
638
async deleteLibraryFolder ( ) {
632
639
const vault = this . app . vault ;
633
640
const path = `${ this . settings . baseFolderName } ` ;
0 commit comments