Skip to content

Commit 5c0da6b

Browse files
committed
fix: 🐛 fix whitespace issues in filenames
- reduce multiple spaces to one - reintroduce '#' and other replacements - trim filename, otherwse WikiLinks will break if there is an additional space at the end of the filename (e.g. `The Filename .md` vs `The Filename.md`).
1 parent ebbf06e commit 5c0da6b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main.ts

+10-3
Original file line numberDiff line numberDiff line change
@@ -376,10 +376,14 @@ export default class ReadwiseMirror extends Plugin {
376376
separator: this.settings.slugifySeparator,
377377
lowercase: this.settings.slugifyLowercase,
378378
})
379-
: `${filenamify(title.replace(/:/g, this.settings.colonSubstitute ?? '-'), {
379+
: // ... else filenamify the title
380+
`${filenamify(title.replace(/:/g, this.settings.colonSubstitute ?? '-'), {
380381
replacement: ' ',
381382
maxLength: 255,
382-
})}`;
383+
})}` // Ensure we remove additional critical characters, replace multiple spaces with one, and trim
384+
.replace(/[<>"'\/\\|?*#]+/g, '')
385+
.replace(/ +/g, ' ')
386+
.trim();
383387

384388
// Filter highlights
385389
const filteredHighlights = this.filterHighlights(highlights);
@@ -576,7 +580,10 @@ export default class ReadwiseMirror extends Plugin {
576580
}
577581
});
578582
} catch (err) {
579-
console.error(`Readwise: Attempt to create file ${path} *DE NOVO* failed (uri: ${metadata.highlights_url})`, err);
583+
console.error(
584+
`Readwise: Attempt to create file ${path} *DE NOVO* failed (uri: ${metadata.highlights_url})`,
585+
err
586+
);
580587
this.notify.notice(`Readwise: Failed to create file '${path}'. ${err}`);
581588
}
582589
}

0 commit comments

Comments
 (0)