Skip to content

Commit

Permalink
Merge pull request #341 from rickdoesdev/master
Browse files Browse the repository at this point in the history
Fix #340 - Whitespace issues while saving
  • Loading branch information
deathau authored Aug 23, 2024
2 parents e1a117a + 71fb3b8 commit 72ddf6f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/background/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,12 @@ function generateValidFileName(title, disallowedChars = null) {
// remove < > : " / \ | ? *
var illegalRe = /[\/\?<>\\:\*\|":]/g;
// and non-breaking spaces (thanks @Licat)
var name = title.replace(illegalRe, "").replace(new RegExp('\u00A0', 'g'), ' ');

var name = title.replace(illegalRe, "").replace(new RegExp('\u00A0', 'g'), ' ')
// collapse extra whitespace
.replace(new RegExp(/\s+/, 'g'), ' ')
// remove leading/trailing whitespace that can cause issues when using {pageTitle} in a download path
.trim();

if (disallowedChars) {
for (let c of disallowedChars) {
if (`[\\^$.|?*+()`.includes(c)) c = `\\${c}`;
Expand Down Expand Up @@ -453,7 +457,7 @@ async function downloadMarkdown(markdown, title, tabId, imageList = {}, mdClipsF
// download images (if enabled)
if (options.downloadImages) {
// get the relative path of the markdown file (if any) for image path
const destPath = mdClipsFolder + title.substring(0, title.lastIndexOf('/'));
let destPath = mdClipsFolder + title.substring(0, title.lastIndexOf('/'));
if(destPath && !destPath.endsWith('/')) destPath += '/';
Object.entries(imageList).forEach(async ([src, filename]) => {
// start the download of the image
Expand Down

0 comments on commit 72ddf6f

Please sign in to comment.