diff --git a/src/background/background.js b/src/background/background.js index 983062a..32b7138 100644 --- a/src/background/background.js +++ b/src/background/background.js @@ -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}`; @@ -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