Skip to content

Commit 583ea5a

Browse files
add option --filename-replaced-character
1 parent 0e7ae88 commit 583ea5a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

options.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ const OPTIONS_INFO = {
9090
"filename-template": { description: "Template used to generate the output filename (see help page of the extension for more info)", type: "string", defaultValue: "%if-empty<{page-title}|No title> ({date-locale} {time-locale}).{filename-extension}" },
9191
"filename-conflict-action": { description: "Action when the filename is conflicting with existing one on the filesystem. The possible values are \"uniquify\" (default), \"overwrite\" and \"skip\"", type: "string", defaultValue: "uniquify" },
9292
"filename-replacement-character": { description: "The character used for replacing invalid characters in filenames", type: "string", defaultValue: "_" },
93+
"filename-replaced-character": { description: "The replaced character and the character(s) used for replacing the replacement character in filenames separated by a space, e.g. --filename-replaced-character \">\" _GT_ to replace \">\" with _GT_", type: "string[]", defaultValue: ["~ ~", "+ +", "? ?", "% %", "* *", ": :", "| |", "\" "", "< <", "> >", "\\\\ \", "\\x00-\\x1f _", "\x7F _"] },
9394
"filename-max-length": { description: "Specify the maximum length of the filename", type: "number", defaultValue: 192 },
9495
"filename-max-length-unit": { description: "Specify the unit of the maximum length of the filename ('bytes' or 'chars')", type: "string", defaultValue: "bytes" },
9596
"replace-emojis-in-filename": { description: "Replace emojis in the filename with their unicode text representation", type: "boolean" },
@@ -324,6 +325,28 @@ function parseArgs(args, setDefaultValues = true) {
324325
result.options.blockedURLPatterns = result.options.blockedUrlPatterns;
325326
delete result.options.blockedUrlPatterns;
326327
}
328+
if (result.options.filenameReplacedCharacters) {
329+
const filenameReplacedCharacters = result.options.filenameReplacedCharacters;
330+
result.options.filenameReplacedCharacters = [];
331+
result.options.filenameReplacementCharacters = [];
332+
filenameReplacedCharacters.forEach(replacement => {
333+
let [replacedCharacter, replacementCharacter] = replacement.split(" ");
334+
try {
335+
replacedCharacter = JSON.parse(replacedCharacter);
336+
} catch (error) {
337+
// ignored
338+
}
339+
result.options.filenameReplacedCharacters.push(replacedCharacter);
340+
if (replacementCharacter !== undefined) {
341+
try {
342+
replacementCharacter = JSON.parse(replacementCharacter);
343+
} catch (error) {
344+
// ignored
345+
}
346+
result.options.filenameReplacementCharacters.push(replacementCharacter);
347+
}
348+
});
349+
}
327350
return result;
328351
}
329352

0 commit comments

Comments
 (0)